Compare commits
97 Commits
2.5.3-alph
...
3.0.3
Author | SHA1 | Date | |
---|---|---|---|
|
802ce28103 | ||
|
f31356b227 | ||
|
7942466863 | ||
|
db2cade4e2 | ||
|
718b4bb5dd | ||
|
6aa25dd2dc | ||
|
0bbcf6cdb2 | ||
|
f11d60f78c | ||
|
8a6b98614f | ||
|
d7eec528e4 | ||
|
a10c61168a | ||
|
5c4886c66b | ||
|
4335b8dc2c | ||
|
3bf7225712 | ||
|
b76440ab9a | ||
|
3152605bca | ||
|
eaabd30dc2 | ||
|
de0d28b12d | ||
|
c3a8bc9486 | ||
|
5b77404597 | ||
|
d9c1b00b50 | ||
|
2fc439b306 | ||
|
2cb1b01fbf | ||
|
d16cca9847 | ||
|
e39f009661 | ||
|
1d622b653d | ||
|
582a958195 | ||
|
9245b4cc27 | ||
|
ba9396ad5c | ||
|
27de16cba9 | ||
|
90ea073089 | ||
|
4811e53d12 | ||
|
c7f38adb3f | ||
|
99a7359be3 | ||
|
d42cc3e275 | ||
|
b8f4589b87 | ||
|
f9ac6804b2 | ||
|
62f5d54676 | ||
|
8feca3fb21 | ||
|
7b16140ee1 | ||
|
14ec280d26 | ||
|
71ac05ae85 | ||
|
c4a9cb0a4a | ||
|
7ae87d1dbe | ||
|
346036b7e7 | ||
|
69c355c8cd | ||
|
8dbbe80dbf | ||
|
77e6ce8c7c | ||
|
cd405a9b9e | ||
|
b5d6cf047c | ||
|
aaa9c4e190 | ||
|
6ea09dc964 | ||
|
eace5ca8fb | ||
|
03308be7f5 | ||
|
4f40459b96 | ||
|
791368b100 | ||
|
5dd3f5bbd7 | ||
|
d1d60e55d5 | ||
|
471b631838 | ||
|
2f1fd87435 | ||
|
a03c73f8d6 | ||
|
f7029e5ee2 | ||
|
802e405c4e | ||
|
55deabe56b | ||
|
f8e4e69e53 | ||
|
3c7d1696ff | ||
|
902def1dd7 | ||
|
f260ed1175 | ||
|
bc40e91215 | ||
|
120b35d394 | ||
|
ded568ec3f | ||
|
e958059572 | ||
|
d988becf1f | ||
|
e8476d5b05 | ||
|
1ea0307156 | ||
|
4ae47b09dc | ||
|
3e9bb63894 | ||
|
dce86d9c69 | ||
|
4013098201 | ||
|
56f633d58b | ||
|
6c1fb14cda | ||
|
ad0e55cf4c | ||
|
c4fb5489fa | ||
|
3d3006c681 | ||
|
a9d983ddc6 | ||
|
f6554a2a51 | ||
|
ec3426b827 | ||
|
d0494aa2e7 | ||
|
6adcd491db | ||
|
bc709336e1 | ||
|
7d56a04283 | ||
|
7851404d69 | ||
|
30b5acc3b4 | ||
|
29b0bc980f | ||
|
b05279ed4b | ||
|
88f3cb0a3f | ||
|
f48fdac085 |
10
.gitignore
vendored
Normal file
10
.gitignore
vendored
Normal file
@@ -0,0 +1,10 @@
|
|||||||
|
**/.settings
|
||||||
|
**/.gitignore
|
||||||
|
**/.project
|
||||||
|
**/.classpath
|
||||||
|
**/.idea
|
||||||
|
**/target
|
||||||
|
**/bin
|
||||||
|
**/lib
|
||||||
|
**/out
|
||||||
|
**dependency-reduced-pom.xml
|
219
OpenInv/pom.xml
219
OpenInv/pom.xml
@@ -1,219 +0,0 @@
|
|||||||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
|
||||||
<modelVersion>4.0.0</modelVersion>
|
|
||||||
|
|
||||||
<parent>
|
|
||||||
<groupId>com.lishid</groupId>
|
|
||||||
<artifactId>openinvparent</artifactId>
|
|
||||||
<version>1.0-SNAPSHOT</version>
|
|
||||||
</parent>
|
|
||||||
|
|
||||||
<artifactId>openinv</artifactId>
|
|
||||||
<name>OpenInv</name>
|
|
||||||
<version>2.5.3-SNAPSHOT</version>
|
|
||||||
|
|
||||||
<profiles>
|
|
||||||
|
|
||||||
<profile>
|
|
||||||
<id>latest</id>
|
|
||||||
<dependencies>
|
|
||||||
<dependency>
|
|
||||||
<groupId>com.lishid</groupId>
|
|
||||||
<artifactId>openinvcraftbukkit1_11_R1</artifactId>
|
|
||||||
<version>1.0-SNAPSHOT</version>
|
|
||||||
</dependency>
|
|
||||||
</dependencies>
|
|
||||||
</profile>
|
|
||||||
|
|
||||||
<profile>
|
|
||||||
<id>modern</id>
|
|
||||||
<dependencies>
|
|
||||||
<dependency>
|
|
||||||
<groupId>com.lishid</groupId>
|
|
||||||
<artifactId>openinvcraftbukkit1_7_R4</artifactId>
|
|
||||||
<version>1.0-SNAPSHOT</version>
|
|
||||||
</dependency>
|
|
||||||
<dependency>
|
|
||||||
<groupId>com.lishid</groupId>
|
|
||||||
<artifactId>openinvcraftbukkit1_8_R1</artifactId>
|
|
||||||
<version>1.0-SNAPSHOT</version>
|
|
||||||
</dependency>
|
|
||||||
<dependency>
|
|
||||||
<groupId>com.lishid</groupId>
|
|
||||||
<artifactId>openinvcraftbukkit1_8_R2</artifactId>
|
|
||||||
<version>1.0-SNAPSHOT</version>
|
|
||||||
</dependency>
|
|
||||||
<dependency>
|
|
||||||
<groupId>com.lishid</groupId>
|
|
||||||
<artifactId>openinvcraftbukkit1_8_R3</artifactId>
|
|
||||||
<version>1.0-SNAPSHOT</version>
|
|
||||||
</dependency>
|
|
||||||
<dependency>
|
|
||||||
<groupId>com.lishid</groupId>
|
|
||||||
<artifactId>openinvcraftbukkit1_9_R1</artifactId>
|
|
||||||
<version>1.0-SNAPSHOT</version>
|
|
||||||
</dependency>
|
|
||||||
<dependency>
|
|
||||||
<groupId>com.lishid</groupId>
|
|
||||||
<artifactId>openinvcraftbukkit1_9_R2</artifactId>
|
|
||||||
<version>1.0-SNAPSHOT</version>
|
|
||||||
</dependency>
|
|
||||||
<dependency>
|
|
||||||
<groupId>com.lishid</groupId>
|
|
||||||
<artifactId>openinvcraftbukkit1_10_R1</artifactId>
|
|
||||||
<version>1.0-SNAPSHOT</version>
|
|
||||||
</dependency>
|
|
||||||
<dependency>
|
|
||||||
<groupId>com.lishid</groupId>
|
|
||||||
<artifactId>openinvcraftbukkit1_11_R1</artifactId>
|
|
||||||
<version>1.0-SNAPSHOT</version>
|
|
||||||
</dependency>
|
|
||||||
</dependencies>
|
|
||||||
</profile>
|
|
||||||
|
|
||||||
<profile>
|
|
||||||
<id>all</id>
|
|
||||||
<dependencies>
|
|
||||||
<dependency>
|
|
||||||
<groupId>com.lishid</groupId>
|
|
||||||
<artifactId>openinvcraftbukkit1_4_5</artifactId>
|
|
||||||
<version>1.0-SNAPSHOT</version>
|
|
||||||
</dependency>
|
|
||||||
<dependency>
|
|
||||||
<groupId>com.lishid</groupId>
|
|
||||||
<artifactId>openinvcraftbukkit1_4_6</artifactId>
|
|
||||||
<version>1.0-SNAPSHOT</version>
|
|
||||||
</dependency>
|
|
||||||
<dependency>
|
|
||||||
<groupId>com.lishid</groupId>
|
|
||||||
<artifactId>openinvcraftbukkit1_4_R1</artifactId>
|
|
||||||
<version>1.0-SNAPSHOT</version>
|
|
||||||
</dependency>
|
|
||||||
<dependency>
|
|
||||||
<groupId>com.lishid</groupId>
|
|
||||||
<artifactId>openinvcraftbukkit1_5_R2</artifactId>
|
|
||||||
<version>1.0-SNAPSHOT</version>
|
|
||||||
</dependency>
|
|
||||||
<dependency>
|
|
||||||
<groupId>com.lishid</groupId>
|
|
||||||
<artifactId>openinvcraftbukkit1_5_R3</artifactId>
|
|
||||||
<version>1.0-SNAPSHOT</version>
|
|
||||||
</dependency>
|
|
||||||
<dependency>
|
|
||||||
<groupId>com.lishid</groupId>
|
|
||||||
<artifactId>openinvcraftbukkit1_6_R1</artifactId>
|
|
||||||
<version>1.0-SNAPSHOT</version>
|
|
||||||
</dependency>
|
|
||||||
<dependency>
|
|
||||||
<groupId>com.lishid</groupId>
|
|
||||||
<artifactId>openinvcraftbukkit1_6_R2</artifactId>
|
|
||||||
<version>1.0-SNAPSHOT</version>
|
|
||||||
</dependency>
|
|
||||||
<dependency>
|
|
||||||
<groupId>com.lishid</groupId>
|
|
||||||
<artifactId>openinvcraftbukkit1_6_R3</artifactId>
|
|
||||||
<version>1.0-SNAPSHOT</version>
|
|
||||||
</dependency>
|
|
||||||
<dependency>
|
|
||||||
<groupId>com.lishid</groupId>
|
|
||||||
<artifactId>openinvcraftbukkit1_7_R1</artifactId>
|
|
||||||
<version>1.0-SNAPSHOT</version>
|
|
||||||
</dependency>
|
|
||||||
<dependency>
|
|
||||||
<groupId>com.lishid</groupId>
|
|
||||||
<artifactId>openinvcraftbukkit1_7_R2</artifactId>
|
|
||||||
<version>1.0-SNAPSHOT</version>
|
|
||||||
</dependency>
|
|
||||||
<dependency>
|
|
||||||
<groupId>com.lishid</groupId>
|
|
||||||
<artifactId>openinvcraftbukkit1_7_R3</artifactId>
|
|
||||||
<version>1.0-SNAPSHOT</version>
|
|
||||||
</dependency>
|
|
||||||
<dependency>
|
|
||||||
<groupId>com.lishid</groupId>
|
|
||||||
<artifactId>openinvcraftbukkit1_7_R4</artifactId>
|
|
||||||
<version>1.0-SNAPSHOT</version>
|
|
||||||
</dependency>
|
|
||||||
<dependency>
|
|
||||||
<groupId>com.lishid</groupId>
|
|
||||||
<artifactId>openinvcraftbukkit1_8_R1</artifactId>
|
|
||||||
<version>1.0-SNAPSHOT</version>
|
|
||||||
</dependency>
|
|
||||||
<dependency>
|
|
||||||
<groupId>com.lishid</groupId>
|
|
||||||
<artifactId>openinvcraftbukkit1_8_R2</artifactId>
|
|
||||||
<version>1.0-SNAPSHOT</version>
|
|
||||||
</dependency>
|
|
||||||
<dependency>
|
|
||||||
<groupId>com.lishid</groupId>
|
|
||||||
<artifactId>openinvcraftbukkit1_8_R3</artifactId>
|
|
||||||
<version>1.0-SNAPSHOT</version>
|
|
||||||
</dependency>
|
|
||||||
<dependency>
|
|
||||||
<groupId>com.lishid</groupId>
|
|
||||||
<artifactId>openinvcraftbukkit1_9_R1</artifactId>
|
|
||||||
<version>1.0-SNAPSHOT</version>
|
|
||||||
</dependency>
|
|
||||||
<dependency>
|
|
||||||
<groupId>com.lishid</groupId>
|
|
||||||
<artifactId>openinvcraftbukkit1_9_R2</artifactId>
|
|
||||||
<version>1.0-SNAPSHOT</version>
|
|
||||||
</dependency>
|
|
||||||
<dependency>
|
|
||||||
<groupId>com.lishid</groupId>
|
|
||||||
<artifactId>openinvcraftbukkit1_10_R1</artifactId>
|
|
||||||
<version>1.0-SNAPSHOT</version>
|
|
||||||
</dependency>
|
|
||||||
<dependency>
|
|
||||||
<groupId>com.lishid</groupId>
|
|
||||||
<artifactId>openinvcraftbukkit1_11_R1</artifactId>
|
|
||||||
<version>1.0-SNAPSHOT</version>
|
|
||||||
</dependency>
|
|
||||||
</dependencies>
|
|
||||||
</profile>
|
|
||||||
</profiles>
|
|
||||||
|
|
||||||
<build>
|
|
||||||
<directory>../target</directory>
|
|
||||||
<finalName>${project.name}</finalName>
|
|
||||||
|
|
||||||
<resources>
|
|
||||||
<resource>
|
|
||||||
<directory>../OpenInvPlugin/src/main/resources</directory>
|
|
||||||
<filtering>true</filtering>
|
|
||||||
</resource>
|
|
||||||
</resources>
|
|
||||||
|
|
||||||
<plugins>
|
|
||||||
<plugin>
|
|
||||||
<groupId>org.apache.maven.plugins</groupId>
|
|
||||||
<artifactId>maven-shade-plugin</artifactId>
|
|
||||||
<version>2.4.3</version>
|
|
||||||
<configuration>
|
|
||||||
<!--
|
|
||||||
~ This keeps the final file clean, but may cause issues for people not familiar with the setup.
|
|
||||||
~ If you're having trouble with the final product missing files, remove or tweak this configuration.
|
|
||||||
-->
|
|
||||||
<minimizeJar>true</minimizeJar>
|
|
||||||
<filters>
|
|
||||||
<filter>
|
|
||||||
<artifact>com.lishid:*</artifact>
|
|
||||||
<includes>
|
|
||||||
<include>com/lishid/openinv/**/*</include>
|
|
||||||
<include>plugin.yml</include>
|
|
||||||
</includes>
|
|
||||||
</filter>
|
|
||||||
</filters>
|
|
||||||
</configuration>
|
|
||||||
<executions>
|
|
||||||
<execution>
|
|
||||||
<phase>package</phase>
|
|
||||||
<goals>
|
|
||||||
<goal>shade</goal>
|
|
||||||
</goals>
|
|
||||||
</execution>
|
|
||||||
</executions>
|
|
||||||
</plugin>
|
|
||||||
</plugins>
|
|
||||||
</build>
|
|
||||||
|
|
||||||
</project>
|
|
@@ -1,39 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright (C) 2011-2014 lishid. All rights reserved.
|
|
||||||
*
|
|
||||||
* This program is free software: you can redistribute it and/or modify
|
|
||||||
* it under the terms of the GNU General Public License as published by
|
|
||||||
* the Free Software Foundation, version 3.
|
|
||||||
*
|
|
||||||
* This program is distributed in the hope that it will be useful,
|
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
* GNU General Public License for more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU General Public License
|
|
||||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package com.lishid.openinv.internal;
|
|
||||||
|
|
||||||
import org.bukkit.entity.Player;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @deprecated Use {@link IAnySilentContainer}
|
|
||||||
*/
|
|
||||||
@Deprecated
|
|
||||||
public interface IAnySilentChest {
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @deprecated Use {@link IAnySilentContainer#activateContainer(Player, boolean, boolean, int, int, int)}.
|
|
||||||
*/
|
|
||||||
@Deprecated
|
|
||||||
public boolean activateChest(Player player, boolean anychest, boolean silentchest, int x, int y, int z);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @deprecated Use {@link IAnySilentContainer#isAnyContainerNeeded(Player, int, int, int)}.
|
|
||||||
*/
|
|
||||||
@Deprecated
|
|
||||||
public boolean isAnyChestNeeded(Player player, int x, int y, int z);
|
|
||||||
|
|
||||||
}
|
|
@@ -1,33 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright (C) 2011-2014 lishid. All rights reserved.
|
|
||||||
*
|
|
||||||
* This program is free software: you can redistribute it and/or modify
|
|
||||||
* it under the terms of the GNU General Public License as published by
|
|
||||||
* the Free Software Foundation, version 3.
|
|
||||||
*
|
|
||||||
* This program is distributed in the hope that it will be useful,
|
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
* GNU General Public License for more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU General Public License
|
|
||||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package com.lishid.openinv.internal;
|
|
||||||
|
|
||||||
import org.bukkit.entity.HumanEntity;
|
|
||||||
import org.bukkit.inventory.Inventory;
|
|
||||||
|
|
||||||
public interface IInventoryAccess {
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Check if an entity has permission to modify the contents of an inventory.
|
|
||||||
*
|
|
||||||
* @param inventory the Inventory
|
|
||||||
* @param player the HumanEntity
|
|
||||||
* @return true if the HumanEntity can modify the Inventory
|
|
||||||
*/
|
|
||||||
public boolean check(Inventory inventory, HumanEntity player);
|
|
||||||
|
|
||||||
}
|
|
@@ -1,153 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright (C) 2011-2014 lishid. All rights reserved.
|
|
||||||
*
|
|
||||||
* This program is free software: you can redistribute it and/or modify
|
|
||||||
* it under the terms of the GNU General Public License as published by
|
|
||||||
* the Free Software Foundation, version 3.
|
|
||||||
*
|
|
||||||
* This program is distributed in the hope that it will be useful,
|
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
* GNU General Public License for more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU General Public License
|
|
||||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package com.lishid.openinv.internal.v1_10_R1;
|
|
||||||
|
|
||||||
import com.lishid.openinv.internal.IAnySilentContainer;
|
|
||||||
|
|
||||||
import org.bukkit.ChatColor;
|
|
||||||
import org.bukkit.block.BlockState;
|
|
||||||
import org.bukkit.entity.Player;
|
|
||||||
|
|
||||||
// Volatile
|
|
||||||
import net.minecraft.server.v1_10_R1.AxisAlignedBB;
|
|
||||||
import net.minecraft.server.v1_10_R1.Block;
|
|
||||||
import net.minecraft.server.v1_10_R1.BlockPosition;
|
|
||||||
import net.minecraft.server.v1_10_R1.Entity;
|
|
||||||
import net.minecraft.server.v1_10_R1.EntityOcelot;
|
|
||||||
import net.minecraft.server.v1_10_R1.EntityPlayer;
|
|
||||||
import net.minecraft.server.v1_10_R1.IInventory;
|
|
||||||
import net.minecraft.server.v1_10_R1.ITileInventory;
|
|
||||||
import net.minecraft.server.v1_10_R1.InventoryLargeChest;
|
|
||||||
import net.minecraft.server.v1_10_R1.PacketPlayOutOpenWindow;
|
|
||||||
import net.minecraft.server.v1_10_R1.TileEntityChest;
|
|
||||||
import net.minecraft.server.v1_10_R1.World;
|
|
||||||
|
|
||||||
import org.bukkit.craftbukkit.v1_10_R1.entity.CraftPlayer;
|
|
||||||
|
|
||||||
public class AnySilentContainer implements IAnySilentContainer {
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean isAnySilentContainer(BlockState block) {
|
|
||||||
return block instanceof org.bukkit.block.Chest;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean activateContainer(Player p, boolean anychest, boolean silentchest, int x, int y, int z) {
|
|
||||||
EntityPlayer player = ((CraftPlayer) p).getHandle();
|
|
||||||
World world = player.world;
|
|
||||||
Object chest = world.getTileEntity(new BlockPosition(x, y, z));
|
|
||||||
if (chest == null)
|
|
||||||
return false;
|
|
||||||
|
|
||||||
if (!anychest && isAnyContainerNeeded(p, x, y, z)) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
int id = Block.getId(world.getType(new BlockPosition(x, y, z)).getBlock());
|
|
||||||
|
|
||||||
if (Block.getId(world.getType(new BlockPosition(x - 1, y, z)).getBlock()) == id)
|
|
||||||
chest = new InventoryLargeChest("Large chest", (TileEntityChest) world.getTileEntity(new BlockPosition(x - 1, y, z)), (ITileInventory) chest);
|
|
||||||
if (Block.getId(world.getType(new BlockPosition(x + 1, y, z)).getBlock()) == id)
|
|
||||||
chest = new InventoryLargeChest("Large chest", (ITileInventory) chest, (TileEntityChest) world.getTileEntity(new BlockPosition(x + 1, y, z)));
|
|
||||||
if (Block.getId(world.getType(new BlockPosition(x, y, z - 1)).getBlock()) == id)
|
|
||||||
chest = new InventoryLargeChest("Large chest", (TileEntityChest) world.getTileEntity(new BlockPosition(x, y, z - 1)), (ITileInventory) chest);
|
|
||||||
if (Block.getId(world.getType(new BlockPosition(x, y, z + 1)).getBlock()) == id)
|
|
||||||
chest = new InventoryLargeChest("Large chest", (ITileInventory) chest, (TileEntityChest) world.getTileEntity(new BlockPosition(x, y, z + 1)));
|
|
||||||
|
|
||||||
boolean returnValue = false;
|
|
||||||
if (!silentchest) {
|
|
||||||
player.openContainer((IInventory) chest);
|
|
||||||
returnValue = true;
|
|
||||||
} else {
|
|
||||||
try {
|
|
||||||
SilentContainerChest silentContainerChest = new SilentContainerChest(player.inventory, ((IInventory) chest), player);
|
|
||||||
int windowId = player.nextContainerCounter();
|
|
||||||
player.playerConnection.sendPacket(new PacketPlayOutOpenWindow(windowId, "minecraft:chest", ((IInventory) chest).getScoreboardDisplayName(), ((IInventory) chest).getSize()));
|
|
||||||
player.activeContainer = silentContainerChest;
|
|
||||||
player.activeContainer.windowId = windowId;
|
|
||||||
player.activeContainer.addSlotListener(player);
|
|
||||||
returnValue = true;
|
|
||||||
} catch (Exception e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
p.sendMessage(ChatColor.RED + "Error while sending silent chest.");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return returnValue;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean isAnyContainerNeeded(Player p, int x, int y, int z) {
|
|
||||||
// FOR REFERENCE, LOOK AT net.minecraft.server.BlockChest
|
|
||||||
EntityPlayer player = ((CraftPlayer) p).getHandle();
|
|
||||||
World world = player.world;
|
|
||||||
|
|
||||||
// If block or ocelot on top
|
|
||||||
if (world.getType(new BlockPosition(x, y + 1, z)).l() || hasOcelotOnTop(world, x, y, z))
|
|
||||||
return true;
|
|
||||||
|
|
||||||
int id = Block.getId(world.getType(new BlockPosition(x, y, z)).getBlock());
|
|
||||||
|
|
||||||
// If block next to chest is chest and has a block or ocelot on top
|
|
||||||
return isBlockedChest(world, id, x - 1, y, z) || isBlockedChest(world, id, x + 1, y, z)
|
|
||||||
|| isBlockedChest(world, id, x, y, z - 1) || isBlockedChest(world, id, x, y, z + 1);
|
|
||||||
}
|
|
||||||
|
|
||||||
private boolean isBlockedChest(World world, int id, int x, int y, int z) {
|
|
||||||
BlockPosition position = new BlockPosition(x, y, z);
|
|
||||||
if (Block.getId(world.getType(position).getBlock()) != id) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (world.getType(position).l()) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
return hasOcelotOnTop(world, x, y, z);
|
|
||||||
}
|
|
||||||
|
|
||||||
private boolean hasOcelotOnTop(World world, int x, int y, int z) {
|
|
||||||
for (Entity localEntity : world.a(EntityOcelot.class,
|
|
||||||
new AxisAlignedBB(x, y + 1, z, x + 1, y + 2, z + 1))) {
|
|
||||||
EntityOcelot localEntityOcelot = (EntityOcelot) localEntity;
|
|
||||||
if (localEntityOcelot.isSitting()) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @deprecated Use {@link #activateContainer(Player, boolean, boolean, int, int, int)}.
|
|
||||||
*/
|
|
||||||
@Deprecated
|
|
||||||
@Override
|
|
||||||
public boolean activateChest(Player player, boolean anychest, boolean silentchest, int x, int y, int z) {
|
|
||||||
return !activateContainer(player, anychest, silentchest, x, y, z);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @deprecated Use {@link #isAnyContainerNeeded(Player, int, int, int)}.
|
|
||||||
*/
|
|
||||||
@Deprecated
|
|
||||||
@Override
|
|
||||||
public boolean isAnyChestNeeded(Player player, int x, int y, int z) {
|
|
||||||
return isAnyContainerNeeded(player, x, y, z);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
@@ -1,74 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright (C) 2011-2014 lishid. All rights reserved.
|
|
||||||
*
|
|
||||||
* This program is free software: you can redistribute it and/or modify
|
|
||||||
* it under the terms of the GNU General Public License as published by
|
|
||||||
* the Free Software Foundation, version 3.
|
|
||||||
*
|
|
||||||
* This program is distributed in the hope that it will be useful,
|
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
* GNU General Public License for more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU General Public License
|
|
||||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package com.lishid.openinv.internal.v1_10_R1;
|
|
||||||
|
|
||||||
import java.lang.reflect.Field;
|
|
||||||
|
|
||||||
import com.lishid.openinv.OpenInv;
|
|
||||||
import com.lishid.openinv.Permissions;
|
|
||||||
import com.lishid.openinv.internal.IInventoryAccess;
|
|
||||||
|
|
||||||
import org.bukkit.entity.HumanEntity;
|
|
||||||
import org.bukkit.inventory.Inventory;
|
|
||||||
|
|
||||||
// Volatile
|
|
||||||
import net.minecraft.server.v1_10_R1.IInventory;
|
|
||||||
|
|
||||||
import org.bukkit.craftbukkit.v1_10_R1.inventory.CraftInventory;
|
|
||||||
|
|
||||||
public class InventoryAccess implements IInventoryAccess {
|
|
||||||
@Override
|
|
||||||
public boolean check(Inventory inventory, HumanEntity player) {
|
|
||||||
IInventory inv = grabInventory(inventory);
|
|
||||||
|
|
||||||
if (inv instanceof SpecialPlayerInventory) {
|
|
||||||
if (!OpenInv.hasPermission(player, Permissions.PERM_EDITINV)) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
else if (inv instanceof SpecialEnderChest) {
|
|
||||||
if (!OpenInv.hasPermission(player, Permissions.PERM_EDITENDER)) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
private IInventory grabInventory(Inventory inventory) {
|
|
||||||
if(inventory instanceof CraftInventory) {
|
|
||||||
return ((CraftInventory) inventory).getInventory();
|
|
||||||
}
|
|
||||||
|
|
||||||
//Use reflection to find the iinventory
|
|
||||||
Class<? extends Inventory> clazz = inventory.getClass();
|
|
||||||
IInventory result = null;
|
|
||||||
for(Field f : clazz.getDeclaredFields()) {
|
|
||||||
f.setAccessible(true);
|
|
||||||
if(IInventory.class.isAssignableFrom(f.getDeclaringClass())) {
|
|
||||||
try {
|
|
||||||
result = (IInventory) f.get(inventory);
|
|
||||||
}
|
|
||||||
catch (Exception e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
}
|
|
@@ -1,72 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright (C) 2011-2014 lishid. All rights reserved.
|
|
||||||
*
|
|
||||||
* This program is free software: you can redistribute it and/or modify
|
|
||||||
* it under the terms of the GNU General Public License as published by
|
|
||||||
* the Free Software Foundation, version 3.
|
|
||||||
*
|
|
||||||
* This program is distributed in the hope that it will be useful,
|
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
* GNU General Public License for more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU General Public License
|
|
||||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package com.lishid.openinv.internal.v1_11_R1;
|
|
||||||
|
|
||||||
import java.lang.reflect.Field;
|
|
||||||
|
|
||||||
import com.lishid.openinv.OpenInv;
|
|
||||||
import com.lishid.openinv.Permissions;
|
|
||||||
import com.lishid.openinv.internal.IInventoryAccess;
|
|
||||||
|
|
||||||
import org.bukkit.entity.HumanEntity;
|
|
||||||
import org.bukkit.inventory.Inventory;
|
|
||||||
|
|
||||||
// Volatile
|
|
||||||
import net.minecraft.server.v1_11_R1.IInventory;
|
|
||||||
|
|
||||||
import org.bukkit.craftbukkit.v1_11_R1.inventory.CraftInventory;
|
|
||||||
|
|
||||||
public class InventoryAccess implements IInventoryAccess {
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean check(Inventory inventory, HumanEntity player) {
|
|
||||||
IInventory inv = grabInventory(inventory);
|
|
||||||
|
|
||||||
if (inv instanceof SpecialPlayerInventory) {
|
|
||||||
if (!OpenInv.hasPermission(player, Permissions.PERM_EDITINV)) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
} else if (inv instanceof SpecialEnderChest) {
|
|
||||||
if (!OpenInv.hasPermission(player, Permissions.PERM_EDITENDER)) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
private IInventory grabInventory(Inventory inventory) {
|
|
||||||
if (inventory instanceof CraftInventory) {
|
|
||||||
return ((CraftInventory) inventory).getInventory();
|
|
||||||
}
|
|
||||||
|
|
||||||
// Use reflection to find the iinventory
|
|
||||||
Class<? extends Inventory> clazz = inventory.getClass();
|
|
||||||
IInventory result = null;
|
|
||||||
for (Field f : clazz.getDeclaredFields()) {
|
|
||||||
f.setAccessible(true);
|
|
||||||
if (IInventory.class.isAssignableFrom(f.getDeclaringClass())) {
|
|
||||||
try {
|
|
||||||
result = (IInventory) f.get(inventory);
|
|
||||||
} catch (Exception e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
}
|
|
@@ -1,154 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright (C) 2011-2014 lishid. All rights reserved.
|
|
||||||
*
|
|
||||||
* This program is free software: you can redistribute it and/or modify
|
|
||||||
* it under the terms of the GNU General Public License as published by
|
|
||||||
* the Free Software Foundation, version 3.
|
|
||||||
*
|
|
||||||
* This program is distributed in the hope that it will be useful,
|
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
* GNU General Public License for more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU General Public License
|
|
||||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package com.lishid.openinv.internal.v1_4_5;
|
|
||||||
|
|
||||||
import java.lang.reflect.Field;
|
|
||||||
|
|
||||||
import com.lishid.openinv.internal.IAnySilentContainer;
|
|
||||||
|
|
||||||
import org.bukkit.ChatColor;
|
|
||||||
import org.bukkit.block.BlockState;
|
|
||||||
import org.bukkit.entity.Player;
|
|
||||||
|
|
||||||
// Volatile
|
|
||||||
import net.minecraft.server.v1_4_5.AxisAlignedBB;
|
|
||||||
import net.minecraft.server.v1_4_5.Block;
|
|
||||||
import net.minecraft.server.v1_4_5.EntityOcelot;
|
|
||||||
import net.minecraft.server.v1_4_5.EntityPlayer;
|
|
||||||
import net.minecraft.server.v1_4_5.IInventory;
|
|
||||||
import net.minecraft.server.v1_4_5.InventoryLargeChest;
|
|
||||||
import net.minecraft.server.v1_4_5.Packet100OpenWindow;
|
|
||||||
import net.minecraft.server.v1_4_5.TileEntityChest;
|
|
||||||
import net.minecraft.server.v1_4_5.World;
|
|
||||||
|
|
||||||
import org.bukkit.craftbukkit.v1_4_5.entity.CraftPlayer;
|
|
||||||
|
|
||||||
public class AnySilentContainer implements IAnySilentContainer {
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean isAnySilentContainer(BlockState block) {
|
|
||||||
return block instanceof org.bukkit.block.Chest;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean activateContainer(Player p, boolean anychest, boolean silentchest, int x, int y, int z) {
|
|
||||||
EntityPlayer player = ((CraftPlayer) p).getHandle();
|
|
||||||
World world = player.world;
|
|
||||||
Object chest = world.getTileEntity(x, y, z);
|
|
||||||
if (chest == null)
|
|
||||||
return false;
|
|
||||||
|
|
||||||
if (!anychest && isAnyContainerNeeded(p, x, y, z)) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (world.getTypeId(x - 1, y, z) == Block.CHEST.id)
|
|
||||||
chest = new InventoryLargeChest("Large chest", (TileEntityChest) world.getTileEntity(x - 1, y, z), (IInventory) chest);
|
|
||||||
if (world.getTypeId(x + 1, y, z) == Block.CHEST.id)
|
|
||||||
chest = new InventoryLargeChest("Large chest", (IInventory) chest, (TileEntityChest) world.getTileEntity(x + 1, y, z));
|
|
||||||
if (world.getTypeId(x, y, z - 1) == Block.CHEST.id)
|
|
||||||
chest = new InventoryLargeChest("Large chest", (TileEntityChest) world.getTileEntity(x, y, z - 1), (IInventory) chest);
|
|
||||||
if (world.getTypeId(x, y, z + 1) == Block.CHEST.id)
|
|
||||||
chest = new InventoryLargeChest("Large chest", (IInventory) chest, (TileEntityChest) world.getTileEntity(x, y, z + 1));
|
|
||||||
|
|
||||||
boolean returnValue = false;
|
|
||||||
if (!silentchest) {
|
|
||||||
player.openContainer((IInventory) chest);
|
|
||||||
returnValue = true;
|
|
||||||
} else {
|
|
||||||
try {
|
|
||||||
int id = 0;
|
|
||||||
try {
|
|
||||||
Field windowID = player.getClass().getDeclaredField("containerCounter");
|
|
||||||
windowID.setAccessible(true);
|
|
||||||
id = windowID.getInt(player);
|
|
||||||
id = id % 100 + 1;
|
|
||||||
windowID.setInt(player, id);
|
|
||||||
} catch (NoSuchFieldException e) {}
|
|
||||||
|
|
||||||
player.netServerHandler.sendPacket(new Packet100OpenWindow(id, 0, ((IInventory) chest).getName(), ((IInventory) chest).getSize()));
|
|
||||||
player.activeContainer = new SilentContainerChest(player.inventory, ((IInventory) chest));
|
|
||||||
player.activeContainer.windowId = id;
|
|
||||||
player.activeContainer.addSlotListener(player);
|
|
||||||
returnValue = true;
|
|
||||||
} catch (Exception e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
p.sendMessage(ChatColor.RED + "Error while sending silent chest.");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return returnValue;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean isAnyContainerNeeded(Player p, int x, int y, int z) {
|
|
||||||
// FOR REFERENCE, LOOK AT net.minecraft.server.BlockChest
|
|
||||||
EntityPlayer player = ((CraftPlayer) p).getHandle();
|
|
||||||
World world = player.world;
|
|
||||||
|
|
||||||
// If block or ocelot on top
|
|
||||||
if (world.s(x, y + 1, z) || hasOcelotOnTop(world, x, y, z))
|
|
||||||
return true;
|
|
||||||
|
|
||||||
// If block next to chest is chest and has a block or ocelot on top
|
|
||||||
return isBlockedChest(world, x - 1, y, z) || isBlockedChest(world, x + 1, y, z)
|
|
||||||
|| isBlockedChest(world, x, y, z - 1) || isBlockedChest(world, x, y, z + 1);
|
|
||||||
}
|
|
||||||
|
|
||||||
private boolean isBlockedChest(World world, int x, int y, int z) {
|
|
||||||
if (world.getTypeId(x, y, z) != Block.CHEST.id) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (world.s(x, y + 1, z)) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
return hasOcelotOnTop(world, x, y, z);
|
|
||||||
}
|
|
||||||
|
|
||||||
private boolean hasOcelotOnTop(World world, int x, int y, int z) {
|
|
||||||
for (Object localEntity : world.a(EntityOcelot.class,
|
|
||||||
AxisAlignedBB.a().a(x, y + 1, z, x + 1, y + 2, z + 1))) {
|
|
||||||
EntityOcelot localEntityOcelot = (EntityOcelot) localEntity;
|
|
||||||
if (localEntityOcelot.isSitting()) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @deprecated Use {@link #activateContainer(Player, boolean, boolean, int, int, int)}.
|
|
||||||
*/
|
|
||||||
@Deprecated
|
|
||||||
@Override
|
|
||||||
public boolean activateChest(Player player, boolean anychest, boolean silentchest, int x, int y, int z) {
|
|
||||||
return !activateContainer(player, anychest, silentchest, x, y, z);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @deprecated Use {@link #isAnyContainerNeeded(Player, int, int, int)}.
|
|
||||||
*/
|
|
||||||
@Deprecated
|
|
||||||
@Override
|
|
||||||
public boolean isAnyChestNeeded(Player player, int x, int y, int z) {
|
|
||||||
return isAnyContainerNeeded(player, x, y, z);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
@@ -1,50 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright (C) 2011-2014 lishid. All rights reserved.
|
|
||||||
*
|
|
||||||
* This program is free software: you can redistribute it and/or modify
|
|
||||||
* it under the terms of the GNU General Public License as published by
|
|
||||||
* the Free Software Foundation, version 3.
|
|
||||||
*
|
|
||||||
* This program is distributed in the hope that it will be useful,
|
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
* GNU General Public License for more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU General Public License
|
|
||||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package com.lishid.openinv.internal.v1_4_5;
|
|
||||||
|
|
||||||
import org.bukkit.entity.HumanEntity;
|
|
||||||
import org.bukkit.inventory.Inventory;
|
|
||||||
|
|
||||||
import com.lishid.openinv.OpenInv;
|
|
||||||
import com.lishid.openinv.Permissions;
|
|
||||||
import com.lishid.openinv.internal.IInventoryAccess;
|
|
||||||
|
|
||||||
// Volatile
|
|
||||||
import net.minecraft.server.v1_4_5.IInventory;
|
|
||||||
|
|
||||||
import org.bukkit.craftbukkit.v1_4_5.inventory.CraftInventory;
|
|
||||||
|
|
||||||
public class InventoryAccess implements IInventoryAccess {
|
|
||||||
@Override
|
|
||||||
public boolean check(Inventory inventory, HumanEntity player) {
|
|
||||||
IInventory inv = ((CraftInventory) inventory).getInventory();
|
|
||||||
|
|
||||||
if (inv instanceof SpecialPlayerInventory) {
|
|
||||||
if (!OpenInv.hasPermission(player, Permissions.PERM_EDITINV)) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
else if (inv instanceof SpecialEnderChest) {
|
|
||||||
if (!OpenInv.hasPermission(player, Permissions.PERM_EDITENDER)) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
@@ -1,154 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright (C) 2011-2014 lishid. All rights reserved.
|
|
||||||
*
|
|
||||||
* This program is free software: you can redistribute it and/or modify
|
|
||||||
* it under the terms of the GNU General Public License as published by
|
|
||||||
* the Free Software Foundation, version 3.
|
|
||||||
*
|
|
||||||
* This program is distributed in the hope that it will be useful,
|
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
* GNU General Public License for more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU General Public License
|
|
||||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package com.lishid.openinv.internal.v1_4_6;
|
|
||||||
|
|
||||||
import java.lang.reflect.Field;
|
|
||||||
|
|
||||||
import com.lishid.openinv.internal.IAnySilentContainer;
|
|
||||||
|
|
||||||
import org.bukkit.ChatColor;
|
|
||||||
import org.bukkit.block.BlockState;
|
|
||||||
import org.bukkit.entity.Player;
|
|
||||||
|
|
||||||
// Volatile
|
|
||||||
import net.minecraft.server.v1_4_6.AxisAlignedBB;
|
|
||||||
import net.minecraft.server.v1_4_6.Block;
|
|
||||||
import net.minecraft.server.v1_4_6.EntityOcelot;
|
|
||||||
import net.minecraft.server.v1_4_6.EntityPlayer;
|
|
||||||
import net.minecraft.server.v1_4_6.IInventory;
|
|
||||||
import net.minecraft.server.v1_4_6.InventoryLargeChest;
|
|
||||||
import net.minecraft.server.v1_4_6.Packet100OpenWindow;
|
|
||||||
import net.minecraft.server.v1_4_6.TileEntityChest;
|
|
||||||
import net.minecraft.server.v1_4_6.World;
|
|
||||||
|
|
||||||
import org.bukkit.craftbukkit.v1_4_6.entity.CraftPlayer;
|
|
||||||
|
|
||||||
public class AnySilentContainer implements IAnySilentContainer {
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean isAnySilentContainer(BlockState block) {
|
|
||||||
return block instanceof org.bukkit.block.Chest;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean activateContainer(Player p, boolean anychest, boolean silentchest, int x, int y, int z) {
|
|
||||||
EntityPlayer player = ((CraftPlayer) p).getHandle();
|
|
||||||
World world = player.world;
|
|
||||||
Object chest = world.getTileEntity(x, y, z);
|
|
||||||
if (chest == null)
|
|
||||||
return false;
|
|
||||||
|
|
||||||
if (!anychest && isAnyContainerNeeded(p, x, y, z)) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (world.getTypeId(x - 1, y, z) == Block.CHEST.id)
|
|
||||||
chest = new InventoryLargeChest("Large chest", (TileEntityChest) world.getTileEntity(x - 1, y, z), (IInventory) chest);
|
|
||||||
if (world.getTypeId(x + 1, y, z) == Block.CHEST.id)
|
|
||||||
chest = new InventoryLargeChest("Large chest", (IInventory) chest, (TileEntityChest) world.getTileEntity(x + 1, y, z));
|
|
||||||
if (world.getTypeId(x, y, z - 1) == Block.CHEST.id)
|
|
||||||
chest = new InventoryLargeChest("Large chest", (TileEntityChest) world.getTileEntity(x, y, z - 1), (IInventory) chest);
|
|
||||||
if (world.getTypeId(x, y, z + 1) == Block.CHEST.id)
|
|
||||||
chest = new InventoryLargeChest("Large chest", (IInventory) chest, (TileEntityChest) world.getTileEntity(x, y, z + 1));
|
|
||||||
|
|
||||||
boolean returnValue = false;
|
|
||||||
if (!silentchest) {
|
|
||||||
player.openContainer((IInventory) chest);
|
|
||||||
returnValue = true;
|
|
||||||
} else {
|
|
||||||
try {
|
|
||||||
int id = 0;
|
|
||||||
try {
|
|
||||||
Field windowID = player.getClass().getDeclaredField("containerCounter");
|
|
||||||
windowID.setAccessible(true);
|
|
||||||
id = windowID.getInt(player);
|
|
||||||
id = id % 100 + 1;
|
|
||||||
windowID.setInt(player, id);
|
|
||||||
} catch (NoSuchFieldException e) {}
|
|
||||||
|
|
||||||
player.playerConnection.sendPacket(new Packet100OpenWindow(id, 0, ((IInventory) chest).getName(), ((IInventory) chest).getSize()));
|
|
||||||
player.activeContainer = new SilentContainerChest(player.inventory, ((IInventory) chest));
|
|
||||||
player.activeContainer.windowId = id;
|
|
||||||
player.activeContainer.addSlotListener(player);
|
|
||||||
returnValue = true;
|
|
||||||
} catch (Exception e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
p.sendMessage(ChatColor.RED + "Error while sending silent chest.");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return returnValue;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean isAnyContainerNeeded(Player p, int x, int y, int z) {
|
|
||||||
// FOR REFERENCE, LOOK AT net.minecraft.server.BlockChest
|
|
||||||
EntityPlayer player = ((CraftPlayer) p).getHandle();
|
|
||||||
World world = player.world;
|
|
||||||
|
|
||||||
// If block or ocelot on top
|
|
||||||
if (world.s(x, y + 1, z) || hasOcelotOnTop(world, x, y, z))
|
|
||||||
return true;
|
|
||||||
|
|
||||||
// If block next to chest is chest and has a block or ocelot on top
|
|
||||||
return isBlockedChest(world, x - 1, y, z) || isBlockedChest(world, x + 1, y, z)
|
|
||||||
|| isBlockedChest(world, x, y, z - 1) || isBlockedChest(world, x, y, z + 1);
|
|
||||||
}
|
|
||||||
|
|
||||||
private boolean isBlockedChest(World world, int x, int y, int z) {
|
|
||||||
if (world.getTypeId(x, y, z) != Block.CHEST.id) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (world.s(x, y + 1, z)) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
return hasOcelotOnTop(world, x, y, z);
|
|
||||||
}
|
|
||||||
|
|
||||||
private boolean hasOcelotOnTop(World world, int x, int y, int z) {
|
|
||||||
for (Object localEntity : world.a(EntityOcelot.class,
|
|
||||||
AxisAlignedBB.a().a(x, y + 1, z, x + 1, y + 2, z + 1))) {
|
|
||||||
EntityOcelot localEntityOcelot = (EntityOcelot) localEntity;
|
|
||||||
if (localEntityOcelot.isSitting()) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @deprecated Use {@link #activateContainer(Player, boolean, boolean, int, int, int)}.
|
|
||||||
*/
|
|
||||||
@Deprecated
|
|
||||||
@Override
|
|
||||||
public boolean activateChest(Player player, boolean anychest, boolean silentchest, int x, int y, int z) {
|
|
||||||
return !activateContainer(player, anychest, silentchest, x, y, z);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @deprecated Use {@link #isAnyContainerNeeded(Player, int, int, int)}.
|
|
||||||
*/
|
|
||||||
@Deprecated
|
|
||||||
@Override
|
|
||||||
public boolean isAnyChestNeeded(Player player, int x, int y, int z) {
|
|
||||||
return isAnyContainerNeeded(player, x, y, z);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
@@ -1,50 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright (C) 2011-2014 lishid. All rights reserved.
|
|
||||||
*
|
|
||||||
* This program is free software: you can redistribute it and/or modify
|
|
||||||
* it under the terms of the GNU General Public License as published by
|
|
||||||
* the Free Software Foundation, version 3.
|
|
||||||
*
|
|
||||||
* This program is distributed in the hope that it will be useful,
|
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
* GNU General Public License for more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU General Public License
|
|
||||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package com.lishid.openinv.internal.v1_4_6;
|
|
||||||
|
|
||||||
import org.bukkit.entity.HumanEntity;
|
|
||||||
import org.bukkit.inventory.Inventory;
|
|
||||||
|
|
||||||
import com.lishid.openinv.OpenInv;
|
|
||||||
import com.lishid.openinv.Permissions;
|
|
||||||
import com.lishid.openinv.internal.IInventoryAccess;
|
|
||||||
|
|
||||||
// Volatile
|
|
||||||
import net.minecraft.server.v1_4_6.IInventory;
|
|
||||||
|
|
||||||
import org.bukkit.craftbukkit.v1_4_6.inventory.CraftInventory;
|
|
||||||
|
|
||||||
public class InventoryAccess implements IInventoryAccess {
|
|
||||||
@Override
|
|
||||||
public boolean check(Inventory inventory, HumanEntity player) {
|
|
||||||
IInventory inv = ((CraftInventory) inventory).getInventory();
|
|
||||||
|
|
||||||
if (inv instanceof SpecialPlayerInventory) {
|
|
||||||
if (!OpenInv.hasPermission(player, Permissions.PERM_EDITINV)) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
else if (inv instanceof SpecialEnderChest) {
|
|
||||||
if (!OpenInv.hasPermission(player, Permissions.PERM_EDITENDER)) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
@@ -1,154 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright (C) 2011-2014 lishid. All rights reserved.
|
|
||||||
*
|
|
||||||
* This program is free software: you can redistribute it and/or modify
|
|
||||||
* it under the terms of the GNU General Public License as published by
|
|
||||||
* the Free Software Foundation, version 3.
|
|
||||||
*
|
|
||||||
* This program is distributed in the hope that it will be useful,
|
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
* GNU General Public License for more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU General Public License
|
|
||||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package com.lishid.openinv.internal.v1_4_R1;
|
|
||||||
|
|
||||||
import java.lang.reflect.Field;
|
|
||||||
|
|
||||||
import com.lishid.openinv.internal.IAnySilentContainer;
|
|
||||||
|
|
||||||
import org.bukkit.ChatColor;
|
|
||||||
import org.bukkit.block.BlockState;
|
|
||||||
import org.bukkit.entity.Player;
|
|
||||||
|
|
||||||
// Volatile
|
|
||||||
import net.minecraft.server.v1_4_R1.AxisAlignedBB;
|
|
||||||
import net.minecraft.server.v1_4_R1.Block;
|
|
||||||
import net.minecraft.server.v1_4_R1.EntityOcelot;
|
|
||||||
import net.minecraft.server.v1_4_R1.EntityPlayer;
|
|
||||||
import net.minecraft.server.v1_4_R1.IInventory;
|
|
||||||
import net.minecraft.server.v1_4_R1.InventoryLargeChest;
|
|
||||||
import net.minecraft.server.v1_4_R1.Packet100OpenWindow;
|
|
||||||
import net.minecraft.server.v1_4_R1.TileEntityChest;
|
|
||||||
import net.minecraft.server.v1_4_R1.World;
|
|
||||||
|
|
||||||
import org.bukkit.craftbukkit.v1_4_R1.entity.CraftPlayer;
|
|
||||||
|
|
||||||
public class AnySilentContainer implements IAnySilentContainer {
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean isAnySilentContainer(BlockState block) {
|
|
||||||
return block instanceof org.bukkit.block.Chest;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean activateContainer(Player p, boolean anychest, boolean silentchest, int x, int y, int z) {
|
|
||||||
EntityPlayer player = ((CraftPlayer) p).getHandle();
|
|
||||||
World world = player.world;
|
|
||||||
Object chest = world.getTileEntity(x, y, z);
|
|
||||||
if (chest == null)
|
|
||||||
return false;
|
|
||||||
|
|
||||||
if (!anychest && isAnyContainerNeeded(p, x, y, z)) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (world.getTypeId(x - 1, y, z) == Block.CHEST.id)
|
|
||||||
chest = new InventoryLargeChest("Large chest", (TileEntityChest) world.getTileEntity(x - 1, y, z), (IInventory) chest);
|
|
||||||
if (world.getTypeId(x + 1, y, z) == Block.CHEST.id)
|
|
||||||
chest = new InventoryLargeChest("Large chest", (IInventory) chest, (TileEntityChest) world.getTileEntity(x + 1, y, z));
|
|
||||||
if (world.getTypeId(x, y, z - 1) == Block.CHEST.id)
|
|
||||||
chest = new InventoryLargeChest("Large chest", (TileEntityChest) world.getTileEntity(x, y, z - 1), (IInventory) chest);
|
|
||||||
if (world.getTypeId(x, y, z + 1) == Block.CHEST.id)
|
|
||||||
chest = new InventoryLargeChest("Large chest", (IInventory) chest, (TileEntityChest) world.getTileEntity(x, y, z + 1));
|
|
||||||
|
|
||||||
boolean returnValue = false;
|
|
||||||
if (!silentchest) {
|
|
||||||
player.openContainer((IInventory) chest);
|
|
||||||
returnValue = true;
|
|
||||||
} else {
|
|
||||||
try {
|
|
||||||
int id = 0;
|
|
||||||
try {
|
|
||||||
Field windowID = player.getClass().getDeclaredField("containerCounter");
|
|
||||||
windowID.setAccessible(true);
|
|
||||||
id = windowID.getInt(player);
|
|
||||||
id = id % 100 + 1;
|
|
||||||
windowID.setInt(player, id);
|
|
||||||
} catch (NoSuchFieldException e) {}
|
|
||||||
|
|
||||||
player.playerConnection.sendPacket(new Packet100OpenWindow(id, 0, ((IInventory) chest).getName(), ((IInventory) chest).getSize()));
|
|
||||||
player.activeContainer = new SilentContainerChest(player.inventory, ((IInventory) chest));
|
|
||||||
player.activeContainer.windowId = id;
|
|
||||||
player.activeContainer.addSlotListener(player);
|
|
||||||
returnValue = true;
|
|
||||||
} catch (Exception e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
p.sendMessage(ChatColor.RED + "Error while sending silent chest.");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return returnValue;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean isAnyContainerNeeded(Player p, int x, int y, int z) {
|
|
||||||
// FOR REFERENCE, LOOK AT net.minecraft.server.BlockChest
|
|
||||||
EntityPlayer player = ((CraftPlayer) p).getHandle();
|
|
||||||
World world = player.world;
|
|
||||||
|
|
||||||
// If block or ocelot on top
|
|
||||||
if (world.s(x, y + 1, z) || hasOcelotOnTop(world, x, y, z))
|
|
||||||
return true;
|
|
||||||
|
|
||||||
// If block next to chest is chest and has a block or ocelot on top
|
|
||||||
return isBlockedChest(world, x - 1, y, z) || isBlockedChest(world, x + 1, y, z)
|
|
||||||
|| isBlockedChest(world, x, y, z - 1) || isBlockedChest(world, x, y, z + 1);
|
|
||||||
}
|
|
||||||
|
|
||||||
private boolean isBlockedChest(World world, int x, int y, int z) {
|
|
||||||
if (world.getTypeId(x, y, z) != Block.CHEST.id) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (world.s(x, y + 1, z)) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
return hasOcelotOnTop(world, x, y, z);
|
|
||||||
}
|
|
||||||
|
|
||||||
private boolean hasOcelotOnTop(World world, int x, int y, int z) {
|
|
||||||
for (Object localEntity : world.a(EntityOcelot.class,
|
|
||||||
AxisAlignedBB.a().a(x, y + 1, z, x + 1, y + 2, z + 1))) {
|
|
||||||
EntityOcelot localEntityOcelot = (EntityOcelot) localEntity;
|
|
||||||
if (localEntityOcelot.isSitting()) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @deprecated Use {@link #activateContainer(Player, boolean, boolean, int, int, int)}.
|
|
||||||
*/
|
|
||||||
@Deprecated
|
|
||||||
@Override
|
|
||||||
public boolean activateChest(Player player, boolean anychest, boolean silentchest, int x, int y, int z) {
|
|
||||||
return !activateContainer(player, anychest, silentchest, x, y, z);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @deprecated Use {@link #isAnyContainerNeeded(Player, int, int, int)}.
|
|
||||||
*/
|
|
||||||
@Deprecated
|
|
||||||
@Override
|
|
||||||
public boolean isAnyChestNeeded(Player player, int x, int y, int z) {
|
|
||||||
return isAnyContainerNeeded(player, x, y, z);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
@@ -1,50 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright (C) 2011-2014 lishid. All rights reserved.
|
|
||||||
*
|
|
||||||
* This program is free software: you can redistribute it and/or modify
|
|
||||||
* it under the terms of the GNU General Public License as published by
|
|
||||||
* the Free Software Foundation, version 3.
|
|
||||||
*
|
|
||||||
* This program is distributed in the hope that it will be useful,
|
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
* GNU General Public License for more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU General Public License
|
|
||||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package com.lishid.openinv.internal.v1_4_R1;
|
|
||||||
|
|
||||||
import com.lishid.openinv.OpenInv;
|
|
||||||
import com.lishid.openinv.Permissions;
|
|
||||||
import com.lishid.openinv.internal.IInventoryAccess;
|
|
||||||
|
|
||||||
import org.bukkit.entity.HumanEntity;
|
|
||||||
import org.bukkit.inventory.Inventory;
|
|
||||||
|
|
||||||
// Volatile
|
|
||||||
import net.minecraft.server.v1_4_R1.IInventory;
|
|
||||||
|
|
||||||
import org.bukkit.craftbukkit.v1_4_R1.inventory.CraftInventory;
|
|
||||||
|
|
||||||
public class InventoryAccess implements IInventoryAccess {
|
|
||||||
@Override
|
|
||||||
public boolean check(Inventory inventory, HumanEntity player) {
|
|
||||||
IInventory inv = ((CraftInventory) inventory).getInventory();
|
|
||||||
|
|
||||||
if (inv instanceof SpecialPlayerInventory) {
|
|
||||||
if (!OpenInv.hasPermission(player, Permissions.PERM_EDITINV)) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
else if (inv instanceof SpecialEnderChest) {
|
|
||||||
if (!OpenInv.hasPermission(player, Permissions.PERM_EDITENDER)) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
@@ -1,157 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright (C) 2011-2014 lishid. All rights reserved.
|
|
||||||
*
|
|
||||||
* This program is free software: you can redistribute it and/or modify
|
|
||||||
* it under the terms of the GNU General Public License as published by
|
|
||||||
* the Free Software Foundation, version 3.
|
|
||||||
*
|
|
||||||
* This program is distributed in the hope that it will be useful,
|
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
* GNU General Public License for more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU General Public License
|
|
||||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package com.lishid.openinv.internal.v1_5_R2;
|
|
||||||
|
|
||||||
import java.lang.reflect.Field;
|
|
||||||
|
|
||||||
import com.lishid.openinv.internal.IAnySilentContainer;
|
|
||||||
|
|
||||||
import org.bukkit.ChatColor;
|
|
||||||
import org.bukkit.block.BlockState;
|
|
||||||
import org.bukkit.entity.Player;
|
|
||||||
|
|
||||||
// Volatile
|
|
||||||
import net.minecraft.server.v1_5_R2.AxisAlignedBB;
|
|
||||||
import net.minecraft.server.v1_5_R2.EntityOcelot;
|
|
||||||
import net.minecraft.server.v1_5_R2.EntityPlayer;
|
|
||||||
import net.minecraft.server.v1_5_R2.IInventory;
|
|
||||||
import net.minecraft.server.v1_5_R2.InventoryLargeChest;
|
|
||||||
import net.minecraft.server.v1_5_R2.Packet100OpenWindow;
|
|
||||||
import net.minecraft.server.v1_5_R2.TileEntityChest;
|
|
||||||
import net.minecraft.server.v1_5_R2.World;
|
|
||||||
|
|
||||||
import org.bukkit.craftbukkit.v1_5_R2.entity.CraftPlayer;
|
|
||||||
|
|
||||||
public class AnySilentContainer implements IAnySilentContainer {
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean isAnySilentContainer(BlockState block) {
|
|
||||||
return block instanceof org.bukkit.block.Chest;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean activateContainer(Player p, boolean anychest, boolean silentchest, int x, int y, int z) {
|
|
||||||
EntityPlayer player = ((CraftPlayer) p).getHandle();
|
|
||||||
World world = player.world;
|
|
||||||
Object chest = world.getTileEntity(x, y, z);
|
|
||||||
if (chest == null)
|
|
||||||
return false;
|
|
||||||
|
|
||||||
if (!anychest && isAnyContainerNeeded(p, x, y, z)) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
int id = world.getTypeId(x, y, z);
|
|
||||||
|
|
||||||
if (world.getTypeId(x - 1, y, z) == id)
|
|
||||||
chest = new InventoryLargeChest("Large chest", (TileEntityChest) world.getTileEntity(x - 1, y, z), (IInventory) chest);
|
|
||||||
if (world.getTypeId(x + 1, y, z) == id)
|
|
||||||
chest = new InventoryLargeChest("Large chest", (IInventory) chest, (TileEntityChest) world.getTileEntity(x + 1, y, z));
|
|
||||||
if (world.getTypeId(x, y, z - 1) == id)
|
|
||||||
chest = new InventoryLargeChest("Large chest", (TileEntityChest) world.getTileEntity(x, y, z - 1), (IInventory) chest);
|
|
||||||
if (world.getTypeId(x, y, z + 1) == id)
|
|
||||||
chest = new InventoryLargeChest("Large chest", (IInventory) chest, (TileEntityChest) world.getTileEntity(x, y, z + 1));
|
|
||||||
|
|
||||||
boolean returnValue = false;
|
|
||||||
if (!silentchest) {
|
|
||||||
player.openContainer((IInventory) chest);
|
|
||||||
returnValue = true;
|
|
||||||
} else {
|
|
||||||
try {
|
|
||||||
int windowId = 0;
|
|
||||||
try {
|
|
||||||
Field windowID = player.getClass().getDeclaredField("containerCounter");
|
|
||||||
windowID.setAccessible(true);
|
|
||||||
windowId = windowID.getInt(player);
|
|
||||||
windowId = windowId % 100 + 1;
|
|
||||||
windowID.setInt(player, windowId);
|
|
||||||
} catch (NoSuchFieldException e) {}
|
|
||||||
|
|
||||||
player.playerConnection.sendPacket(new Packet100OpenWindow(windowId, 0, ((IInventory) chest).getName(), ((IInventory) chest).getSize(), true));
|
|
||||||
player.activeContainer = new SilentContainerChest(player.inventory, ((IInventory) chest));
|
|
||||||
player.activeContainer.windowId = windowId;
|
|
||||||
player.activeContainer.addSlotListener(player);
|
|
||||||
returnValue = true;
|
|
||||||
} catch (Exception e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
p.sendMessage(ChatColor.RED + "Error while sending silent chest.");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return returnValue;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean isAnyContainerNeeded(Player p, int x, int y, int z) {
|
|
||||||
// FOR REFERENCE, LOOK AT net.minecraft.server.BlockChest
|
|
||||||
EntityPlayer player = ((CraftPlayer) p).getHandle();
|
|
||||||
World world = player.world;
|
|
||||||
|
|
||||||
// If block or ocelot on top
|
|
||||||
if (world.t(x, y + 1, z) || hasOcelotOnTop(world, x, y, z))
|
|
||||||
return true;
|
|
||||||
|
|
||||||
int id = world.getTypeId(x, y, z);
|
|
||||||
|
|
||||||
// If block next to chest is chest and has a block or ocelot on top
|
|
||||||
return isBlockedChest(world, id, x - 1, y, z) || isBlockedChest(world, id, x + 1, y, z)
|
|
||||||
|| isBlockedChest(world, id, x, y, z - 1) || isBlockedChest(world, id, x, y, z + 1);
|
|
||||||
}
|
|
||||||
|
|
||||||
private boolean isBlockedChest(World world, int id, int x, int y, int z) {
|
|
||||||
if (world.getTypeId(x, y, z) != id) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (world.t(x, y + 1, z)) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
return hasOcelotOnTop(world, x, y, z);
|
|
||||||
}
|
|
||||||
|
|
||||||
private boolean hasOcelotOnTop(World world, int x, int y, int z) {
|
|
||||||
for (Object localEntity : world.a(EntityOcelot.class,
|
|
||||||
AxisAlignedBB.a().a(x, y + 1, z, x + 1, y + 2, z + 1))) {
|
|
||||||
EntityOcelot localEntityOcelot = (EntityOcelot) localEntity;
|
|
||||||
if (localEntityOcelot.isSitting()) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @deprecated Use {@link #activateContainer(Player, boolean, boolean, int, int, int)}.
|
|
||||||
*/
|
|
||||||
@Deprecated
|
|
||||||
@Override
|
|
||||||
public boolean activateChest(Player player, boolean anychest, boolean silentchest, int x, int y, int z) {
|
|
||||||
return !activateContainer(player, anychest, silentchest, x, y, z);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @deprecated Use {@link #isAnyContainerNeeded(Player, int, int, int)}.
|
|
||||||
*/
|
|
||||||
@Deprecated
|
|
||||||
@Override
|
|
||||||
public boolean isAnyChestNeeded(Player player, int x, int y, int z) {
|
|
||||||
return isAnyContainerNeeded(player, x, y, z);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
@@ -1,50 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright (C) 2011-2014 lishid. All rights reserved.
|
|
||||||
*
|
|
||||||
* This program is free software: you can redistribute it and/or modify
|
|
||||||
* it under the terms of the GNU General Public License as published by
|
|
||||||
* the Free Software Foundation, version 3.
|
|
||||||
*
|
|
||||||
* This program is distributed in the hope that it will be useful,
|
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
* GNU General Public License for more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU General Public License
|
|
||||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package com.lishid.openinv.internal.v1_5_R2;
|
|
||||||
|
|
||||||
import com.lishid.openinv.OpenInv;
|
|
||||||
import com.lishid.openinv.Permissions;
|
|
||||||
import com.lishid.openinv.internal.IInventoryAccess;
|
|
||||||
|
|
||||||
import org.bukkit.entity.HumanEntity;
|
|
||||||
import org.bukkit.inventory.Inventory;
|
|
||||||
|
|
||||||
// Volatile
|
|
||||||
import net.minecraft.server.v1_5_R2.IInventory;
|
|
||||||
|
|
||||||
import org.bukkit.craftbukkit.v1_5_R2.inventory.CraftInventory;
|
|
||||||
|
|
||||||
public class InventoryAccess implements IInventoryAccess {
|
|
||||||
@Override
|
|
||||||
public boolean check(Inventory inventory, HumanEntity player) {
|
|
||||||
IInventory inv = ((CraftInventory) inventory).getInventory();
|
|
||||||
|
|
||||||
if (inv instanceof SpecialPlayerInventory) {
|
|
||||||
if (!OpenInv.hasPermission(player, Permissions.PERM_EDITINV)) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
else if (inv instanceof SpecialEnderChest) {
|
|
||||||
if (!OpenInv.hasPermission(player, Permissions.PERM_EDITENDER)) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
@@ -1,157 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright (C) 2011-2014 lishid. All rights reserved.
|
|
||||||
*
|
|
||||||
* This program is free software: you can redistribute it and/or modify
|
|
||||||
* it under the terms of the GNU General Public License as published by
|
|
||||||
* the Free Software Foundation, version 3.
|
|
||||||
*
|
|
||||||
* This program is distributed in the hope that it will be useful,
|
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
* GNU General Public License for more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU General Public License
|
|
||||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package com.lishid.openinv.internal.v1_5_R3;
|
|
||||||
|
|
||||||
import java.lang.reflect.Field;
|
|
||||||
|
|
||||||
import com.lishid.openinv.internal.IAnySilentContainer;
|
|
||||||
|
|
||||||
import org.bukkit.ChatColor;
|
|
||||||
import org.bukkit.block.BlockState;
|
|
||||||
import org.bukkit.entity.Player;
|
|
||||||
|
|
||||||
//Volatile
|
|
||||||
import net.minecraft.server.v1_5_R3.AxisAlignedBB;
|
|
||||||
import net.minecraft.server.v1_5_R3.EntityOcelot;
|
|
||||||
import net.minecraft.server.v1_5_R3.EntityPlayer;
|
|
||||||
import net.minecraft.server.v1_5_R3.IInventory;
|
|
||||||
import net.minecraft.server.v1_5_R3.InventoryLargeChest;
|
|
||||||
import net.minecraft.server.v1_5_R3.Packet100OpenWindow;
|
|
||||||
import net.minecraft.server.v1_5_R3.TileEntityChest;
|
|
||||||
import net.minecraft.server.v1_5_R3.World;
|
|
||||||
|
|
||||||
import org.bukkit.craftbukkit.v1_5_R3.entity.CraftPlayer;
|
|
||||||
|
|
||||||
public class AnySilentContainer implements IAnySilentContainer {
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean isAnySilentContainer(BlockState block) {
|
|
||||||
return block instanceof org.bukkit.block.Chest;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean activateContainer(Player p, boolean anychest, boolean silentchest, int x, int y, int z) {
|
|
||||||
EntityPlayer player = ((CraftPlayer) p).getHandle();
|
|
||||||
World world = player.world;
|
|
||||||
Object chest = world.getTileEntity(x, y, z);
|
|
||||||
if (chest == null)
|
|
||||||
return false;
|
|
||||||
|
|
||||||
if (!anychest && isAnyContainerNeeded(p, x, y, z)) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
int id = world.getTypeId(x, y, z);
|
|
||||||
|
|
||||||
if (world.getTypeId(x - 1, y, z) == id)
|
|
||||||
chest = new InventoryLargeChest("Large chest", (TileEntityChest) world.getTileEntity(x - 1, y, z), (IInventory) chest);
|
|
||||||
if (world.getTypeId(x + 1, y, z) == id)
|
|
||||||
chest = new InventoryLargeChest("Large chest", (IInventory) chest, (TileEntityChest) world.getTileEntity(x + 1, y, z));
|
|
||||||
if (world.getTypeId(x, y, z - 1) == id)
|
|
||||||
chest = new InventoryLargeChest("Large chest", (TileEntityChest) world.getTileEntity(x, y, z - 1), (IInventory) chest);
|
|
||||||
if (world.getTypeId(x, y, z + 1) == id)
|
|
||||||
chest = new InventoryLargeChest("Large chest", (IInventory) chest, (TileEntityChest) world.getTileEntity(x, y, z + 1));
|
|
||||||
|
|
||||||
boolean returnValue = false;
|
|
||||||
if (!silentchest) {
|
|
||||||
player.openContainer((IInventory) chest);
|
|
||||||
returnValue = true;
|
|
||||||
} else {
|
|
||||||
try {
|
|
||||||
int windowId = 0;
|
|
||||||
try {
|
|
||||||
Field windowID = player.getClass().getDeclaredField("containerCounter");
|
|
||||||
windowID.setAccessible(true);
|
|
||||||
windowId = windowID.getInt(player);
|
|
||||||
windowId = windowId % 100 + 1;
|
|
||||||
windowID.setInt(player, windowId);
|
|
||||||
} catch (NoSuchFieldException e) {}
|
|
||||||
|
|
||||||
player.playerConnection.sendPacket(new Packet100OpenWindow(windowId, 0, ((IInventory) chest).getName(), ((IInventory) chest).getSize(), true));
|
|
||||||
player.activeContainer = new SilentContainerChest(player.inventory, ((IInventory) chest));
|
|
||||||
player.activeContainer.windowId = windowId;
|
|
||||||
player.activeContainer.addSlotListener(player);
|
|
||||||
returnValue = true;
|
|
||||||
} catch (Exception e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
p.sendMessage(ChatColor.RED + "Error while sending silent chest.");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return returnValue;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean isAnyContainerNeeded(Player p, int x, int y, int z) {
|
|
||||||
// FOR REFERENCE, LOOK AT net.minecraft.server.BlockChest
|
|
||||||
EntityPlayer player = ((CraftPlayer) p).getHandle();
|
|
||||||
World world = player.world;
|
|
||||||
|
|
||||||
// If block or ocelot on top
|
|
||||||
if (world.t(x, y + 1, z) || hasOcelotOnTop(world, x, y, z))
|
|
||||||
return true;
|
|
||||||
|
|
||||||
int id = world.getTypeId(x, y, z);
|
|
||||||
|
|
||||||
// If block next to chest is chest and has a block or ocelot on top
|
|
||||||
return isBlockedChest(world, id, x - 1, y, z) || isBlockedChest(world, id, x + 1, y, z)
|
|
||||||
|| isBlockedChest(world, id, x, y, z - 1) || isBlockedChest(world, id, x, y, z + 1);
|
|
||||||
}
|
|
||||||
|
|
||||||
private boolean isBlockedChest(World world, int id, int x, int y, int z) {
|
|
||||||
if (world.getTypeId(x, y, z) != id) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (world.t(x, y + 1, z)) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
return hasOcelotOnTop(world, x, y, z);
|
|
||||||
}
|
|
||||||
|
|
||||||
private boolean hasOcelotOnTop(World world, int x, int y, int z) {
|
|
||||||
for (Object localEntity : world.a(EntityOcelot.class,
|
|
||||||
AxisAlignedBB.a().a(x, y + 1, z, x + 1, y + 2, z + 1))) {
|
|
||||||
EntityOcelot localEntityOcelot = (EntityOcelot) localEntity;
|
|
||||||
if (localEntityOcelot.isSitting()) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @deprecated Use {@link #activateContainer(Player, boolean, boolean, int, int, int)}.
|
|
||||||
*/
|
|
||||||
@Deprecated
|
|
||||||
@Override
|
|
||||||
public boolean activateChest(Player player, boolean anychest, boolean silentchest, int x, int y, int z) {
|
|
||||||
return !activateContainer(player, anychest, silentchest, x, y, z);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @deprecated Use {@link #isAnyContainerNeeded(Player, int, int, int)}.
|
|
||||||
*/
|
|
||||||
@Deprecated
|
|
||||||
@Override
|
|
||||||
public boolean isAnyChestNeeded(Player player, int x, int y, int z) {
|
|
||||||
return isAnyContainerNeeded(player, x, y, z);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
@@ -1,50 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright (C) 2011-2014 lishid. All rights reserved.
|
|
||||||
*
|
|
||||||
* This program is free software: you can redistribute it and/or modify
|
|
||||||
* it under the terms of the GNU General Public License as published by
|
|
||||||
* the Free Software Foundation, version 3.
|
|
||||||
*
|
|
||||||
* This program is distributed in the hope that it will be useful,
|
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
* GNU General Public License for more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU General Public License
|
|
||||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package com.lishid.openinv.internal.v1_5_R3;
|
|
||||||
|
|
||||||
import com.lishid.openinv.OpenInv;
|
|
||||||
import com.lishid.openinv.Permissions;
|
|
||||||
import com.lishid.openinv.internal.IInventoryAccess;
|
|
||||||
|
|
||||||
import org.bukkit.entity.HumanEntity;
|
|
||||||
import org.bukkit.inventory.Inventory;
|
|
||||||
|
|
||||||
// Volatile
|
|
||||||
import net.minecraft.server.v1_5_R3.IInventory;
|
|
||||||
|
|
||||||
import org.bukkit.craftbukkit.v1_5_R3.inventory.CraftInventory;
|
|
||||||
|
|
||||||
public class InventoryAccess implements IInventoryAccess {
|
|
||||||
@Override
|
|
||||||
public boolean check(Inventory inventory, HumanEntity player) {
|
|
||||||
IInventory inv = ((CraftInventory) inventory).getInventory();
|
|
||||||
|
|
||||||
if (inv instanceof SpecialPlayerInventory) {
|
|
||||||
if (!OpenInv.hasPermission(player, Permissions.PERM_EDITINV)) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
else if (inv instanceof SpecialEnderChest) {
|
|
||||||
if (!OpenInv.hasPermission(player, Permissions.PERM_EDITENDER)) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
@@ -1,157 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright (C) 2011-2014 lishid. All rights reserved.
|
|
||||||
*
|
|
||||||
* This program is free software: you can redistribute it and/or modify
|
|
||||||
* it under the terms of the GNU General Public License as published by
|
|
||||||
* the Free Software Foundation, version 3.
|
|
||||||
*
|
|
||||||
* This program is distributed in the hope that it will be useful,
|
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
* GNU General Public License for more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU General Public License
|
|
||||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package com.lishid.openinv.internal.v1_6_R1;
|
|
||||||
|
|
||||||
import java.lang.reflect.Field;
|
|
||||||
|
|
||||||
import com.lishid.openinv.internal.IAnySilentContainer;
|
|
||||||
|
|
||||||
import org.bukkit.ChatColor;
|
|
||||||
import org.bukkit.block.BlockState;
|
|
||||||
import org.bukkit.entity.Player;
|
|
||||||
|
|
||||||
// Volatile
|
|
||||||
import net.minecraft.server.v1_6_R1.AxisAlignedBB;
|
|
||||||
import net.minecraft.server.v1_6_R1.EntityOcelot;
|
|
||||||
import net.minecraft.server.v1_6_R1.EntityPlayer;
|
|
||||||
import net.minecraft.server.v1_6_R1.IInventory;
|
|
||||||
import net.minecraft.server.v1_6_R1.InventoryLargeChest;
|
|
||||||
import net.minecraft.server.v1_6_R1.Packet100OpenWindow;
|
|
||||||
import net.minecraft.server.v1_6_R1.TileEntityChest;
|
|
||||||
import net.minecraft.server.v1_6_R1.World;
|
|
||||||
|
|
||||||
import org.bukkit.craftbukkit.v1_6_R1.entity.CraftPlayer;
|
|
||||||
|
|
||||||
public class AnySilentContainer implements IAnySilentContainer {
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean isAnySilentContainer(BlockState block) {
|
|
||||||
return block instanceof org.bukkit.block.Chest;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean activateContainer(Player p, boolean anychest, boolean silentchest, int x, int y, int z) {
|
|
||||||
EntityPlayer player = ((CraftPlayer) p).getHandle();
|
|
||||||
World world = player.world;
|
|
||||||
Object chest = world.getTileEntity(x, y, z);
|
|
||||||
if (chest == null)
|
|
||||||
return false;
|
|
||||||
|
|
||||||
if (!anychest && isAnyContainerNeeded(p, x, y, z)) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
int id = world.getTypeId(x, y, z);
|
|
||||||
|
|
||||||
if (world.getTypeId(x - 1, y, z) == id)
|
|
||||||
chest = new InventoryLargeChest("Large chest", (TileEntityChest) world.getTileEntity(x - 1, y, z), (IInventory) chest);
|
|
||||||
if (world.getTypeId(x + 1, y, z) == id)
|
|
||||||
chest = new InventoryLargeChest("Large chest", (IInventory) chest, (TileEntityChest) world.getTileEntity(x + 1, y, z));
|
|
||||||
if (world.getTypeId(x, y, z - 1) == id)
|
|
||||||
chest = new InventoryLargeChest("Large chest", (TileEntityChest) world.getTileEntity(x, y, z - 1), (IInventory) chest);
|
|
||||||
if (world.getTypeId(x, y, z + 1) == id)
|
|
||||||
chest = new InventoryLargeChest("Large chest", (IInventory) chest, (TileEntityChest) world.getTileEntity(x, y, z + 1));
|
|
||||||
|
|
||||||
boolean returnValue = false;
|
|
||||||
if (!silentchest) {
|
|
||||||
player.openContainer((IInventory) chest);
|
|
||||||
returnValue = true;
|
|
||||||
} else {
|
|
||||||
try {
|
|
||||||
int windowId = 0;
|
|
||||||
try {
|
|
||||||
Field windowID = player.getClass().getDeclaredField("containerCounter");
|
|
||||||
windowID.setAccessible(true);
|
|
||||||
windowId = windowID.getInt(player);
|
|
||||||
windowId = windowId % 100 + 1;
|
|
||||||
windowID.setInt(player, windowId);
|
|
||||||
} catch (NoSuchFieldException e) {}
|
|
||||||
|
|
||||||
player.playerConnection.sendPacket(new Packet100OpenWindow(windowId, 0, ((IInventory) chest).getName(), ((IInventory) chest).getSize(), true));
|
|
||||||
player.activeContainer = new SilentContainerChest(player.inventory, ((IInventory) chest));
|
|
||||||
player.activeContainer.windowId = windowId;
|
|
||||||
player.activeContainer.addSlotListener(player);
|
|
||||||
returnValue = true;
|
|
||||||
} catch (Exception e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
p.sendMessage(ChatColor.RED + "Error while sending silent chest.");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return returnValue;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean isAnyContainerNeeded(Player p, int x, int y, int z) {
|
|
||||||
// FOR REFERENCE, LOOK AT net.minecraft.server.BlockChest
|
|
||||||
EntityPlayer player = ((CraftPlayer) p).getHandle();
|
|
||||||
World world = player.world;
|
|
||||||
|
|
||||||
// If block or ocelot on top
|
|
||||||
if (world.t(x, y + 1, z) || hasOcelotOnTop(world, x, y, z))
|
|
||||||
return true;
|
|
||||||
|
|
||||||
int id = world.getTypeId(x, y, z);
|
|
||||||
|
|
||||||
// If block next to chest is chest and has a block or ocelot on top
|
|
||||||
return isBlockedChest(world, id, x - 1, y, z) || isBlockedChest(world, id, x + 1, y, z)
|
|
||||||
|| isBlockedChest(world, id, x, y, z - 1) || isBlockedChest(world, id, x, y, z + 1);
|
|
||||||
}
|
|
||||||
|
|
||||||
private boolean isBlockedChest(World world, int id, int x, int y, int z) {
|
|
||||||
if (world.getTypeId(x, y, z) != id) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (world.t(x, y + 1, z)) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
return hasOcelotOnTop(world, x, y, z);
|
|
||||||
}
|
|
||||||
|
|
||||||
private boolean hasOcelotOnTop(World world, int x, int y, int z) {
|
|
||||||
for (Object localEntity : world.a(EntityOcelot.class,
|
|
||||||
AxisAlignedBB.a().a(x, y + 1, z, x + 1, y + 2, z + 1))) {
|
|
||||||
EntityOcelot localEntityOcelot = (EntityOcelot) localEntity;
|
|
||||||
if (localEntityOcelot.isSitting()) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @deprecated Use {@link #activateContainer(Player, boolean, boolean, int, int, int)}.
|
|
||||||
*/
|
|
||||||
@Deprecated
|
|
||||||
@Override
|
|
||||||
public boolean activateChest(Player player, boolean anychest, boolean silentchest, int x, int y, int z) {
|
|
||||||
return !activateContainer(player, anychest, silentchest, x, y, z);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @deprecated Use {@link #isAnyContainerNeeded(Player, int, int, int)}.
|
|
||||||
*/
|
|
||||||
@Deprecated
|
|
||||||
@Override
|
|
||||||
public boolean isAnyChestNeeded(Player player, int x, int y, int z) {
|
|
||||||
return isAnyContainerNeeded(player, x, y, z);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
@@ -1,50 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright (C) 2011-2014 lishid. All rights reserved.
|
|
||||||
*
|
|
||||||
* This program is free software: you can redistribute it and/or modify
|
|
||||||
* it under the terms of the GNU General Public License as published by
|
|
||||||
* the Free Software Foundation, version 3.
|
|
||||||
*
|
|
||||||
* This program is distributed in the hope that it will be useful,
|
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
* GNU General Public License for more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU General Public License
|
|
||||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package com.lishid.openinv.internal.v1_6_R1;
|
|
||||||
|
|
||||||
import com.lishid.openinv.OpenInv;
|
|
||||||
import com.lishid.openinv.Permissions;
|
|
||||||
import com.lishid.openinv.internal.IInventoryAccess;
|
|
||||||
|
|
||||||
import org.bukkit.entity.HumanEntity;
|
|
||||||
import org.bukkit.inventory.Inventory;
|
|
||||||
|
|
||||||
// Volatile
|
|
||||||
import net.minecraft.server.v1_6_R1.IInventory;
|
|
||||||
|
|
||||||
import org.bukkit.craftbukkit.v1_6_R1.inventory.CraftInventory;
|
|
||||||
|
|
||||||
public class InventoryAccess implements IInventoryAccess {
|
|
||||||
@Override
|
|
||||||
public boolean check(Inventory inventory, HumanEntity player) {
|
|
||||||
IInventory inv = ((CraftInventory) inventory).getInventory();
|
|
||||||
|
|
||||||
if (inv instanceof SpecialPlayerInventory) {
|
|
||||||
if (!OpenInv.hasPermission(player, Permissions.PERM_EDITINV)) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
else if (inv instanceof SpecialEnderChest) {
|
|
||||||
if (!OpenInv.hasPermission(player, Permissions.PERM_EDITENDER)) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
@@ -1,157 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright (C) 2011-2014 lishid. All rights reserved.
|
|
||||||
*
|
|
||||||
* This program is free software: you can redistribute it and/or modify
|
|
||||||
* it under the terms of the GNU General Public License as published by
|
|
||||||
* the Free Software Foundation, version 3.
|
|
||||||
*
|
|
||||||
* This program is distributed in the hope that it will be useful,
|
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
* GNU General Public License for more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU General Public License
|
|
||||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package com.lishid.openinv.internal.v1_6_R2;
|
|
||||||
|
|
||||||
import java.lang.reflect.Field;
|
|
||||||
|
|
||||||
import com.lishid.openinv.internal.IAnySilentContainer;
|
|
||||||
|
|
||||||
import org.bukkit.ChatColor;
|
|
||||||
import org.bukkit.block.BlockState;
|
|
||||||
import org.bukkit.entity.Player;
|
|
||||||
|
|
||||||
// Volatile
|
|
||||||
import net.minecraft.server.v1_6_R2.AxisAlignedBB;
|
|
||||||
import net.minecraft.server.v1_6_R2.EntityOcelot;
|
|
||||||
import net.minecraft.server.v1_6_R2.EntityPlayer;
|
|
||||||
import net.minecraft.server.v1_6_R2.IInventory;
|
|
||||||
import net.minecraft.server.v1_6_R2.InventoryLargeChest;
|
|
||||||
import net.minecraft.server.v1_6_R2.Packet100OpenWindow;
|
|
||||||
import net.minecraft.server.v1_6_R2.TileEntityChest;
|
|
||||||
import net.minecraft.server.v1_6_R2.World;
|
|
||||||
|
|
||||||
import org.bukkit.craftbukkit.v1_6_R2.entity.CraftPlayer;
|
|
||||||
|
|
||||||
public class AnySilentContainer implements IAnySilentContainer {
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean isAnySilentContainer(BlockState block) {
|
|
||||||
return block instanceof org.bukkit.block.Chest;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean activateContainer(Player p, boolean anychest, boolean silentchest, int x, int y, int z) {
|
|
||||||
EntityPlayer player = ((CraftPlayer) p).getHandle();
|
|
||||||
World world = player.world;
|
|
||||||
Object chest = world.getTileEntity(x, y, z);
|
|
||||||
if (chest == null)
|
|
||||||
return false;
|
|
||||||
|
|
||||||
if (!anychest && isAnyContainerNeeded(p, x, y, z)) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
int id = world.getTypeId(x, y, z);
|
|
||||||
|
|
||||||
if (world.getTypeId(x - 1, y, z) == id)
|
|
||||||
chest = new InventoryLargeChest("Large chest", (TileEntityChest) world.getTileEntity(x - 1, y, z), (IInventory) chest);
|
|
||||||
if (world.getTypeId(x + 1, y, z) == id)
|
|
||||||
chest = new InventoryLargeChest("Large chest", (IInventory) chest, (TileEntityChest) world.getTileEntity(x + 1, y, z));
|
|
||||||
if (world.getTypeId(x, y, z - 1) == id)
|
|
||||||
chest = new InventoryLargeChest("Large chest", (TileEntityChest) world.getTileEntity(x, y, z - 1), (IInventory) chest);
|
|
||||||
if (world.getTypeId(x, y, z + 1) == id)
|
|
||||||
chest = new InventoryLargeChest("Large chest", (IInventory) chest, (TileEntityChest) world.getTileEntity(x, y, z + 1));
|
|
||||||
|
|
||||||
boolean returnValue = false;
|
|
||||||
if (!silentchest) {
|
|
||||||
player.openContainer((IInventory) chest);
|
|
||||||
returnValue = true;
|
|
||||||
} else {
|
|
||||||
try {
|
|
||||||
int windowId = 0;
|
|
||||||
try {
|
|
||||||
Field windowID = player.getClass().getDeclaredField("containerCounter");
|
|
||||||
windowID.setAccessible(true);
|
|
||||||
windowId = windowID.getInt(player);
|
|
||||||
windowId = windowId % 100 + 1;
|
|
||||||
windowID.setInt(player, windowId);
|
|
||||||
} catch (NoSuchFieldException e) {}
|
|
||||||
|
|
||||||
player.playerConnection.sendPacket(new Packet100OpenWindow(windowId, 0, ((IInventory) chest).getName(), ((IInventory) chest).getSize(), true));
|
|
||||||
player.activeContainer = new SilentContainerChest(player.inventory, ((IInventory) chest));
|
|
||||||
player.activeContainer.windowId = windowId;
|
|
||||||
player.activeContainer.addSlotListener(player);
|
|
||||||
returnValue = true;
|
|
||||||
} catch (Exception e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
p.sendMessage(ChatColor.RED + "Error while sending silent chest.");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return returnValue;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean isAnyContainerNeeded(Player p, int x, int y, int z) {
|
|
||||||
// FOR REFERENCE, LOOK AT net.minecraft.server.BlockChest
|
|
||||||
EntityPlayer player = ((CraftPlayer) p).getHandle();
|
|
||||||
World world = player.world;
|
|
||||||
|
|
||||||
// If block or ocelot on top
|
|
||||||
if (world.t(x, y + 1, z) || hasOcelotOnTop(world, x, y, z))
|
|
||||||
return true;
|
|
||||||
|
|
||||||
int id = world.getTypeId(x, y, z);
|
|
||||||
|
|
||||||
// If block next to chest is chest and has a block or ocelot on top
|
|
||||||
return isBlockedChest(world, id, x - 1, y, z) || isBlockedChest(world, id, x + 1, y, z)
|
|
||||||
|| isBlockedChest(world, id, x, y, z - 1) || isBlockedChest(world, id, x, y, z + 1);
|
|
||||||
}
|
|
||||||
|
|
||||||
private boolean isBlockedChest(World world, int id, int x, int y, int z) {
|
|
||||||
if (world.getTypeId(x, y, z) != id) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (world.t(x, y + 1, z)) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
return hasOcelotOnTop(world, x, y, z);
|
|
||||||
}
|
|
||||||
|
|
||||||
private boolean hasOcelotOnTop(World world, int x, int y, int z) {
|
|
||||||
for (Object localEntity : world.a(EntityOcelot.class,
|
|
||||||
AxisAlignedBB.a().a(x, y + 1, z, x + 1, y + 2, z + 1))) {
|
|
||||||
EntityOcelot localEntityOcelot = (EntityOcelot) localEntity;
|
|
||||||
if (localEntityOcelot.isSitting()) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @deprecated Use {@link #activateContainer(Player, boolean, boolean, int, int, int)}.
|
|
||||||
*/
|
|
||||||
@Deprecated
|
|
||||||
@Override
|
|
||||||
public boolean activateChest(Player player, boolean anychest, boolean silentchest, int x, int y, int z) {
|
|
||||||
return !activateContainer(player, anychest, silentchest, x, y, z);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @deprecated Use {@link #isAnyContainerNeeded(Player, int, int, int)}.
|
|
||||||
*/
|
|
||||||
@Deprecated
|
|
||||||
@Override
|
|
||||||
public boolean isAnyChestNeeded(Player player, int x, int y, int z) {
|
|
||||||
return isAnyContainerNeeded(player, x, y, z);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
@@ -1,50 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright (C) 2011-2014 lishid. All rights reserved.
|
|
||||||
*
|
|
||||||
* This program is free software: you can redistribute it and/or modify
|
|
||||||
* it under the terms of the GNU General Public License as published by
|
|
||||||
* the Free Software Foundation, version 3.
|
|
||||||
*
|
|
||||||
* This program is distributed in the hope that it will be useful,
|
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
* GNU General Public License for more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU General Public License
|
|
||||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package com.lishid.openinv.internal.v1_6_R2;
|
|
||||||
|
|
||||||
import com.lishid.openinv.OpenInv;
|
|
||||||
import com.lishid.openinv.Permissions;
|
|
||||||
import com.lishid.openinv.internal.IInventoryAccess;
|
|
||||||
|
|
||||||
import org.bukkit.entity.HumanEntity;
|
|
||||||
import org.bukkit.inventory.Inventory;
|
|
||||||
|
|
||||||
// Volatile
|
|
||||||
import net.minecraft.server.v1_6_R2.IInventory;
|
|
||||||
|
|
||||||
import org.bukkit.craftbukkit.v1_6_R2.inventory.CraftInventory;
|
|
||||||
|
|
||||||
public class InventoryAccess implements IInventoryAccess {
|
|
||||||
@Override
|
|
||||||
public boolean check(Inventory inventory, HumanEntity player) {
|
|
||||||
IInventory inv = ((CraftInventory) inventory).getInventory();
|
|
||||||
|
|
||||||
if (inv instanceof SpecialPlayerInventory) {
|
|
||||||
if (!OpenInv.hasPermission(player, Permissions.PERM_EDITINV)) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
else if (inv instanceof SpecialEnderChest) {
|
|
||||||
if (!OpenInv.hasPermission(player, Permissions.PERM_EDITENDER)) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
@@ -1,157 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright (C) 2011-2014 lishid. All rights reserved.
|
|
||||||
*
|
|
||||||
* This program is free software: you can redistribute it and/or modify
|
|
||||||
* it under the terms of the GNU General Public License as published by
|
|
||||||
* the Free Software Foundation, version 3.
|
|
||||||
*
|
|
||||||
* This program is distributed in the hope that it will be useful,
|
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
* GNU General Public License for more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU General Public License
|
|
||||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package com.lishid.openinv.internal.v1_6_R3;
|
|
||||||
|
|
||||||
import java.lang.reflect.Field;
|
|
||||||
|
|
||||||
import com.lishid.openinv.internal.IAnySilentContainer;
|
|
||||||
|
|
||||||
import org.bukkit.ChatColor;
|
|
||||||
import org.bukkit.block.BlockState;
|
|
||||||
import org.bukkit.entity.Player;
|
|
||||||
|
|
||||||
// Volatile
|
|
||||||
import net.minecraft.server.v1_6_R3.AxisAlignedBB;
|
|
||||||
import net.minecraft.server.v1_6_R3.EntityOcelot;
|
|
||||||
import net.minecraft.server.v1_6_R3.EntityPlayer;
|
|
||||||
import net.minecraft.server.v1_6_R3.IInventory;
|
|
||||||
import net.minecraft.server.v1_6_R3.InventoryLargeChest;
|
|
||||||
import net.minecraft.server.v1_6_R3.Packet100OpenWindow;
|
|
||||||
import net.minecraft.server.v1_6_R3.TileEntityChest;
|
|
||||||
import net.minecraft.server.v1_6_R3.World;
|
|
||||||
|
|
||||||
import org.bukkit.craftbukkit.v1_6_R3.entity.CraftPlayer;
|
|
||||||
|
|
||||||
public class AnySilentContainer implements IAnySilentContainer {
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean isAnySilentContainer(BlockState block) {
|
|
||||||
return block instanceof org.bukkit.block.Chest;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean activateContainer(Player p, boolean anychest, boolean silentchest, int x, int y, int z) {
|
|
||||||
EntityPlayer player = ((CraftPlayer) p).getHandle();
|
|
||||||
World world = player.world;
|
|
||||||
Object chest = world.getTileEntity(x, y, z);
|
|
||||||
if (chest == null)
|
|
||||||
return false;
|
|
||||||
|
|
||||||
if (!anychest && isAnyContainerNeeded(p, x, y, z)) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
int id = world.getTypeId(x, y, z);
|
|
||||||
|
|
||||||
if (world.getTypeId(x - 1, y, z) == id)
|
|
||||||
chest = new InventoryLargeChest("Large chest", (TileEntityChest) world.getTileEntity(x - 1, y, z), (IInventory) chest);
|
|
||||||
if (world.getTypeId(x + 1, y, z) == id)
|
|
||||||
chest = new InventoryLargeChest("Large chest", (IInventory) chest, (TileEntityChest) world.getTileEntity(x + 1, y, z));
|
|
||||||
if (world.getTypeId(x, y, z - 1) == id)
|
|
||||||
chest = new InventoryLargeChest("Large chest", (TileEntityChest) world.getTileEntity(x, y, z - 1), (IInventory) chest);
|
|
||||||
if (world.getTypeId(x, y, z + 1) == id)
|
|
||||||
chest = new InventoryLargeChest("Large chest", (IInventory) chest, (TileEntityChest) world.getTileEntity(x, y, z + 1));
|
|
||||||
|
|
||||||
boolean returnValue = false;
|
|
||||||
if (!silentchest) {
|
|
||||||
player.openContainer((IInventory) chest);
|
|
||||||
returnValue = true;
|
|
||||||
} else {
|
|
||||||
try {
|
|
||||||
int windowId = 0;
|
|
||||||
try {
|
|
||||||
Field windowID = player.getClass().getDeclaredField("containerCounter");
|
|
||||||
windowID.setAccessible(true);
|
|
||||||
windowId = windowID.getInt(player);
|
|
||||||
windowId = windowId % 100 + 1;
|
|
||||||
windowID.setInt(player, windowId);
|
|
||||||
} catch (NoSuchFieldException e) {}
|
|
||||||
|
|
||||||
player.playerConnection.sendPacket(new Packet100OpenWindow(windowId, 0, ((IInventory) chest).getName(), ((IInventory) chest).getSize(), true));
|
|
||||||
player.activeContainer = new SilentContainerChest(player.inventory, ((IInventory) chest));
|
|
||||||
player.activeContainer.windowId = windowId;
|
|
||||||
player.activeContainer.addSlotListener(player);
|
|
||||||
returnValue = true;
|
|
||||||
} catch (Exception e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
p.sendMessage(ChatColor.RED + "Error while sending silent chest.");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return returnValue;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean isAnyContainerNeeded(Player p, int x, int y, int z) {
|
|
||||||
// FOR REFERENCE, LOOK AT net.minecraft.server.BlockChest
|
|
||||||
EntityPlayer player = ((CraftPlayer) p).getHandle();
|
|
||||||
World world = player.world;
|
|
||||||
|
|
||||||
// If block or ocelot on top
|
|
||||||
if (world.t(x, y + 1, z) || hasOcelotOnTop(world, x, y, z))
|
|
||||||
return true;
|
|
||||||
|
|
||||||
int id = world.getTypeId(x, y, z);
|
|
||||||
|
|
||||||
// If block next to chest is chest and has a block or ocelot on top
|
|
||||||
return isBlockedChest(world, id, x - 1, y, z) || isBlockedChest(world, id, x + 1, y, z)
|
|
||||||
|| isBlockedChest(world, id, x, y, z - 1) || isBlockedChest(world, id, x, y, z + 1);
|
|
||||||
}
|
|
||||||
|
|
||||||
private boolean isBlockedChest(World world, int id, int x, int y, int z) {
|
|
||||||
if (world.getTypeId(x, y, z) != id) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (world.t(x, y + 1, z)) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
return hasOcelotOnTop(world, x, y, z);
|
|
||||||
}
|
|
||||||
|
|
||||||
private boolean hasOcelotOnTop(World world, int x, int y, int z) {
|
|
||||||
for (Object localEntity : world.a(EntityOcelot.class,
|
|
||||||
AxisAlignedBB.a().a(x, y + 1, z, x + 1, y + 2, z + 1))) {
|
|
||||||
EntityOcelot localEntityOcelot = (EntityOcelot) localEntity;
|
|
||||||
if (localEntityOcelot.isSitting()) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @deprecated Use {@link #activateContainer(Player, boolean, boolean, int, int, int)}.
|
|
||||||
*/
|
|
||||||
@Deprecated
|
|
||||||
@Override
|
|
||||||
public boolean activateChest(Player player, boolean anychest, boolean silentchest, int x, int y, int z) {
|
|
||||||
return !activateContainer(player, anychest, silentchest, x, y, z);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @deprecated Use {@link #isAnyContainerNeeded(Player, int, int, int)}.
|
|
||||||
*/
|
|
||||||
@Deprecated
|
|
||||||
@Override
|
|
||||||
public boolean isAnyChestNeeded(Player player, int x, int y, int z) {
|
|
||||||
return isAnyContainerNeeded(player, x, y, z);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
@@ -1,50 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright (C) 2011-2014 lishid. All rights reserved.
|
|
||||||
*
|
|
||||||
* This program is free software: you can redistribute it and/or modify
|
|
||||||
* it under the terms of the GNU General Public License as published by
|
|
||||||
* the Free Software Foundation, version 3.
|
|
||||||
*
|
|
||||||
* This program is distributed in the hope that it will be useful,
|
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
* GNU General Public License for more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU General Public License
|
|
||||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package com.lishid.openinv.internal.v1_6_R3;
|
|
||||||
|
|
||||||
import com.lishid.openinv.OpenInv;
|
|
||||||
import com.lishid.openinv.Permissions;
|
|
||||||
import com.lishid.openinv.internal.IInventoryAccess;
|
|
||||||
|
|
||||||
import org.bukkit.entity.HumanEntity;
|
|
||||||
import org.bukkit.inventory.Inventory;
|
|
||||||
|
|
||||||
// Volatile
|
|
||||||
import net.minecraft.server.v1_6_R3.IInventory;
|
|
||||||
|
|
||||||
import org.bukkit.craftbukkit.v1_6_R3.inventory.CraftInventory;
|
|
||||||
|
|
||||||
public class InventoryAccess implements IInventoryAccess {
|
|
||||||
@Override
|
|
||||||
public boolean check(Inventory inventory, HumanEntity player) {
|
|
||||||
IInventory inv = ((CraftInventory) inventory).getInventory();
|
|
||||||
|
|
||||||
if (inv instanceof SpecialPlayerInventory) {
|
|
||||||
if (!OpenInv.hasPermission(player, Permissions.PERM_EDITINV)) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
else if (inv instanceof SpecialEnderChest) {
|
|
||||||
if (!OpenInv.hasPermission(player, Permissions.PERM_EDITENDER)) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
@@ -1,158 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright (C) 2011-2014 lishid. All rights reserved.
|
|
||||||
*
|
|
||||||
* This program is free software: you can redistribute it and/or modify
|
|
||||||
* it under the terms of the GNU General Public License as published by
|
|
||||||
* the Free Software Foundation, version 3.
|
|
||||||
*
|
|
||||||
* This program is distributed in the hope that it will be useful,
|
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
* GNU General Public License for more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU General Public License
|
|
||||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package com.lishid.openinv.internal.v1_7_R1;
|
|
||||||
|
|
||||||
import java.lang.reflect.Field;
|
|
||||||
|
|
||||||
import com.lishid.openinv.internal.IAnySilentContainer;
|
|
||||||
|
|
||||||
import org.bukkit.ChatColor;
|
|
||||||
import org.bukkit.block.BlockState;
|
|
||||||
import org.bukkit.entity.Player;
|
|
||||||
|
|
||||||
//Volatile
|
|
||||||
import net.minecraft.server.v1_7_R1.AxisAlignedBB;
|
|
||||||
import net.minecraft.server.v1_7_R1.Block;
|
|
||||||
import net.minecraft.server.v1_7_R1.EntityOcelot;
|
|
||||||
import net.minecraft.server.v1_7_R1.EntityPlayer;
|
|
||||||
import net.minecraft.server.v1_7_R1.IInventory;
|
|
||||||
import net.minecraft.server.v1_7_R1.InventoryLargeChest;
|
|
||||||
import net.minecraft.server.v1_7_R1.PacketPlayOutOpenWindow;
|
|
||||||
import net.minecraft.server.v1_7_R1.TileEntityChest;
|
|
||||||
import net.minecraft.server.v1_7_R1.World;
|
|
||||||
|
|
||||||
import org.bukkit.craftbukkit.v1_7_R1.entity.CraftPlayer;
|
|
||||||
|
|
||||||
public class AnySilentContainer implements IAnySilentContainer {
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean isAnySilentContainer(BlockState block) {
|
|
||||||
return block instanceof org.bukkit.block.Chest;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean activateContainer(Player p, boolean anychest, boolean silentchest, int x, int y, int z) {
|
|
||||||
EntityPlayer player = ((CraftPlayer) p).getHandle();
|
|
||||||
World world = player.world;
|
|
||||||
Object chest = world.getTileEntity(x, y, z);
|
|
||||||
if (chest == null)
|
|
||||||
return false;
|
|
||||||
|
|
||||||
if (!anychest && isAnyContainerNeeded(p, x, y, z)) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
int id = Block.b(world.getType(x, y, z));
|
|
||||||
|
|
||||||
if (Block.b(world.getType(x - 1, y, z)) == id)
|
|
||||||
chest = new InventoryLargeChest("Large chest", (TileEntityChest) world.getTileEntity(x - 1, y, z), (IInventory) chest);
|
|
||||||
if (Block.b(world.getType(x + 1, y, z)) == id)
|
|
||||||
chest = new InventoryLargeChest("Large chest", (IInventory) chest, (TileEntityChest) world.getTileEntity(x + 1, y, z));
|
|
||||||
if (Block.b(world.getType(x, y, z - 1)) == id)
|
|
||||||
chest = new InventoryLargeChest("Large chest", (TileEntityChest) world.getTileEntity(x, y, z - 1), (IInventory) chest);
|
|
||||||
if (Block.b(world.getType(x, y, z + 1)) == id)
|
|
||||||
chest = new InventoryLargeChest("Large chest", (IInventory) chest, (TileEntityChest) world.getTileEntity(x, y, z + 1));
|
|
||||||
|
|
||||||
boolean returnValue = false;
|
|
||||||
if (!silentchest) {
|
|
||||||
player.openContainer((IInventory) chest);
|
|
||||||
returnValue = true;
|
|
||||||
} else {
|
|
||||||
try {
|
|
||||||
int windowId = 0;
|
|
||||||
try {
|
|
||||||
Field windowID = player.getClass().getDeclaredField("containerCounter");
|
|
||||||
windowID.setAccessible(true);
|
|
||||||
windowId = windowID.getInt(player);
|
|
||||||
windowId = windowId % 100 + 1;
|
|
||||||
windowID.setInt(player, windowId);
|
|
||||||
} catch (NoSuchFieldException e) {}
|
|
||||||
|
|
||||||
player.playerConnection.sendPacket(new PacketPlayOutOpenWindow(windowId, 0, ((IInventory) chest).getInventoryName(), ((IInventory) chest).getSize(), true));
|
|
||||||
player.activeContainer = new SilentContainerChest(player.inventory, ((IInventory) chest));
|
|
||||||
player.activeContainer.windowId = windowId;
|
|
||||||
player.activeContainer.addSlotListener(player);
|
|
||||||
returnValue = true;
|
|
||||||
} catch (Exception e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
p.sendMessage(ChatColor.RED + "Error while sending silent chest.");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return returnValue;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean isAnyContainerNeeded(Player p, int x, int y, int z) {
|
|
||||||
// FOR REFERENCE, LOOK AT net.minecraft.server.BlockChest
|
|
||||||
EntityPlayer player = ((CraftPlayer) p).getHandle();
|
|
||||||
World world = player.world;
|
|
||||||
|
|
||||||
// If block or ocelot on top
|
|
||||||
if (world.t(x, y + 1, z) || hasOcelotOnTop(world, x, y, z))
|
|
||||||
return true;
|
|
||||||
|
|
||||||
int id = Block.b(world.getType(x, y, z));
|
|
||||||
|
|
||||||
// If block next to chest is chest and has a block or ocelot on top
|
|
||||||
return isBlockedChest(world, id, x - 1, y, z) || isBlockedChest(world, id, x + 1, y, z)
|
|
||||||
|| isBlockedChest(world, id, x, y, z - 1) || isBlockedChest(world, id, x, y, z + 1);
|
|
||||||
}
|
|
||||||
|
|
||||||
private boolean isBlockedChest(World world, int id, int x, int y, int z) {
|
|
||||||
if (Block.b(world.getType(x, y, z)) != id) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (world.t(x, y + 1, z)) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
return hasOcelotOnTop(world, x, y, z);
|
|
||||||
}
|
|
||||||
|
|
||||||
private boolean hasOcelotOnTop(World world, int x, int y, int z) {
|
|
||||||
for (Object localEntity : world.a(EntityOcelot.class,
|
|
||||||
AxisAlignedBB.a().a(x, y + 1, z, x + 1, y + 2, z + 1))) {
|
|
||||||
EntityOcelot localEntityOcelot = (EntityOcelot) localEntity;
|
|
||||||
if (localEntityOcelot.isSitting()) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @deprecated Use {@link #activateContainer(Player, boolean, boolean, int, int, int)}.
|
|
||||||
*/
|
|
||||||
@Deprecated
|
|
||||||
@Override
|
|
||||||
public boolean activateChest(Player player, boolean anychest, boolean silentchest, int x, int y, int z) {
|
|
||||||
return !activateContainer(player, anychest, silentchest, x, y, z);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @deprecated Use {@link #isAnyContainerNeeded(Player, int, int, int)}.
|
|
||||||
*/
|
|
||||||
@Deprecated
|
|
||||||
@Override
|
|
||||||
public boolean isAnyChestNeeded(Player player, int x, int y, int z) {
|
|
||||||
return isAnyContainerNeeded(player, x, y, z);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
@@ -1,50 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright (C) 2011-2014 lishid. All rights reserved.
|
|
||||||
*
|
|
||||||
* This program is free software: you can redistribute it and/or modify
|
|
||||||
* it under the terms of the GNU General Public License as published by
|
|
||||||
* the Free Software Foundation, version 3.
|
|
||||||
*
|
|
||||||
* This program is distributed in the hope that it will be useful,
|
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
* GNU General Public License for more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU General Public License
|
|
||||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package com.lishid.openinv.internal.v1_7_R1;
|
|
||||||
|
|
||||||
import com.lishid.openinv.OpenInv;
|
|
||||||
import com.lishid.openinv.Permissions;
|
|
||||||
import com.lishid.openinv.internal.IInventoryAccess;
|
|
||||||
|
|
||||||
import org.bukkit.entity.HumanEntity;
|
|
||||||
import org.bukkit.inventory.Inventory;
|
|
||||||
|
|
||||||
// Volatile
|
|
||||||
import net.minecraft.server.v1_7_R1.IInventory;
|
|
||||||
|
|
||||||
import org.bukkit.craftbukkit.v1_7_R1.inventory.CraftInventory;
|
|
||||||
|
|
||||||
public class InventoryAccess implements IInventoryAccess {
|
|
||||||
@Override
|
|
||||||
public boolean check(Inventory inventory, HumanEntity player) {
|
|
||||||
IInventory inv = ((CraftInventory) inventory).getInventory();
|
|
||||||
|
|
||||||
if (inv instanceof SpecialPlayerInventory) {
|
|
||||||
if (!OpenInv.hasPermission(player, Permissions.PERM_EDITINV)) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
else if (inv instanceof SpecialEnderChest) {
|
|
||||||
if (!OpenInv.hasPermission(player, Permissions.PERM_EDITENDER)) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
@@ -1,158 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright (C) 2011-2014 lishid. All rights reserved.
|
|
||||||
*
|
|
||||||
* This program is free software: you can redistribute it and/or modify
|
|
||||||
* it under the terms of the GNU General Public License as published by
|
|
||||||
* the Free Software Foundation, version 3.
|
|
||||||
*
|
|
||||||
* This program is distributed in the hope that it will be useful,
|
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
* GNU General Public License for more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU General Public License
|
|
||||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package com.lishid.openinv.internal.v1_7_R2;
|
|
||||||
|
|
||||||
import java.lang.reflect.Field;
|
|
||||||
|
|
||||||
import com.lishid.openinv.internal.IAnySilentContainer;
|
|
||||||
|
|
||||||
import org.bukkit.ChatColor;
|
|
||||||
import org.bukkit.block.BlockState;
|
|
||||||
import org.bukkit.entity.Player;
|
|
||||||
|
|
||||||
//Volatile
|
|
||||||
import net.minecraft.server.v1_7_R2.AxisAlignedBB;
|
|
||||||
import net.minecraft.server.v1_7_R2.Block;
|
|
||||||
import net.minecraft.server.v1_7_R2.EntityOcelot;
|
|
||||||
import net.minecraft.server.v1_7_R2.EntityPlayer;
|
|
||||||
import net.minecraft.server.v1_7_R2.IInventory;
|
|
||||||
import net.minecraft.server.v1_7_R2.InventoryLargeChest;
|
|
||||||
import net.minecraft.server.v1_7_R2.PacketPlayOutOpenWindow;
|
|
||||||
import net.minecraft.server.v1_7_R2.TileEntityChest;
|
|
||||||
import net.minecraft.server.v1_7_R2.World;
|
|
||||||
|
|
||||||
import org.bukkit.craftbukkit.v1_7_R2.entity.CraftPlayer;
|
|
||||||
|
|
||||||
public class AnySilentContainer implements IAnySilentContainer {
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean isAnySilentContainer(BlockState block) {
|
|
||||||
return block instanceof org.bukkit.block.Chest;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean activateContainer(Player p, boolean anychest, boolean silentchest, int x, int y, int z) {
|
|
||||||
EntityPlayer player = ((CraftPlayer) p).getHandle();
|
|
||||||
World world = player.world;
|
|
||||||
Object chest = world.getTileEntity(x, y, z);
|
|
||||||
if (chest == null)
|
|
||||||
return false;
|
|
||||||
|
|
||||||
if (!anychest && isAnyContainerNeeded(p, x, y, z)) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
int id = Block.b(world.getType(x, y, z));
|
|
||||||
|
|
||||||
if (Block.b(world.getType(x - 1, y, z)) == id)
|
|
||||||
chest = new InventoryLargeChest("Large chest", (TileEntityChest) world.getTileEntity(x - 1, y, z), (IInventory) chest);
|
|
||||||
if (Block.b(world.getType(x + 1, y, z)) == id)
|
|
||||||
chest = new InventoryLargeChest("Large chest", (IInventory) chest, (TileEntityChest) world.getTileEntity(x + 1, y, z));
|
|
||||||
if (Block.b(world.getType(x, y, z - 1)) == id)
|
|
||||||
chest = new InventoryLargeChest("Large chest", (TileEntityChest) world.getTileEntity(x, y, z - 1), (IInventory) chest);
|
|
||||||
if (Block.b(world.getType(x, y, z + 1)) == id)
|
|
||||||
chest = new InventoryLargeChest("Large chest", (IInventory) chest, (TileEntityChest) world.getTileEntity(x, y, z + 1));
|
|
||||||
|
|
||||||
boolean returnValue = false;
|
|
||||||
if (!silentchest) {
|
|
||||||
player.openContainer((IInventory) chest);
|
|
||||||
returnValue = true;
|
|
||||||
} else {
|
|
||||||
try {
|
|
||||||
int windowId = 0;
|
|
||||||
try {
|
|
||||||
Field windowID = player.getClass().getDeclaredField("containerCounter");
|
|
||||||
windowID.setAccessible(true);
|
|
||||||
windowId = windowID.getInt(player);
|
|
||||||
windowId = windowId % 100 + 1;
|
|
||||||
windowID.setInt(player, windowId);
|
|
||||||
} catch (NoSuchFieldException e) {}
|
|
||||||
|
|
||||||
player.playerConnection.sendPacket(new PacketPlayOutOpenWindow(windowId, 0, ((IInventory) chest).getInventoryName(), ((IInventory) chest).getSize(), true));
|
|
||||||
player.activeContainer = new SilentContainerChest(player.inventory, ((IInventory) chest));
|
|
||||||
player.activeContainer.windowId = windowId;
|
|
||||||
player.activeContainer.addSlotListener(player);
|
|
||||||
returnValue = true;
|
|
||||||
} catch (Exception e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
p.sendMessage(ChatColor.RED + "Error while sending silent chest.");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return returnValue;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean isAnyContainerNeeded(Player p, int x, int y, int z) {
|
|
||||||
// FOR REFERENCE, LOOK AT net.minecraft.server.BlockChest
|
|
||||||
EntityPlayer player = ((CraftPlayer) p).getHandle();
|
|
||||||
World world = player.world;
|
|
||||||
|
|
||||||
// If block or ocelot on top
|
|
||||||
if (world.t(x, y + 1, z) || hasOcelotOnTop(world, x, y, z))
|
|
||||||
return true;
|
|
||||||
|
|
||||||
int id = Block.b(world.getType(x, y, z));
|
|
||||||
|
|
||||||
// If block next to chest is chest and has a block or ocelot on top
|
|
||||||
return isBlockedChest(world, id, x - 1, y, z) || isBlockedChest(world, id, x + 1, y, z)
|
|
||||||
|| isBlockedChest(world, id, x, y, z - 1) || isBlockedChest(world, id, x, y, z + 1);
|
|
||||||
}
|
|
||||||
|
|
||||||
private boolean isBlockedChest(World world, int id, int x, int y, int z) {
|
|
||||||
if (Block.b(world.getType(x, y, z)) != id) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (world.t(x, y + 1, z)) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
return hasOcelotOnTop(world, x, y, z);
|
|
||||||
}
|
|
||||||
|
|
||||||
private boolean hasOcelotOnTop(World world, int x, int y, int z) {
|
|
||||||
for (Object localEntity : world.a(EntityOcelot.class,
|
|
||||||
AxisAlignedBB.a(x, y + 1, z, x + 1, y + 2, z + 1))) {
|
|
||||||
EntityOcelot localEntityOcelot = (EntityOcelot) localEntity;
|
|
||||||
if (localEntityOcelot.isSitting()) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @deprecated Use {@link #activateContainer(Player, boolean, boolean, int, int, int)}.
|
|
||||||
*/
|
|
||||||
@Deprecated
|
|
||||||
@Override
|
|
||||||
public boolean activateChest(Player player, boolean anychest, boolean silentchest, int x, int y, int z) {
|
|
||||||
return !activateContainer(player, anychest, silentchest, x, y, z);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @deprecated Use {@link #isAnyContainerNeeded(Player, int, int, int)}.
|
|
||||||
*/
|
|
||||||
@Deprecated
|
|
||||||
@Override
|
|
||||||
public boolean isAnyChestNeeded(Player player, int x, int y, int z) {
|
|
||||||
return isAnyContainerNeeded(player, x, y, z);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
@@ -1,50 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright (C) 2011-2014 lishid. All rights reserved.
|
|
||||||
*
|
|
||||||
* This program is free software: you can redistribute it and/or modify
|
|
||||||
* it under the terms of the GNU General Public License as published by
|
|
||||||
* the Free Software Foundation, version 3.
|
|
||||||
*
|
|
||||||
* This program is distributed in the hope that it will be useful,
|
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
* GNU General Public License for more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU General Public License
|
|
||||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package com.lishid.openinv.internal.v1_7_R2;
|
|
||||||
|
|
||||||
import com.lishid.openinv.OpenInv;
|
|
||||||
import com.lishid.openinv.Permissions;
|
|
||||||
import com.lishid.openinv.internal.IInventoryAccess;
|
|
||||||
|
|
||||||
import org.bukkit.entity.HumanEntity;
|
|
||||||
import org.bukkit.inventory.Inventory;
|
|
||||||
|
|
||||||
// Volatile
|
|
||||||
import net.minecraft.server.v1_7_R2.IInventory;
|
|
||||||
|
|
||||||
import org.bukkit.craftbukkit.v1_7_R2.inventory.CraftInventory;
|
|
||||||
|
|
||||||
public class InventoryAccess implements IInventoryAccess {
|
|
||||||
@Override
|
|
||||||
public boolean check(Inventory inventory, HumanEntity player) {
|
|
||||||
IInventory inv = ((CraftInventory) inventory).getInventory();
|
|
||||||
|
|
||||||
if (inv instanceof SpecialPlayerInventory) {
|
|
||||||
if (!OpenInv.hasPermission(player, Permissions.PERM_EDITINV)) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
else if (inv instanceof SpecialEnderChest) {
|
|
||||||
if (!OpenInv.hasPermission(player, Permissions.PERM_EDITENDER)) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
@@ -1,158 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright (C) 2011-2014 lishid. All rights reserved.
|
|
||||||
*
|
|
||||||
* This program is free software: you can redistribute it and/or modify
|
|
||||||
* it under the terms of the GNU General Public License as published by
|
|
||||||
* the Free Software Foundation, version 3.
|
|
||||||
*
|
|
||||||
* This program is distributed in the hope that it will be useful,
|
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
* GNU General Public License for more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU General Public License
|
|
||||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package com.lishid.openinv.internal.v1_7_R3;
|
|
||||||
|
|
||||||
import java.lang.reflect.Field;
|
|
||||||
|
|
||||||
import com.lishid.openinv.internal.IAnySilentContainer;
|
|
||||||
|
|
||||||
import org.bukkit.ChatColor;
|
|
||||||
import org.bukkit.block.BlockState;
|
|
||||||
import org.bukkit.entity.Player;
|
|
||||||
|
|
||||||
// Volatile
|
|
||||||
import net.minecraft.server.v1_7_R3.AxisAlignedBB;
|
|
||||||
import net.minecraft.server.v1_7_R3.Block;
|
|
||||||
import net.minecraft.server.v1_7_R3.EntityOcelot;
|
|
||||||
import net.minecraft.server.v1_7_R3.EntityPlayer;
|
|
||||||
import net.minecraft.server.v1_7_R3.IInventory;
|
|
||||||
import net.minecraft.server.v1_7_R3.InventoryLargeChest;
|
|
||||||
import net.minecraft.server.v1_7_R3.PacketPlayOutOpenWindow;
|
|
||||||
import net.minecraft.server.v1_7_R3.TileEntityChest;
|
|
||||||
import net.minecraft.server.v1_7_R3.World;
|
|
||||||
|
|
||||||
import org.bukkit.craftbukkit.v1_7_R3.entity.CraftPlayer;
|
|
||||||
|
|
||||||
public class AnySilentContainer implements IAnySilentContainer {
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean isAnySilentContainer(BlockState block) {
|
|
||||||
return block instanceof org.bukkit.block.Chest;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean activateContainer(Player p, boolean anychest, boolean silentchest, int x, int y, int z) {
|
|
||||||
EntityPlayer player = ((CraftPlayer) p).getHandle();
|
|
||||||
World world = player.world;
|
|
||||||
Object chest = world.getTileEntity(x, y, z);
|
|
||||||
if (chest == null)
|
|
||||||
return false;
|
|
||||||
|
|
||||||
if (!anychest && isAnyContainerNeeded(p, x, y, z)) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
int id = Block.b(world.getType(x, y, z));
|
|
||||||
|
|
||||||
if (Block.b(world.getType(x - 1, y, z)) == id)
|
|
||||||
chest = new InventoryLargeChest("Large chest", (TileEntityChest) world.getTileEntity(x - 1, y, z), (IInventory) chest);
|
|
||||||
if (Block.b(world.getType(x + 1, y, z)) == id)
|
|
||||||
chest = new InventoryLargeChest("Large chest", (IInventory) chest, (TileEntityChest) world.getTileEntity(x + 1, y, z));
|
|
||||||
if (Block.b(world.getType(x, y, z - 1)) == id)
|
|
||||||
chest = new InventoryLargeChest("Large chest", (TileEntityChest) world.getTileEntity(x, y, z - 1), (IInventory) chest);
|
|
||||||
if (Block.b(world.getType(x, y, z + 1)) == id)
|
|
||||||
chest = new InventoryLargeChest("Large chest", (IInventory) chest, (TileEntityChest) world.getTileEntity(x, y, z + 1));
|
|
||||||
|
|
||||||
boolean returnValue = false;
|
|
||||||
if (!silentchest) {
|
|
||||||
player.openContainer((IInventory) chest);
|
|
||||||
returnValue = true;
|
|
||||||
} else {
|
|
||||||
try {
|
|
||||||
int windowId = 0;
|
|
||||||
try {
|
|
||||||
Field windowID = player.getClass().getDeclaredField("containerCounter");
|
|
||||||
windowID.setAccessible(true);
|
|
||||||
windowId = windowID.getInt(player);
|
|
||||||
windowId = windowId % 100 + 1;
|
|
||||||
windowID.setInt(player, windowId);
|
|
||||||
} catch (NoSuchFieldException e) {}
|
|
||||||
|
|
||||||
player.playerConnection.sendPacket(new PacketPlayOutOpenWindow(windowId, 0, ((IInventory) chest).getInventoryName(), ((IInventory) chest).getSize(), true));
|
|
||||||
player.activeContainer = new SilentContainerChest(player.inventory, ((IInventory) chest));
|
|
||||||
player.activeContainer.windowId = windowId;
|
|
||||||
player.activeContainer.addSlotListener(player);
|
|
||||||
returnValue = true;
|
|
||||||
} catch (Exception e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
p.sendMessage(ChatColor.RED + "Error while sending silent chest.");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return returnValue;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean isAnyContainerNeeded(Player p, int x, int y, int z) {
|
|
||||||
// FOR REFERENCE, LOOK AT net.minecraft.server.BlockChest
|
|
||||||
EntityPlayer player = ((CraftPlayer) p).getHandle();
|
|
||||||
World world = player.world;
|
|
||||||
|
|
||||||
// If block or ocelot on top
|
|
||||||
if (world.t(x, y + 1, z) || hasOcelotOnTop(world, x, y, z))
|
|
||||||
return true;
|
|
||||||
|
|
||||||
int id = Block.b(world.getType(x, y, z));
|
|
||||||
|
|
||||||
// If block next to chest is chest and has a block or ocelot on top
|
|
||||||
return isBlockedChest(world, id, x - 1, y, z) || isBlockedChest(world, id, x + 1, y, z)
|
|
||||||
|| isBlockedChest(world, id, x, y, z - 1) || isBlockedChest(world, id, x, y, z + 1);
|
|
||||||
}
|
|
||||||
|
|
||||||
private boolean isBlockedChest(World world, int id, int x, int y, int z) {
|
|
||||||
if (Block.b(world.getType(x, y, z)) != id) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (world.t(x, y + 1, z)) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
return hasOcelotOnTop(world, x, y, z);
|
|
||||||
}
|
|
||||||
|
|
||||||
private boolean hasOcelotOnTop(World world, int x, int y, int z) {
|
|
||||||
for (Object localEntity : world.a(EntityOcelot.class,
|
|
||||||
AxisAlignedBB.a(x, y + 1, z, x + 1, y + 2, z + 1))) {
|
|
||||||
EntityOcelot localEntityOcelot = (EntityOcelot) localEntity;
|
|
||||||
if (localEntityOcelot.isSitting()) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @deprecated Use {@link #activateContainer(Player, boolean, boolean, int, int, int)}.
|
|
||||||
*/
|
|
||||||
@Deprecated
|
|
||||||
@Override
|
|
||||||
public boolean activateChest(Player player, boolean anychest, boolean silentchest, int x, int y, int z) {
|
|
||||||
return !activateContainer(player, anychest, silentchest, x, y, z);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @deprecated Use {@link #isAnyContainerNeeded(Player, int, int, int)}.
|
|
||||||
*/
|
|
||||||
@Deprecated
|
|
||||||
@Override
|
|
||||||
public boolean isAnyChestNeeded(Player player, int x, int y, int z) {
|
|
||||||
return isAnyContainerNeeded(player, x, y, z);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
@@ -1,50 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright (C) 2011-2014 lishid. All rights reserved.
|
|
||||||
*
|
|
||||||
* This program is free software: you can redistribute it and/or modify
|
|
||||||
* it under the terms of the GNU General Public License as published by
|
|
||||||
* the Free Software Foundation, version 3.
|
|
||||||
*
|
|
||||||
* This program is distributed in the hope that it will be useful,
|
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
* GNU General Public License for more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU General Public License
|
|
||||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package com.lishid.openinv.internal.v1_7_R3;
|
|
||||||
|
|
||||||
import com.lishid.openinv.OpenInv;
|
|
||||||
import com.lishid.openinv.Permissions;
|
|
||||||
import com.lishid.openinv.internal.IInventoryAccess;
|
|
||||||
|
|
||||||
import org.bukkit.entity.HumanEntity;
|
|
||||||
import org.bukkit.inventory.Inventory;
|
|
||||||
|
|
||||||
// Volatile
|
|
||||||
import net.minecraft.server.v1_7_R3.IInventory;
|
|
||||||
|
|
||||||
import org.bukkit.craftbukkit.v1_7_R3.inventory.CraftInventory;
|
|
||||||
|
|
||||||
public class InventoryAccess implements IInventoryAccess {
|
|
||||||
@Override
|
|
||||||
public boolean check(Inventory inventory, HumanEntity player) {
|
|
||||||
IInventory inv = ((CraftInventory) inventory).getInventory();
|
|
||||||
|
|
||||||
if (inv instanceof SpecialPlayerInventory) {
|
|
||||||
if (!OpenInv.hasPermission(player, Permissions.PERM_EDITINV)) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
else if (inv instanceof SpecialEnderChest) {
|
|
||||||
if (!OpenInv.hasPermission(player, Permissions.PERM_EDITENDER)) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
@@ -1,158 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright (C) 2011-2014 lishid. All rights reserved.
|
|
||||||
*
|
|
||||||
* This program is free software: you can redistribute it and/or modify
|
|
||||||
* it under the terms of the GNU General Public License as published by
|
|
||||||
* the Free Software Foundation, version 3.
|
|
||||||
*
|
|
||||||
* This program is distributed in the hope that it will be useful,
|
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
* GNU General Public License for more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU General Public License
|
|
||||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package com.lishid.openinv.internal.v1_7_R4;
|
|
||||||
|
|
||||||
import java.lang.reflect.Field;
|
|
||||||
|
|
||||||
import com.lishid.openinv.internal.IAnySilentContainer;
|
|
||||||
|
|
||||||
import org.bukkit.ChatColor;
|
|
||||||
import org.bukkit.block.BlockState;
|
|
||||||
import org.bukkit.entity.Player;
|
|
||||||
|
|
||||||
// Volatile
|
|
||||||
import net.minecraft.server.v1_7_R4.AxisAlignedBB;
|
|
||||||
import net.minecraft.server.v1_7_R4.Block;
|
|
||||||
import net.minecraft.server.v1_7_R4.EntityOcelot;
|
|
||||||
import net.minecraft.server.v1_7_R4.EntityPlayer;
|
|
||||||
import net.minecraft.server.v1_7_R4.IInventory;
|
|
||||||
import net.minecraft.server.v1_7_R4.InventoryLargeChest;
|
|
||||||
import net.minecraft.server.v1_7_R4.PacketPlayOutOpenWindow;
|
|
||||||
import net.minecraft.server.v1_7_R4.TileEntityChest;
|
|
||||||
import net.minecraft.server.v1_7_R4.World;
|
|
||||||
|
|
||||||
import org.bukkit.craftbukkit.v1_7_R4.entity.CraftPlayer;
|
|
||||||
|
|
||||||
public class AnySilentContainer implements IAnySilentContainer {
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean isAnySilentContainer(BlockState block) {
|
|
||||||
return block instanceof org.bukkit.block.Chest;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean activateContainer(Player p, boolean anychest, boolean silentchest, int x, int y, int z) {
|
|
||||||
EntityPlayer player = ((CraftPlayer) p).getHandle();
|
|
||||||
World world = player.world;
|
|
||||||
Object chest = world.getTileEntity(x, y, z);
|
|
||||||
if (chest == null)
|
|
||||||
return false;
|
|
||||||
|
|
||||||
if (!anychest && isAnyContainerNeeded(p, x, y, z)) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
int id = Block.getId(world.getType(x, y, z));
|
|
||||||
|
|
||||||
if (Block.getId(world.getType(x - 1, y, z)) == id)
|
|
||||||
chest = new InventoryLargeChest("Large chest", (TileEntityChest) world.getTileEntity(x - 1, y, z), (IInventory) chest);
|
|
||||||
if (Block.getId(world.getType(x + 1, y, z)) == id)
|
|
||||||
chest = new InventoryLargeChest("Large chest", (IInventory) chest, (TileEntityChest) world.getTileEntity(x + 1, y, z));
|
|
||||||
if (Block.getId(world.getType(x, y, z - 1)) == id)
|
|
||||||
chest = new InventoryLargeChest("Large chest", (TileEntityChest) world.getTileEntity(x, y, z - 1), (IInventory) chest);
|
|
||||||
if (Block.getId(world.getType(x, y, z + 1)) == id)
|
|
||||||
chest = new InventoryLargeChest("Large chest", (IInventory) chest, (TileEntityChest) world.getTileEntity(x, y, z + 1));
|
|
||||||
|
|
||||||
boolean returnValue = false;
|
|
||||||
if (!silentchest) {
|
|
||||||
player.openContainer((IInventory) chest);
|
|
||||||
returnValue = true;
|
|
||||||
} else {
|
|
||||||
try {
|
|
||||||
int windowId = 0;
|
|
||||||
try {
|
|
||||||
Field windowID = player.getClass().getDeclaredField("containerCounter");
|
|
||||||
windowID.setAccessible(true);
|
|
||||||
windowId = windowID.getInt(player);
|
|
||||||
windowId = windowId % 100 + 1;
|
|
||||||
windowID.setInt(player, windowId);
|
|
||||||
} catch (NoSuchFieldException e) {}
|
|
||||||
|
|
||||||
player.playerConnection.sendPacket(new PacketPlayOutOpenWindow(windowId, 0, ((IInventory) chest).getInventoryName(), ((IInventory) chest).getSize(), true));
|
|
||||||
player.activeContainer = new SilentContainerChest(player.inventory, ((IInventory) chest));
|
|
||||||
player.activeContainer.windowId = windowId;
|
|
||||||
player.activeContainer.addSlotListener(player);
|
|
||||||
returnValue = true;
|
|
||||||
} catch (Exception e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
p.sendMessage(ChatColor.RED + "Error while sending silent chest.");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return returnValue;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean isAnyContainerNeeded(Player p, int x, int y, int z) {
|
|
||||||
// FOR REFERENCE, LOOK AT net.minecraft.server.BlockChest
|
|
||||||
EntityPlayer player = ((CraftPlayer) p).getHandle();
|
|
||||||
World world = player.world;
|
|
||||||
|
|
||||||
// If block or ocelot on top
|
|
||||||
if (world.t(x, y + 1, z) || hasOcelotOnTop(world, x, y, z))
|
|
||||||
return true;
|
|
||||||
|
|
||||||
int id = Block.getId(world.getType(x, y, z));
|
|
||||||
|
|
||||||
// If block next to chest is chest and has a block or ocelot on top
|
|
||||||
return isBlockedChest(world, id, x - 1, y, z) || isBlockedChest(world, id, x + 1, y, z)
|
|
||||||
|| isBlockedChest(world, id, x, y, z - 1) || isBlockedChest(world, id, x, y, z + 1);
|
|
||||||
}
|
|
||||||
|
|
||||||
private boolean isBlockedChest(World world, int id, int x, int y, int z) {
|
|
||||||
if (Block.getId(world.getType(x, y, z)) != id) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (world.t(x, y + 1, z)) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
return hasOcelotOnTop(world, x, y, z);
|
|
||||||
}
|
|
||||||
|
|
||||||
private boolean hasOcelotOnTop(World world, int x, int y, int z) {
|
|
||||||
for (Object localEntity : world.a(EntityOcelot.class,
|
|
||||||
AxisAlignedBB.a(x, y + 1, z, x + 1, y + 2, z + 1))) {
|
|
||||||
EntityOcelot localEntityOcelot = (EntityOcelot) localEntity;
|
|
||||||
if (localEntityOcelot.isSitting()) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @deprecated Use {@link #activateContainer(Player, boolean, boolean, int, int, int)}.
|
|
||||||
*/
|
|
||||||
@Deprecated
|
|
||||||
@Override
|
|
||||||
public boolean activateChest(Player player, boolean anychest, boolean silentchest, int x, int y, int z) {
|
|
||||||
return !activateContainer(player, anychest, silentchest, x, y, z);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @deprecated Use {@link #isAnyContainerNeeded(Player, int, int, int)}.
|
|
||||||
*/
|
|
||||||
@Deprecated
|
|
||||||
@Override
|
|
||||||
public boolean isAnyChestNeeded(Player player, int x, int y, int z) {
|
|
||||||
return isAnyContainerNeeded(player, x, y, z);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
@@ -1,73 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright (C) 2011-2014 lishid. All rights reserved.
|
|
||||||
*
|
|
||||||
* This program is free software: you can redistribute it and/or modify
|
|
||||||
* it under the terms of the GNU General Public License as published by
|
|
||||||
* the Free Software Foundation, version 3.
|
|
||||||
*
|
|
||||||
* This program is distributed in the hope that it will be useful,
|
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
* GNU General Public License for more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU General Public License
|
|
||||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package com.lishid.openinv.internal.v1_7_R4;
|
|
||||||
|
|
||||||
import java.lang.reflect.Field;
|
|
||||||
|
|
||||||
import com.lishid.openinv.OpenInv;
|
|
||||||
import com.lishid.openinv.Permissions;
|
|
||||||
import com.lishid.openinv.internal.IInventoryAccess;
|
|
||||||
|
|
||||||
import org.bukkit.entity.HumanEntity;
|
|
||||||
import org.bukkit.inventory.Inventory;
|
|
||||||
|
|
||||||
// Volatile
|
|
||||||
import net.minecraft.server.v1_7_R4.IInventory;
|
|
||||||
|
|
||||||
import org.bukkit.craftbukkit.v1_7_R4.inventory.CraftInventory;
|
|
||||||
|
|
||||||
public class InventoryAccess implements IInventoryAccess {
|
|
||||||
@Override
|
|
||||||
public boolean check(Inventory inventory, HumanEntity player) {
|
|
||||||
IInventory inv = grabInventory(inventory);
|
|
||||||
|
|
||||||
if (inv instanceof SpecialPlayerInventory) {
|
|
||||||
if (!OpenInv.hasPermission(player, Permissions.PERM_EDITINV)) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
else if (inv instanceof SpecialEnderChest) {
|
|
||||||
if (!OpenInv.hasPermission(player, Permissions.PERM_EDITENDER)) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
private IInventory grabInventory(Inventory inventory) {
|
|
||||||
if (inventory instanceof CraftInventory) {
|
|
||||||
return ((CraftInventory) inventory).getInventory();
|
|
||||||
}
|
|
||||||
|
|
||||||
// Use reflection to find the iiventory
|
|
||||||
Class<? extends Inventory> clazz = inventory.getClass();
|
|
||||||
IInventory result = null;
|
|
||||||
for (Field f : clazz.getDeclaredFields()) {
|
|
||||||
f.setAccessible(true);
|
|
||||||
if (IInventory.class.isAssignableFrom(f.getDeclaringClass())) {
|
|
||||||
try {
|
|
||||||
result = (IInventory) f.get(inventory);
|
|
||||||
} catch (Exception e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
}
|
|
@@ -1,151 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright (C) 2011-2014 lishid. All rights reserved.
|
|
||||||
*
|
|
||||||
* This program is free software: you can redistribute it and/or modify
|
|
||||||
* it under the terms of the GNU General Public License as published by
|
|
||||||
* the Free Software Foundation, version 3.
|
|
||||||
*
|
|
||||||
* This program is distributed in the hope that it will be useful,
|
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
* GNU General Public License for more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU General Public License
|
|
||||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package com.lishid.openinv.internal.v1_8_R1;
|
|
||||||
|
|
||||||
import com.lishid.openinv.internal.IAnySilentContainer;
|
|
||||||
|
|
||||||
import org.bukkit.ChatColor;
|
|
||||||
import org.bukkit.block.BlockState;
|
|
||||||
import org.bukkit.entity.Player;
|
|
||||||
|
|
||||||
//Volatile
|
|
||||||
import net.minecraft.server.v1_8_R1.AxisAlignedBB;
|
|
||||||
import net.minecraft.server.v1_8_R1.Block;
|
|
||||||
import net.minecraft.server.v1_8_R1.BlockPosition;
|
|
||||||
import net.minecraft.server.v1_8_R1.EntityOcelot;
|
|
||||||
import net.minecraft.server.v1_8_R1.EntityPlayer;
|
|
||||||
import net.minecraft.server.v1_8_R1.IInventory;
|
|
||||||
import net.minecraft.server.v1_8_R1.ITileInventory;
|
|
||||||
import net.minecraft.server.v1_8_R1.InventoryLargeChest;
|
|
||||||
import net.minecraft.server.v1_8_R1.PacketPlayOutOpenWindow;
|
|
||||||
import net.minecraft.server.v1_8_R1.TileEntityChest;
|
|
||||||
import net.minecraft.server.v1_8_R1.World;
|
|
||||||
|
|
||||||
import org.bukkit.craftbukkit.v1_8_R1.entity.CraftPlayer;
|
|
||||||
|
|
||||||
public class AnySilentContainer implements IAnySilentContainer {
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean isAnySilentContainer(BlockState block) {
|
|
||||||
return block instanceof org.bukkit.block.Chest;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean activateContainer(Player p, boolean anychest, boolean silentchest, int x, int y, int z) {
|
|
||||||
EntityPlayer player = ((CraftPlayer) p).getHandle();
|
|
||||||
World world = player.world;
|
|
||||||
Object chest = world.getTileEntity(new BlockPosition(x, y, z));
|
|
||||||
if (chest == null)
|
|
||||||
return false;
|
|
||||||
|
|
||||||
if (!anychest && isAnyContainerNeeded(p, x, y, z)) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
int id = Block.getId(world.getType(new BlockPosition(x, y, z)).getBlock());
|
|
||||||
|
|
||||||
if (Block.getId(world.getType(new BlockPosition(x - 1, y, z)).getBlock()) == id)
|
|
||||||
chest = new InventoryLargeChest("Large chest", (TileEntityChest) world.getTileEntity(new BlockPosition(x - 1, y, z)), (ITileInventory) chest);
|
|
||||||
if (Block.getId(world.getType(new BlockPosition(x + 1, y, z)).getBlock()) == id)
|
|
||||||
chest = new InventoryLargeChest("Large chest", (ITileInventory) chest, (TileEntityChest) world.getTileEntity(new BlockPosition(x + 1, y, z)));
|
|
||||||
if (Block.getId(world.getType(new BlockPosition(x, y, z - 1)).getBlock()) == id)
|
|
||||||
chest = new InventoryLargeChest("Large chest", (TileEntityChest) world.getTileEntity(new BlockPosition(x, y, z - 1)), (ITileInventory) chest);
|
|
||||||
if (Block.getId(world.getType(new BlockPosition(x, y, z + 1)).getBlock()) == id)
|
|
||||||
chest = new InventoryLargeChest("Large chest", (ITileInventory) chest, (TileEntityChest) world.getTileEntity(new BlockPosition(x, y, z + 1)));
|
|
||||||
|
|
||||||
boolean returnValue = false;
|
|
||||||
if (!silentchest) {
|
|
||||||
player.openContainer((IInventory) chest);
|
|
||||||
returnValue = true;
|
|
||||||
} else {
|
|
||||||
try {
|
|
||||||
SilentContainerChest silentContainerChest = new SilentContainerChest(player.inventory, ((IInventory) chest), player);
|
|
||||||
int windowId = player.nextContainerCounter();
|
|
||||||
player.playerConnection.sendPacket(new PacketPlayOutOpenWindow(windowId, "minecraft:chest", ((IInventory) chest).getScoreboardDisplayName(), ((IInventory) chest).getSize()));
|
|
||||||
player.activeContainer = silentContainerChest;
|
|
||||||
player.activeContainer.windowId = windowId;
|
|
||||||
player.activeContainer.addSlotListener(player);
|
|
||||||
returnValue = true;
|
|
||||||
} catch (Exception e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
p.sendMessage(ChatColor.RED + "Error while sending silent chest.");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return returnValue;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean isAnyContainerNeeded(Player p, int x, int y, int z) {
|
|
||||||
// FOR REFERENCE, LOOK AT net.minecraft.server.BlockChest
|
|
||||||
EntityPlayer player = ((CraftPlayer) p).getHandle();
|
|
||||||
World world = player.world;
|
|
||||||
|
|
||||||
// If block or ocelot on top
|
|
||||||
if (world.getType(new BlockPosition(x, y + 1, z)).getBlock().c() || hasOcelotOnTop(world, x, y, z))
|
|
||||||
return true;
|
|
||||||
|
|
||||||
int id = Block.getId(world.getType(new BlockPosition(x, y, z)).getBlock());
|
|
||||||
|
|
||||||
// If block next to chest is chest and has a block or ocelot on top
|
|
||||||
return isBlockedChest(world, id, x - 1, y, z) || isBlockedChest(world, id, x + 1, y, z)
|
|
||||||
|| isBlockedChest(world, id, x, y, z - 1) || isBlockedChest(world, id, x, y, z + 1);
|
|
||||||
}
|
|
||||||
|
|
||||||
private boolean isBlockedChest(World world, int id, int x, int y, int z) {
|
|
||||||
if (Block.getId(world.getType(new BlockPosition(x, y, z)).getBlock()) != id) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (world.getType(new BlockPosition(x, y + 1, z)).getBlock().c()) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
return hasOcelotOnTop(world, x, y, z);
|
|
||||||
}
|
|
||||||
|
|
||||||
private boolean hasOcelotOnTop(World world, int x, int y, int z) {
|
|
||||||
for (Object localEntity : world.a(EntityOcelot.class,
|
|
||||||
AxisAlignedBB.a(x, y + 1, z, x + 1, y + 2, z + 1))) {
|
|
||||||
EntityOcelot localEntityOcelot = (EntityOcelot) localEntity;
|
|
||||||
if (localEntityOcelot.isSitting()) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @deprecated Use {@link #activateContainer(Player, boolean, boolean, int, int, int)}.
|
|
||||||
*/
|
|
||||||
@Deprecated
|
|
||||||
@Override
|
|
||||||
public boolean activateChest(Player player, boolean anychest, boolean silentchest, int x, int y, int z) {
|
|
||||||
return !activateContainer(player, anychest, silentchest, x, y, z);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @deprecated Use {@link #isAnyContainerNeeded(Player, int, int, int)}.
|
|
||||||
*/
|
|
||||||
@Deprecated
|
|
||||||
@Override
|
|
||||||
public boolean isAnyChestNeeded(Player player, int x, int y, int z) {
|
|
||||||
return isAnyContainerNeeded(player, x, y, z);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
@@ -1,73 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright (C) 2011-2014 lishid. All rights reserved.
|
|
||||||
*
|
|
||||||
* This program is free software: you can redistribute it and/or modify
|
|
||||||
* it under the terms of the GNU General Public License as published by
|
|
||||||
* the Free Software Foundation, version 3.
|
|
||||||
*
|
|
||||||
* This program is distributed in the hope that it will be useful,
|
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
* GNU General Public License for more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU General Public License
|
|
||||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package com.lishid.openinv.internal.v1_8_R1;
|
|
||||||
|
|
||||||
import java.lang.reflect.Field;
|
|
||||||
|
|
||||||
import com.lishid.openinv.OpenInv;
|
|
||||||
import com.lishid.openinv.Permissions;
|
|
||||||
import com.lishid.openinv.internal.IInventoryAccess;
|
|
||||||
|
|
||||||
import org.bukkit.entity.HumanEntity;
|
|
||||||
import org.bukkit.inventory.Inventory;
|
|
||||||
|
|
||||||
// Volatile
|
|
||||||
import net.minecraft.server.v1_8_R1.IInventory;
|
|
||||||
|
|
||||||
import org.bukkit.craftbukkit.v1_8_R1.inventory.CraftInventory;
|
|
||||||
|
|
||||||
public class InventoryAccess implements IInventoryAccess {
|
|
||||||
@Override
|
|
||||||
public boolean check(Inventory inventory, HumanEntity player) {
|
|
||||||
IInventory inv = grabInventory(inventory);
|
|
||||||
|
|
||||||
if (inv instanceof SpecialPlayerInventory) {
|
|
||||||
if (!OpenInv.hasPermission(player, Permissions.PERM_EDITINV)) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
else if (inv instanceof SpecialEnderChest) {
|
|
||||||
if (!OpenInv.hasPermission(player, Permissions.PERM_EDITENDER)) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
private IInventory grabInventory(Inventory inventory) {
|
|
||||||
if (inventory instanceof CraftInventory) {
|
|
||||||
return ((CraftInventory) inventory).getInventory();
|
|
||||||
}
|
|
||||||
|
|
||||||
// Use reflection to find the iiventory
|
|
||||||
Class<? extends Inventory> clazz = inventory.getClass();
|
|
||||||
IInventory result = null;
|
|
||||||
for (Field f : clazz.getDeclaredFields()) {
|
|
||||||
f.setAccessible(true);
|
|
||||||
if (IInventory.class.isAssignableFrom(f.getDeclaringClass())) {
|
|
||||||
try {
|
|
||||||
result = (IInventory) f.get(inventory);
|
|
||||||
} catch (Exception e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
}
|
|
@@ -1,151 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright (C) 2011-2014 lishid. All rights reserved.
|
|
||||||
*
|
|
||||||
* This program is free software: you can redistribute it and/or modify
|
|
||||||
* it under the terms of the GNU General Public License as published by
|
|
||||||
* the Free Software Foundation, version 3.
|
|
||||||
*
|
|
||||||
* This program is distributed in the hope that it will be useful,
|
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
* GNU General Public License for more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU General Public License
|
|
||||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package com.lishid.openinv.internal.v1_8_R2;
|
|
||||||
|
|
||||||
import com.lishid.openinv.internal.IAnySilentContainer;
|
|
||||||
|
|
||||||
import org.bukkit.ChatColor;
|
|
||||||
import org.bukkit.block.BlockState;
|
|
||||||
import org.bukkit.entity.Player;
|
|
||||||
|
|
||||||
//Volatile
|
|
||||||
import net.minecraft.server.v1_8_R2.AxisAlignedBB;
|
|
||||||
import net.minecraft.server.v1_8_R2.Block;
|
|
||||||
import net.minecraft.server.v1_8_R2.BlockPosition;
|
|
||||||
import net.minecraft.server.v1_8_R2.EntityOcelot;
|
|
||||||
import net.minecraft.server.v1_8_R2.EntityPlayer;
|
|
||||||
import net.minecraft.server.v1_8_R2.IInventory;
|
|
||||||
import net.minecraft.server.v1_8_R2.ITileInventory;
|
|
||||||
import net.minecraft.server.v1_8_R2.InventoryLargeChest;
|
|
||||||
import net.minecraft.server.v1_8_R2.PacketPlayOutOpenWindow;
|
|
||||||
import net.minecraft.server.v1_8_R2.TileEntityChest;
|
|
||||||
import net.minecraft.server.v1_8_R2.World;
|
|
||||||
|
|
||||||
import org.bukkit.craftbukkit.v1_8_R2.entity.CraftPlayer;
|
|
||||||
|
|
||||||
public class AnySilentContainer implements IAnySilentContainer {
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean isAnySilentContainer(BlockState block) {
|
|
||||||
return block instanceof org.bukkit.block.Chest;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean activateContainer(Player p, boolean anychest, boolean silentchest, int x, int y, int z) {
|
|
||||||
EntityPlayer player = ((CraftPlayer) p).getHandle();
|
|
||||||
World world = player.world;
|
|
||||||
Object chest = world.getTileEntity(new BlockPosition(x, y, z));
|
|
||||||
if (chest == null)
|
|
||||||
return false;
|
|
||||||
|
|
||||||
if (!anychest && isAnyContainerNeeded(p, x, y, z)) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
int id = Block.getId(world.getType(new BlockPosition(x, y, z)).getBlock());
|
|
||||||
|
|
||||||
if (Block.getId(world.getType(new BlockPosition(x - 1, y, z)).getBlock()) == id)
|
|
||||||
chest = new InventoryLargeChest("Large chest", (TileEntityChest) world.getTileEntity(new BlockPosition(x - 1, y, z)), (ITileInventory) chest);
|
|
||||||
if (Block.getId(world.getType(new BlockPosition(x + 1, y, z)).getBlock()) == id)
|
|
||||||
chest = new InventoryLargeChest("Large chest", (ITileInventory) chest, (TileEntityChest) world.getTileEntity(new BlockPosition(x + 1, y, z)));
|
|
||||||
if (Block.getId(world.getType(new BlockPosition(x, y, z - 1)).getBlock()) == id)
|
|
||||||
chest = new InventoryLargeChest("Large chest", (TileEntityChest) world.getTileEntity(new BlockPosition(x, y, z - 1)), (ITileInventory) chest);
|
|
||||||
if (Block.getId(world.getType(new BlockPosition(x, y, z + 1)).getBlock()) == id)
|
|
||||||
chest = new InventoryLargeChest("Large chest", (ITileInventory) chest, (TileEntityChest) world.getTileEntity(new BlockPosition(x, y, z + 1)));
|
|
||||||
|
|
||||||
boolean returnValue = false;
|
|
||||||
if (!silentchest) {
|
|
||||||
player.openContainer((IInventory) chest);
|
|
||||||
returnValue = true;
|
|
||||||
} else {
|
|
||||||
try {
|
|
||||||
SilentContainerChest silentContainerChest = new SilentContainerChest(player.inventory, ((IInventory) chest), player);
|
|
||||||
int windowId = player.nextContainerCounter();
|
|
||||||
player.playerConnection.sendPacket(new PacketPlayOutOpenWindow(windowId, "minecraft:chest", ((IInventory) chest).getScoreboardDisplayName(), ((IInventory) chest).getSize()));
|
|
||||||
player.activeContainer = silentContainerChest;
|
|
||||||
player.activeContainer.windowId = windowId;
|
|
||||||
player.activeContainer.addSlotListener(player);
|
|
||||||
returnValue = true;
|
|
||||||
} catch (Exception e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
p.sendMessage(ChatColor.RED + "Error while sending silent chest.");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return returnValue;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean isAnyContainerNeeded(Player p, int x, int y, int z) {
|
|
||||||
// FOR REFERENCE, LOOK AT net.minecraft.server.BlockChest
|
|
||||||
EntityPlayer player = ((CraftPlayer) p).getHandle();
|
|
||||||
World world = player.world;
|
|
||||||
|
|
||||||
// If block or ocelot on top
|
|
||||||
if (world.getType(new BlockPosition(x, y + 1, z)).getBlock().c() || hasOcelotOnTop(world, x, y, z))
|
|
||||||
return true;
|
|
||||||
|
|
||||||
int id = Block.getId(world.getType(new BlockPosition(x, y, z)).getBlock());
|
|
||||||
|
|
||||||
// If block next to chest is chest and has a block or ocelot on top
|
|
||||||
return isBlockedChest(world, id, x - 1, y, z) || isBlockedChest(world, id, x + 1, y, z)
|
|
||||||
|| isBlockedChest(world, id, x, y, z - 1) || isBlockedChest(world, id, x, y, z + 1);
|
|
||||||
}
|
|
||||||
|
|
||||||
private boolean isBlockedChest(World world, int id, int x, int y, int z) {
|
|
||||||
if (Block.getId(world.getType(new BlockPosition(x, y, z)).getBlock()) != id) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (world.getType(new BlockPosition(x, y + 1, z)).getBlock().c()) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
return hasOcelotOnTop(world, x, y, z);
|
|
||||||
}
|
|
||||||
|
|
||||||
private boolean hasOcelotOnTop(World world, int x, int y, int z) {
|
|
||||||
for (Object localEntity : world.a(EntityOcelot.class,
|
|
||||||
AxisAlignedBB.a(x, y + 1, z, x + 1, y + 2, z + 1))) {
|
|
||||||
EntityOcelot localEntityOcelot = (EntityOcelot) localEntity;
|
|
||||||
if (localEntityOcelot.isSitting()) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @deprecated Use {@link #activateContainer(Player, boolean, boolean, int, int, int)}.
|
|
||||||
*/
|
|
||||||
@Deprecated
|
|
||||||
@Override
|
|
||||||
public boolean activateChest(Player player, boolean anychest, boolean silentchest, int x, int y, int z) {
|
|
||||||
return !activateContainer(player, anychest, silentchest, x, y, z);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @deprecated Use {@link #isAnyContainerNeeded(Player, int, int, int)}.
|
|
||||||
*/
|
|
||||||
@Deprecated
|
|
||||||
@Override
|
|
||||||
public boolean isAnyChestNeeded(Player player, int x, int y, int z) {
|
|
||||||
return isAnyContainerNeeded(player, x, y, z);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
@@ -1,74 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright (C) 2011-2014 lishid. All rights reserved.
|
|
||||||
*
|
|
||||||
* This program is free software: you can redistribute it and/or modify
|
|
||||||
* it under the terms of the GNU General Public License as published by
|
|
||||||
* the Free Software Foundation, version 3.
|
|
||||||
*
|
|
||||||
* This program is distributed in the hope that it will be useful,
|
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
* GNU General Public License for more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU General Public License
|
|
||||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package com.lishid.openinv.internal.v1_8_R2;
|
|
||||||
|
|
||||||
import java.lang.reflect.Field;
|
|
||||||
|
|
||||||
import com.lishid.openinv.OpenInv;
|
|
||||||
import com.lishid.openinv.Permissions;
|
|
||||||
import com.lishid.openinv.internal.IInventoryAccess;
|
|
||||||
|
|
||||||
import org.bukkit.entity.HumanEntity;
|
|
||||||
import org.bukkit.inventory.Inventory;
|
|
||||||
|
|
||||||
// Volatile
|
|
||||||
import net.minecraft.server.v1_8_R2.IInventory;
|
|
||||||
|
|
||||||
import org.bukkit.craftbukkit.v1_8_R2.inventory.CraftInventory;
|
|
||||||
|
|
||||||
public class InventoryAccess implements IInventoryAccess {
|
|
||||||
@Override
|
|
||||||
public boolean check(Inventory inventory, HumanEntity player) {
|
|
||||||
IInventory inv = grabInventory(inventory);
|
|
||||||
|
|
||||||
if (inv instanceof SpecialPlayerInventory) {
|
|
||||||
if (!OpenInv.hasPermission(player, Permissions.PERM_EDITINV)) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
else if (inv instanceof SpecialEnderChest) {
|
|
||||||
if (!OpenInv.hasPermission(player, Permissions.PERM_EDITENDER)) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
private IInventory grabInventory(Inventory inventory) {
|
|
||||||
if(inventory instanceof CraftInventory) {
|
|
||||||
return ((CraftInventory) inventory).getInventory();
|
|
||||||
}
|
|
||||||
|
|
||||||
//Use reflection to find the iiventory
|
|
||||||
Class<? extends Inventory> clazz = inventory.getClass();
|
|
||||||
IInventory result = null;
|
|
||||||
for(Field f : clazz.getDeclaredFields()) {
|
|
||||||
f.setAccessible(true);
|
|
||||||
if(IInventory.class.isAssignableFrom(f.getDeclaringClass())) {
|
|
||||||
try {
|
|
||||||
result = (IInventory) f.get(inventory);
|
|
||||||
}
|
|
||||||
catch (Exception e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
}
|
|
@@ -1,151 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright (C) 2011-2014 lishid. All rights reserved.
|
|
||||||
*
|
|
||||||
* This program is free software: you can redistribute it and/or modify
|
|
||||||
* it under the terms of the GNU General Public License as published by
|
|
||||||
* the Free Software Foundation, version 3.
|
|
||||||
*
|
|
||||||
* This program is distributed in the hope that it will be useful,
|
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
* GNU General Public License for more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU General Public License
|
|
||||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package com.lishid.openinv.internal.v1_8_R3;
|
|
||||||
|
|
||||||
import com.lishid.openinv.internal.IAnySilentContainer;
|
|
||||||
|
|
||||||
import org.bukkit.ChatColor;
|
|
||||||
import org.bukkit.block.BlockState;
|
|
||||||
import org.bukkit.entity.Player;
|
|
||||||
|
|
||||||
//Volatile
|
|
||||||
import net.minecraft.server.v1_8_R3.AxisAlignedBB;
|
|
||||||
import net.minecraft.server.v1_8_R3.Block;
|
|
||||||
import net.minecraft.server.v1_8_R3.BlockPosition;
|
|
||||||
import net.minecraft.server.v1_8_R3.EntityOcelot;
|
|
||||||
import net.minecraft.server.v1_8_R3.EntityPlayer;
|
|
||||||
import net.minecraft.server.v1_8_R3.IInventory;
|
|
||||||
import net.minecraft.server.v1_8_R3.ITileInventory;
|
|
||||||
import net.minecraft.server.v1_8_R3.InventoryLargeChest;
|
|
||||||
import net.minecraft.server.v1_8_R3.PacketPlayOutOpenWindow;
|
|
||||||
import net.minecraft.server.v1_8_R3.TileEntityChest;
|
|
||||||
import net.minecraft.server.v1_8_R3.World;
|
|
||||||
|
|
||||||
import org.bukkit.craftbukkit.v1_8_R3.entity.CraftPlayer;
|
|
||||||
|
|
||||||
public class AnySilentContainer implements IAnySilentContainer {
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean isAnySilentContainer(BlockState block) {
|
|
||||||
return block instanceof org.bukkit.block.Chest;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean activateContainer(Player p, boolean anychest, boolean silentchest, int x, int y, int z) {
|
|
||||||
EntityPlayer player = ((CraftPlayer) p).getHandle();
|
|
||||||
World world = player.world;
|
|
||||||
Object chest = world.getTileEntity(new BlockPosition(x, y, z));
|
|
||||||
if (chest == null)
|
|
||||||
return false;
|
|
||||||
|
|
||||||
if (!anychest && isAnyContainerNeeded(p, x, y, z)) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
int id = Block.getId(world.getType(new BlockPosition(x, y, z)).getBlock());
|
|
||||||
|
|
||||||
if (Block.getId(world.getType(new BlockPosition(x - 1, y, z)).getBlock()) == id)
|
|
||||||
chest = new InventoryLargeChest("Large chest", (TileEntityChest) world.getTileEntity(new BlockPosition(x - 1, y, z)), (ITileInventory) chest);
|
|
||||||
if (Block.getId(world.getType(new BlockPosition(x + 1, y, z)).getBlock()) == id)
|
|
||||||
chest = new InventoryLargeChest("Large chest", (ITileInventory) chest, (TileEntityChest) world.getTileEntity(new BlockPosition(x + 1, y, z)));
|
|
||||||
if (Block.getId(world.getType(new BlockPosition(x, y, z - 1)).getBlock()) == id)
|
|
||||||
chest = new InventoryLargeChest("Large chest", (TileEntityChest) world.getTileEntity(new BlockPosition(x, y, z - 1)), (ITileInventory) chest);
|
|
||||||
if (Block.getId(world.getType(new BlockPosition(x, y, z + 1)).getBlock()) == id)
|
|
||||||
chest = new InventoryLargeChest("Large chest", (ITileInventory) chest, (TileEntityChest) world.getTileEntity(new BlockPosition(x, y, z + 1)));
|
|
||||||
|
|
||||||
boolean returnValue = false;
|
|
||||||
if (!silentchest) {
|
|
||||||
player.openContainer((IInventory) chest);
|
|
||||||
returnValue = true;
|
|
||||||
} else {
|
|
||||||
try {
|
|
||||||
SilentContainerChest silentContainerChest = new SilentContainerChest(player.inventory, ((IInventory) chest), player);
|
|
||||||
int windowId = player.nextContainerCounter();
|
|
||||||
player.playerConnection.sendPacket(new PacketPlayOutOpenWindow(windowId, "minecraft:chest", ((IInventory) chest).getScoreboardDisplayName(), ((IInventory) chest).getSize()));
|
|
||||||
player.activeContainer = silentContainerChest;
|
|
||||||
player.activeContainer.windowId = windowId;
|
|
||||||
player.activeContainer.addSlotListener(player);
|
|
||||||
returnValue = true;
|
|
||||||
} catch (Exception e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
p.sendMessage(ChatColor.RED + "Error while sending silent chest.");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return returnValue;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean isAnyContainerNeeded(Player p, int x, int y, int z) {
|
|
||||||
// FOR REFERENCE, LOOK AT net.minecraft.server.BlockChest
|
|
||||||
EntityPlayer player = ((CraftPlayer) p).getHandle();
|
|
||||||
World world = player.world;
|
|
||||||
|
|
||||||
// If block or ocelot on top
|
|
||||||
if (world.getType(new BlockPosition(x, y + 1, z)).getBlock().c() || hasOcelotOnTop(world, x, y, z))
|
|
||||||
return true;
|
|
||||||
|
|
||||||
int id = Block.getId(world.getType(new BlockPosition(x, y, z)).getBlock());
|
|
||||||
|
|
||||||
// If block next to chest is chest and has a block or ocelot on top
|
|
||||||
return isBlockedChest(world, id, x - 1, y, z) || isBlockedChest(world, id, x + 1, y, z)
|
|
||||||
|| isBlockedChest(world, id, x, y, z - 1) || isBlockedChest(world, id, x, y, z + 1);
|
|
||||||
}
|
|
||||||
|
|
||||||
private boolean isBlockedChest(World world, int id, int x, int y, int z) {
|
|
||||||
if (Block.getId(world.getType(new BlockPosition(x, y, z)).getBlock()) != id) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (world.getType(new BlockPosition(x, y + 1, z)).getBlock().c()) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
return hasOcelotOnTop(world, x, y, z);
|
|
||||||
}
|
|
||||||
|
|
||||||
private boolean hasOcelotOnTop(World world, int x, int y, int z) {
|
|
||||||
for (Object localEntity : world.a(EntityOcelot.class,
|
|
||||||
AxisAlignedBB.a(x, y + 1, z, x + 1, y + 2, z + 1))) {
|
|
||||||
EntityOcelot localEntityOcelot = (EntityOcelot) localEntity;
|
|
||||||
if (localEntityOcelot.isSitting()) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @deprecated Use {@link #activateContainer(Player, boolean, boolean, int, int, int)}.
|
|
||||||
*/
|
|
||||||
@Deprecated
|
|
||||||
@Override
|
|
||||||
public boolean activateChest(Player player, boolean anychest, boolean silentchest, int x, int y, int z) {
|
|
||||||
return !activateContainer(player, anychest, silentchest, x, y, z);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @deprecated Use {@link #isAnyContainerNeeded(Player, int, int, int)}.
|
|
||||||
*/
|
|
||||||
@Deprecated
|
|
||||||
@Override
|
|
||||||
public boolean isAnyChestNeeded(Player player, int x, int y, int z) {
|
|
||||||
return isAnyContainerNeeded(player, x, y, z);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
@@ -1,74 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright (C) 2011-2014 lishid. All rights reserved.
|
|
||||||
*
|
|
||||||
* This program is free software: you can redistribute it and/or modify
|
|
||||||
* it under the terms of the GNU General Public License as published by
|
|
||||||
* the Free Software Foundation, version 3.
|
|
||||||
*
|
|
||||||
* This program is distributed in the hope that it will be useful,
|
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
* GNU General Public License for more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU General Public License
|
|
||||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package com.lishid.openinv.internal.v1_8_R3;
|
|
||||||
|
|
||||||
import java.lang.reflect.Field;
|
|
||||||
|
|
||||||
import com.lishid.openinv.OpenInv;
|
|
||||||
import com.lishid.openinv.Permissions;
|
|
||||||
import com.lishid.openinv.internal.IInventoryAccess;
|
|
||||||
|
|
||||||
import org.bukkit.entity.HumanEntity;
|
|
||||||
import org.bukkit.inventory.Inventory;
|
|
||||||
|
|
||||||
// Volatile
|
|
||||||
import net.minecraft.server.v1_8_R3.IInventory;
|
|
||||||
|
|
||||||
import org.bukkit.craftbukkit.v1_8_R3.inventory.CraftInventory;
|
|
||||||
|
|
||||||
public class InventoryAccess implements IInventoryAccess {
|
|
||||||
@Override
|
|
||||||
public boolean check(Inventory inventory, HumanEntity player) {
|
|
||||||
IInventory inv = grabInventory(inventory);
|
|
||||||
|
|
||||||
if (inv instanceof SpecialPlayerInventory) {
|
|
||||||
if (!OpenInv.hasPermission(player, Permissions.PERM_EDITINV)) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
else if (inv instanceof SpecialEnderChest) {
|
|
||||||
if (!OpenInv.hasPermission(player, Permissions.PERM_EDITENDER)) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
private IInventory grabInventory(Inventory inventory) {
|
|
||||||
if (inventory instanceof CraftInventory) {
|
|
||||||
return ((CraftInventory) inventory).getInventory();
|
|
||||||
}
|
|
||||||
|
|
||||||
// Use reflection to find the iiventory
|
|
||||||
Class<? extends Inventory> clazz = inventory.getClass();
|
|
||||||
IInventory result = null;
|
|
||||||
for (Field f : clazz.getDeclaredFields()) {
|
|
||||||
f.setAccessible(true);
|
|
||||||
if (IInventory.class.isAssignableFrom(f.getDeclaringClass())) {
|
|
||||||
try {
|
|
||||||
result = (IInventory) f.get(inventory);
|
|
||||||
} catch (Exception e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
}
|
|
@@ -1,153 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright (C) 2011-2014 lishid. All rights reserved.
|
|
||||||
*
|
|
||||||
* This program is free software: you can redistribute it and/or modify
|
|
||||||
* it under the terms of the GNU General Public License as published by
|
|
||||||
* the Free Software Foundation, version 3.
|
|
||||||
*
|
|
||||||
* This program is distributed in the hope that it will be useful,
|
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
* GNU General Public License for more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU General Public License
|
|
||||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package com.lishid.openinv.internal.v1_9_R1;
|
|
||||||
|
|
||||||
import com.lishid.openinv.internal.IAnySilentContainer;
|
|
||||||
|
|
||||||
import org.bukkit.ChatColor;
|
|
||||||
import org.bukkit.block.BlockState;
|
|
||||||
import org.bukkit.entity.Player;
|
|
||||||
|
|
||||||
// Volatile
|
|
||||||
import net.minecraft.server.v1_9_R1.AxisAlignedBB;
|
|
||||||
import net.minecraft.server.v1_9_R1.Block;
|
|
||||||
import net.minecraft.server.v1_9_R1.BlockPosition;
|
|
||||||
import net.minecraft.server.v1_9_R1.Entity;
|
|
||||||
import net.minecraft.server.v1_9_R1.EntityOcelot;
|
|
||||||
import net.minecraft.server.v1_9_R1.EntityPlayer;
|
|
||||||
import net.minecraft.server.v1_9_R1.IInventory;
|
|
||||||
import net.minecraft.server.v1_9_R1.ITileInventory;
|
|
||||||
import net.minecraft.server.v1_9_R1.InventoryLargeChest;
|
|
||||||
import net.minecraft.server.v1_9_R1.PacketPlayOutOpenWindow;
|
|
||||||
import net.minecraft.server.v1_9_R1.TileEntityChest;
|
|
||||||
import net.minecraft.server.v1_9_R1.World;
|
|
||||||
|
|
||||||
import org.bukkit.craftbukkit.v1_9_R1.entity.CraftPlayer;
|
|
||||||
|
|
||||||
public class AnySilentContainer implements IAnySilentContainer {
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean isAnySilentContainer(BlockState block) {
|
|
||||||
return block instanceof org.bukkit.block.Chest;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean activateContainer(Player p, boolean anychest, boolean silentchest, int x, int y, int z) {
|
|
||||||
EntityPlayer player = ((CraftPlayer) p).getHandle();
|
|
||||||
World world = player.world;
|
|
||||||
Object chest = world.getTileEntity(new BlockPosition(x, y, z));
|
|
||||||
if (chest == null)
|
|
||||||
return false;
|
|
||||||
|
|
||||||
if (!anychest && isAnyContainerNeeded(p, x, y, z)) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
int id = Block.getId(world.getType(new BlockPosition(x, y, z)).getBlock());
|
|
||||||
|
|
||||||
if (Block.getId(world.getType(new BlockPosition(x - 1, y, z)).getBlock()) == id)
|
|
||||||
chest = new InventoryLargeChest("Large chest", (TileEntityChest) world.getTileEntity(new BlockPosition(x - 1, y, z)), (ITileInventory) chest);
|
|
||||||
if (Block.getId(world.getType(new BlockPosition(x + 1, y, z)).getBlock()) == id)
|
|
||||||
chest = new InventoryLargeChest("Large chest", (ITileInventory) chest, (TileEntityChest) world.getTileEntity(new BlockPosition(x + 1, y, z)));
|
|
||||||
if (Block.getId(world.getType(new BlockPosition(x, y, z - 1)).getBlock()) == id)
|
|
||||||
chest = new InventoryLargeChest("Large chest", (TileEntityChest) world.getTileEntity(new BlockPosition(x, y, z - 1)), (ITileInventory) chest);
|
|
||||||
if (Block.getId(world.getType(new BlockPosition(x, y, z + 1)).getBlock()) == id)
|
|
||||||
chest = new InventoryLargeChest("Large chest", (ITileInventory) chest, (TileEntityChest) world.getTileEntity(new BlockPosition(x, y, z + 1)));
|
|
||||||
|
|
||||||
boolean returnValue = false;
|
|
||||||
if (!silentchest) {
|
|
||||||
player.openContainer((IInventory) chest);
|
|
||||||
returnValue = true;
|
|
||||||
} else {
|
|
||||||
try {
|
|
||||||
SilentContainerChest silentContainerChest = new SilentContainerChest(player.inventory, ((IInventory) chest), player);
|
|
||||||
int windowId = player.nextContainerCounter();
|
|
||||||
player.playerConnection.sendPacket(new PacketPlayOutOpenWindow(windowId, "minecraft:chest", ((IInventory) chest).getScoreboardDisplayName(), ((IInventory) chest).getSize()));
|
|
||||||
player.activeContainer = silentContainerChest;
|
|
||||||
player.activeContainer.windowId = windowId;
|
|
||||||
player.activeContainer.addSlotListener(player);
|
|
||||||
returnValue = true;
|
|
||||||
} catch (Exception e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
p.sendMessage(ChatColor.RED + "Error while sending silent chest.");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return returnValue;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean isAnyContainerNeeded(Player p, int x, int y, int z) {
|
|
||||||
// FOR REFERENCE, LOOK AT net.minecraft.server.BlockChest
|
|
||||||
EntityPlayer player = ((CraftPlayer) p).getHandle();
|
|
||||||
World world = player.world;
|
|
||||||
|
|
||||||
// If block or ocelot on top
|
|
||||||
if (world.getType(new BlockPosition(x, y + 1, z)).l() || hasOcelotOnTop(world, x, y, z))
|
|
||||||
return true;
|
|
||||||
|
|
||||||
int id = Block.getId(world.getType(new BlockPosition(x, y, z)).getBlock());
|
|
||||||
|
|
||||||
// If block next to chest is chest and has a block or ocelot on top
|
|
||||||
return isBlockedChest(world, id, x - 1, y, z) || isBlockedChest(world, id, x + 1, y, z)
|
|
||||||
|| isBlockedChest(world, id, x, y, z - 1) || isBlockedChest(world, id, x, y, z + 1);
|
|
||||||
}
|
|
||||||
|
|
||||||
private boolean isBlockedChest(World world, int id, int x, int y, int z) {
|
|
||||||
BlockPosition position = new BlockPosition(x, y, z);
|
|
||||||
if (Block.getId(world.getType(position).getBlock()) != id) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (world.getType(position).l()) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
return hasOcelotOnTop(world, x, y, z);
|
|
||||||
}
|
|
||||||
|
|
||||||
private boolean hasOcelotOnTop(World world, int x, int y, int z) {
|
|
||||||
for (Entity localEntity : world.a(EntityOcelot.class,
|
|
||||||
new AxisAlignedBB(x, y + 1, z, x + 1, y + 2, z + 1))) {
|
|
||||||
EntityOcelot localEntityOcelot = (EntityOcelot) localEntity;
|
|
||||||
if (localEntityOcelot.isSitting()) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @deprecated Use {@link #activateContainer(Player, boolean, boolean, int, int, int)}.
|
|
||||||
*/
|
|
||||||
@Deprecated
|
|
||||||
@Override
|
|
||||||
public boolean activateChest(Player player, boolean anychest, boolean silentchest, int x, int y, int z) {
|
|
||||||
return !activateContainer(player, anychest, silentchest, x, y, z);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @deprecated Use {@link #isAnyContainerNeeded(Player, int, int, int)}.
|
|
||||||
*/
|
|
||||||
@Deprecated
|
|
||||||
@Override
|
|
||||||
public boolean isAnyChestNeeded(Player player, int x, int y, int z) {
|
|
||||||
return isAnyContainerNeeded(player, x, y, z);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
@@ -1,74 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright (C) 2011-2014 lishid. All rights reserved.
|
|
||||||
*
|
|
||||||
* This program is free software: you can redistribute it and/or modify
|
|
||||||
* it under the terms of the GNU General Public License as published by
|
|
||||||
* the Free Software Foundation, version 3.
|
|
||||||
*
|
|
||||||
* This program is distributed in the hope that it will be useful,
|
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
* GNU General Public License for more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU General Public License
|
|
||||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package com.lishid.openinv.internal.v1_9_R1;
|
|
||||||
|
|
||||||
import java.lang.reflect.Field;
|
|
||||||
|
|
||||||
import com.lishid.openinv.OpenInv;
|
|
||||||
import com.lishid.openinv.Permissions;
|
|
||||||
import com.lishid.openinv.internal.IInventoryAccess;
|
|
||||||
|
|
||||||
import org.bukkit.entity.HumanEntity;
|
|
||||||
import org.bukkit.inventory.Inventory;
|
|
||||||
|
|
||||||
// Volatile
|
|
||||||
import net.minecraft.server.v1_9_R1.IInventory;
|
|
||||||
|
|
||||||
import org.bukkit.craftbukkit.v1_9_R1.inventory.CraftInventory;
|
|
||||||
|
|
||||||
public class InventoryAccess implements IInventoryAccess {
|
|
||||||
@Override
|
|
||||||
public boolean check(Inventory inventory, HumanEntity player) {
|
|
||||||
IInventory inv = grabInventory(inventory);
|
|
||||||
|
|
||||||
if (inv instanceof SpecialPlayerInventory) {
|
|
||||||
if (!OpenInv.hasPermission(player, Permissions.PERM_EDITINV)) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
else if (inv instanceof SpecialEnderChest) {
|
|
||||||
if (!OpenInv.hasPermission(player, Permissions.PERM_EDITENDER)) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
private IInventory grabInventory(Inventory inventory) {
|
|
||||||
if(inventory instanceof CraftInventory) {
|
|
||||||
return ((CraftInventory) inventory).getInventory();
|
|
||||||
}
|
|
||||||
|
|
||||||
//Use reflection to find the iiventory
|
|
||||||
Class<? extends Inventory> clazz = inventory.getClass();
|
|
||||||
IInventory result = null;
|
|
||||||
for(Field f : clazz.getDeclaredFields()) {
|
|
||||||
f.setAccessible(true);
|
|
||||||
if(IInventory.class.isAssignableFrom(f.getDeclaringClass())) {
|
|
||||||
try {
|
|
||||||
result = (IInventory) f.get(inventory);
|
|
||||||
}
|
|
||||||
catch (Exception e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
}
|
|
@@ -1,153 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright (C) 2011-2014 lishid. All rights reserved.
|
|
||||||
*
|
|
||||||
* This program is free software: you can redistribute it and/or modify
|
|
||||||
* it under the terms of the GNU General Public License as published by
|
|
||||||
* the Free Software Foundation, version 3.
|
|
||||||
*
|
|
||||||
* This program is distributed in the hope that it will be useful,
|
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
* GNU General Public License for more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU General Public License
|
|
||||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package com.lishid.openinv.internal.v1_9_R2;
|
|
||||||
|
|
||||||
import com.lishid.openinv.internal.IAnySilentContainer;
|
|
||||||
|
|
||||||
import org.bukkit.ChatColor;
|
|
||||||
import org.bukkit.block.BlockState;
|
|
||||||
import org.bukkit.entity.Player;
|
|
||||||
|
|
||||||
// Volatile
|
|
||||||
import net.minecraft.server.v1_9_R2.AxisAlignedBB;
|
|
||||||
import net.minecraft.server.v1_9_R2.Block;
|
|
||||||
import net.minecraft.server.v1_9_R2.BlockPosition;
|
|
||||||
import net.minecraft.server.v1_9_R2.Entity;
|
|
||||||
import net.minecraft.server.v1_9_R2.EntityOcelot;
|
|
||||||
import net.minecraft.server.v1_9_R2.EntityPlayer;
|
|
||||||
import net.minecraft.server.v1_9_R2.IInventory;
|
|
||||||
import net.minecraft.server.v1_9_R2.ITileInventory;
|
|
||||||
import net.minecraft.server.v1_9_R2.InventoryLargeChest;
|
|
||||||
import net.minecraft.server.v1_9_R2.PacketPlayOutOpenWindow;
|
|
||||||
import net.minecraft.server.v1_9_R2.TileEntityChest;
|
|
||||||
import net.minecraft.server.v1_9_R2.World;
|
|
||||||
|
|
||||||
import org.bukkit.craftbukkit.v1_9_R2.entity.CraftPlayer;
|
|
||||||
|
|
||||||
public class AnySilentContainer implements IAnySilentContainer {
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean isAnySilentContainer(BlockState block) {
|
|
||||||
return block instanceof org.bukkit.block.Chest;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean activateContainer(Player p, boolean anychest, boolean silentchest, int x, int y, int z) {
|
|
||||||
EntityPlayer player = ((CraftPlayer) p).getHandle();
|
|
||||||
World world = player.world;
|
|
||||||
Object chest = world.getTileEntity(new BlockPosition(x, y, z));
|
|
||||||
if (chest == null)
|
|
||||||
return false;
|
|
||||||
|
|
||||||
if (!anychest && isAnyContainerNeeded(p, x, y, z)) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
int id = Block.getId(world.getType(new BlockPosition(x, y, z)).getBlock());
|
|
||||||
|
|
||||||
if (Block.getId(world.getType(new BlockPosition(x - 1, y, z)).getBlock()) == id)
|
|
||||||
chest = new InventoryLargeChest("Large chest", (TileEntityChest) world.getTileEntity(new BlockPosition(x - 1, y, z)), (ITileInventory) chest);
|
|
||||||
if (Block.getId(world.getType(new BlockPosition(x + 1, y, z)).getBlock()) == id)
|
|
||||||
chest = new InventoryLargeChest("Large chest", (ITileInventory) chest, (TileEntityChest) world.getTileEntity(new BlockPosition(x + 1, y, z)));
|
|
||||||
if (Block.getId(world.getType(new BlockPosition(x, y, z - 1)).getBlock()) == id)
|
|
||||||
chest = new InventoryLargeChest("Large chest", (TileEntityChest) world.getTileEntity(new BlockPosition(x, y, z - 1)), (ITileInventory) chest);
|
|
||||||
if (Block.getId(world.getType(new BlockPosition(x, y, z + 1)).getBlock()) == id)
|
|
||||||
chest = new InventoryLargeChest("Large chest", (ITileInventory) chest, (TileEntityChest) world.getTileEntity(new BlockPosition(x, y, z + 1)));
|
|
||||||
|
|
||||||
boolean returnValue = false;
|
|
||||||
if (!silentchest) {
|
|
||||||
player.openContainer((IInventory) chest);
|
|
||||||
returnValue = true;
|
|
||||||
} else {
|
|
||||||
try {
|
|
||||||
SilentContainerChest silentContainerChest = new SilentContainerChest(player.inventory, ((IInventory) chest), player);
|
|
||||||
int windowId = player.nextContainerCounter();
|
|
||||||
player.playerConnection.sendPacket(new PacketPlayOutOpenWindow(windowId, "minecraft:chest", ((IInventory) chest).getScoreboardDisplayName(), ((IInventory) chest).getSize()));
|
|
||||||
player.activeContainer = silentContainerChest;
|
|
||||||
player.activeContainer.windowId = windowId;
|
|
||||||
player.activeContainer.addSlotListener(player);
|
|
||||||
returnValue = true;
|
|
||||||
} catch (Exception e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
p.sendMessage(ChatColor.RED + "Error while sending silent chest.");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return returnValue;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean isAnyContainerNeeded(Player p, int x, int y, int z) {
|
|
||||||
// FOR REFERENCE, LOOK AT net.minecraft.server.BlockChest
|
|
||||||
EntityPlayer player = ((CraftPlayer) p).getHandle();
|
|
||||||
World world = player.world;
|
|
||||||
|
|
||||||
// If block or ocelot on top
|
|
||||||
if (world.getType(new BlockPosition(x, y + 1, z)).l() || hasOcelotOnTop(world, x, y, z))
|
|
||||||
return true;
|
|
||||||
|
|
||||||
int id = Block.getId(world.getType(new BlockPosition(x, y, z)).getBlock());
|
|
||||||
|
|
||||||
// If block next to chest is chest and has a block or ocelot on top
|
|
||||||
return isBlockedChest(world, id, x - 1, y, z) || isBlockedChest(world, id, x + 1, y, z)
|
|
||||||
|| isBlockedChest(world, id, x, y, z - 1) || isBlockedChest(world, id, x, y, z + 1);
|
|
||||||
}
|
|
||||||
|
|
||||||
private boolean isBlockedChest(World world, int id, int x, int y, int z) {
|
|
||||||
BlockPosition position = new BlockPosition(x, y, z);
|
|
||||||
if (Block.getId(world.getType(position).getBlock()) != id) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (world.getType(position).l()) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
return hasOcelotOnTop(world, x, y, z);
|
|
||||||
}
|
|
||||||
|
|
||||||
private boolean hasOcelotOnTop(World world, int x, int y, int z) {
|
|
||||||
for (Entity localEntity : world.a(EntityOcelot.class,
|
|
||||||
new AxisAlignedBB(x, y + 1, z, x + 1, y + 2, z + 1))) {
|
|
||||||
EntityOcelot localEntityOcelot = (EntityOcelot) localEntity;
|
|
||||||
if (localEntityOcelot.isSitting()) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @deprecated Use {@link #activateContainer(Player, boolean, boolean, int, int, int)}.
|
|
||||||
*/
|
|
||||||
@Deprecated
|
|
||||||
@Override
|
|
||||||
public boolean activateChest(Player player, boolean anychest, boolean silentchest, int x, int y, int z) {
|
|
||||||
return !activateContainer(player, anychest, silentchest, x, y, z);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @deprecated Use {@link #isAnyContainerNeeded(Player, int, int, int)}.
|
|
||||||
*/
|
|
||||||
@Deprecated
|
|
||||||
@Override
|
|
||||||
public boolean isAnyChestNeeded(Player player, int x, int y, int z) {
|
|
||||||
return isAnyContainerNeeded(player, x, y, z);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
@@ -1,74 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright (C) 2011-2014 lishid. All rights reserved.
|
|
||||||
*
|
|
||||||
* This program is free software: you can redistribute it and/or modify
|
|
||||||
* it under the terms of the GNU General Public License as published by
|
|
||||||
* the Free Software Foundation, version 3.
|
|
||||||
*
|
|
||||||
* This program is distributed in the hope that it will be useful,
|
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
* GNU General Public License for more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU General Public License
|
|
||||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package com.lishid.openinv.internal.v1_9_R2;
|
|
||||||
|
|
||||||
import java.lang.reflect.Field;
|
|
||||||
|
|
||||||
import com.lishid.openinv.OpenInv;
|
|
||||||
import com.lishid.openinv.Permissions;
|
|
||||||
import com.lishid.openinv.internal.IInventoryAccess;
|
|
||||||
|
|
||||||
import org.bukkit.entity.HumanEntity;
|
|
||||||
import org.bukkit.inventory.Inventory;
|
|
||||||
|
|
||||||
// Volatile
|
|
||||||
import net.minecraft.server.v1_9_R2.IInventory;
|
|
||||||
|
|
||||||
import org.bukkit.craftbukkit.v1_9_R2.inventory.CraftInventory;
|
|
||||||
|
|
||||||
public class InventoryAccess implements IInventoryAccess {
|
|
||||||
@Override
|
|
||||||
public boolean check(Inventory inventory, HumanEntity player) {
|
|
||||||
IInventory inv = grabInventory(inventory);
|
|
||||||
|
|
||||||
if (inv instanceof SpecialPlayerInventory) {
|
|
||||||
if (!OpenInv.hasPermission(player, Permissions.PERM_EDITINV)) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
else if (inv instanceof SpecialEnderChest) {
|
|
||||||
if (!OpenInv.hasPermission(player, Permissions.PERM_EDITENDER)) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
private IInventory grabInventory(Inventory inventory) {
|
|
||||||
if(inventory instanceof CraftInventory) {
|
|
||||||
return ((CraftInventory) inventory).getInventory();
|
|
||||||
}
|
|
||||||
|
|
||||||
//Use reflection to find the iinventory
|
|
||||||
Class<? extends Inventory> clazz = inventory.getClass();
|
|
||||||
IInventory result = null;
|
|
||||||
for(Field f : clazz.getDeclaredFields()) {
|
|
||||||
f.setAccessible(true);
|
|
||||||
if(IInventory.class.isAssignableFrom(f.getDeclaringClass())) {
|
|
||||||
try {
|
|
||||||
result = (IInventory) f.get(inventory);
|
|
||||||
}
|
|
||||||
catch (Exception e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
}
|
|
@@ -1,92 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright (C) 2011-2014 lishid. All rights reserved.
|
|
||||||
*
|
|
||||||
* This program is free software: you can redistribute it and/or modify
|
|
||||||
* it under the terms of the GNU General Public License as published by
|
|
||||||
* the Free Software Foundation, version 3.
|
|
||||||
*
|
|
||||||
* This program is distributed in the hope that it will be useful,
|
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
* GNU General Public License for more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU General Public License
|
|
||||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package com.lishid.openinv;
|
|
||||||
|
|
||||||
import org.bukkit.entity.Player;
|
|
||||||
import org.bukkit.event.Event.Result;
|
|
||||||
import org.bukkit.event.EventHandler;
|
|
||||||
import org.bukkit.event.EventPriority;
|
|
||||||
import org.bukkit.event.Listener;
|
|
||||||
import org.bukkit.event.block.Action;
|
|
||||||
import org.bukkit.event.player.PlayerInteractEvent;
|
|
||||||
import org.bukkit.event.player.PlayerJoinEvent;
|
|
||||||
import org.bukkit.event.player.PlayerQuitEvent;
|
|
||||||
|
|
||||||
public class OpenInvPlayerListener implements Listener {
|
|
||||||
|
|
||||||
private final OpenInv plugin;
|
|
||||||
|
|
||||||
public OpenInvPlayerListener(OpenInv plugin) {
|
|
||||||
this.plugin = plugin;
|
|
||||||
}
|
|
||||||
|
|
||||||
@EventHandler(priority = EventPriority.MONITOR)
|
|
||||||
public void onPlayerJoin(final PlayerJoinEvent event) {
|
|
||||||
plugin.setPlayerOnline(event.getPlayer());
|
|
||||||
}
|
|
||||||
|
|
||||||
@EventHandler(priority = EventPriority.MONITOR)
|
|
||||||
public void onPlayerQuit(PlayerQuitEvent event) {
|
|
||||||
plugin.setPlayerOffline(event.getPlayer());
|
|
||||||
}
|
|
||||||
|
|
||||||
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
|
|
||||||
public void onPlayerInteract(PlayerInteractEvent event) {
|
|
||||||
if (event.getAction() != Action.RIGHT_CLICK_BLOCK || event.getPlayer().isSneaking()
|
|
||||||
|| event.useInteractedBlock() == Result.DENY) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
Player player = event.getPlayer();
|
|
||||||
|
|
||||||
if (event.getClickedBlock().getType() == org.bukkit.Material.ENDER_CHEST) {
|
|
||||||
if (OpenInv.hasPermission(player, Permissions.PERM_SILENT)
|
|
||||||
&& plugin.getPlayerSilentChestStatus(player)) {
|
|
||||||
// TODO: Bypasses blocks on top, anychest also does not work
|
|
||||||
event.setCancelled(true);
|
|
||||||
player.openInventory(player.getEnderChest());
|
|
||||||
}
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (plugin.getAnySilentContainer().isAnySilentContainer(event.getClickedBlock().getState())) {
|
|
||||||
|
|
||||||
boolean silentchest = OpenInv.hasPermission(player, Permissions.PERM_SILENT) && plugin.getPlayerSilentChestStatus(player);
|
|
||||||
boolean anychest = OpenInv.hasPermission(player, Permissions.PERM_ANYCHEST) && plugin.getPlayerAnyChestStatus(player);
|
|
||||||
|
|
||||||
int x = event.getClickedBlock().getX();
|
|
||||||
int y = event.getClickedBlock().getY();
|
|
||||||
int z = event.getClickedBlock().getZ();
|
|
||||||
|
|
||||||
// If anychest or silentchest is active
|
|
||||||
if (anychest || silentchest) {
|
|
||||||
if (plugin.getAnySilentContainer().activateContainer(player, anychest, silentchest, x, y, z)) {
|
|
||||||
if (silentchest && plugin.notifySilentChest() && anychest && plugin.notifyAnyChest()) {
|
|
||||||
player.sendMessage("You are opening a blocked chest silently.");
|
|
||||||
} else if (silentchest && plugin.notifySilentChest()) {
|
|
||||||
player.sendMessage("You are opening a chest silently.");
|
|
||||||
} else if (anychest && plugin.notifyAnyChest()) {
|
|
||||||
// TODO fix anychest always claiming chest is blocked
|
|
||||||
player.sendMessage("You are opening a blocked chest.");
|
|
||||||
}
|
|
||||||
event.setCancelled(true);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
@@ -1,16 +0,0 @@
|
|||||||
package com.lishid.openinv;
|
|
||||||
|
|
||||||
public class Permissions {
|
|
||||||
public static final String PERM_OPENINV = "OpenInv.openinv";
|
|
||||||
public static final String PERM_OVERRIDE = "OpenInv.override";
|
|
||||||
public static final String PERM_EXEMPT = "OpenInv.exempt";
|
|
||||||
public static final String PERM_CROSSWORLD = "OpenInv.crossworld";
|
|
||||||
public static final String PERM_SILENT = "OpenInv.silent";
|
|
||||||
public static final String PERM_ANYCHEST = "OpenInv.anychest";
|
|
||||||
public static final String PERM_ENDERCHEST = "OpenInv.openender";
|
|
||||||
public static final String PERM_ENDERCHEST_ALL = "OpenInv.openenderall";
|
|
||||||
public static final String PERM_SEARCH = "OpenInv.search";
|
|
||||||
public static final String PERM_EDITINV = "OpenInv.editinv";
|
|
||||||
public static final String PERM_EDITENDER = "OpenInv.editender";
|
|
||||||
public static final String PERM_OPENSELF = "OpenInv.openself";
|
|
||||||
}
|
|
@@ -1,130 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright (C) 2011-2014 lishid. All rights reserved.
|
|
||||||
*
|
|
||||||
* This program is free software: you can redistribute it and/or modify
|
|
||||||
* it under the terms of the GNU General Public License as published by
|
|
||||||
* the Free Software Foundation, version 3.
|
|
||||||
*
|
|
||||||
* This program is distributed in the hope that it will be useful,
|
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
* GNU General Public License for more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU General Public License
|
|
||||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package com.lishid.openinv.internal;
|
|
||||||
|
|
||||||
import com.lishid.openinv.OpenInv;
|
|
||||||
|
|
||||||
import org.bukkit.Server;
|
|
||||||
import org.bukkit.entity.Player;
|
|
||||||
|
|
||||||
public class InternalAccessor {
|
|
||||||
|
|
||||||
private final OpenInv plugin;
|
|
||||||
|
|
||||||
private String version;
|
|
||||||
|
|
||||||
public InternalAccessor(OpenInv plugin) {
|
|
||||||
this.plugin = plugin;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Check if the current server version is supported, and, if it is, prepare to load version-specific code.
|
|
||||||
*
|
|
||||||
* @param server the Server
|
|
||||||
*
|
|
||||||
* @return true if supported
|
|
||||||
*/
|
|
||||||
public boolean initialize(Server server) {
|
|
||||||
String packageName = server.getClass().getPackage().getName();
|
|
||||||
version = packageName.substring(packageName.lastIndexOf('.') + 1);
|
|
||||||
|
|
||||||
try {
|
|
||||||
Class.forName("com.lishid.openinv.internal." + version + ".AnySilentContainer");
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
catch (Exception e) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getVersion() {
|
|
||||||
return this.version != null ? this.version : "null";
|
|
||||||
}
|
|
||||||
|
|
||||||
private void printErrorMessage() {
|
|
||||||
plugin.getLogger().warning("OpenInv encountered an error with the CraftBukkit version \"" + version + "\". Please look for an updated version of OpenInv.");
|
|
||||||
}
|
|
||||||
|
|
||||||
public IPlayerDataManager newPlayerDataManager() {
|
|
||||||
return (IPlayerDataManager) createObject(IPlayerDataManager.class, "PlayerDataManager");
|
|
||||||
}
|
|
||||||
|
|
||||||
public IInventoryAccess newInventoryAccess() {
|
|
||||||
return (IInventoryAccess) createObject(IInventoryAccess.class, "InventoryAccess");
|
|
||||||
}
|
|
||||||
|
|
||||||
public IAnySilentContainer newAnySilentContainer() {
|
|
||||||
return (IAnySilentContainer) createObject(IAnySilentContainer.class, "AnySilentContainer");
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @deprecated Use {@link #newAnySilentContainer()}
|
|
||||||
*/
|
|
||||||
@Deprecated
|
|
||||||
public IAnySilentChest newAnySilentChest() {
|
|
||||||
return newAnySilentContainer();
|
|
||||||
}
|
|
||||||
|
|
||||||
public ISpecialPlayerInventory newSpecialPlayerInventory(Player player, boolean offline) {
|
|
||||||
try {
|
|
||||||
Class<?> internalClass = Class.forName("com.lishid.openinv.internal." + version + ".SpecialPlayerInventory");
|
|
||||||
if (ISpecialPlayerInventory.class.isAssignableFrom(internalClass)) {
|
|
||||||
return (ISpecialPlayerInventory) internalClass
|
|
||||||
.getConstructor(Player.class, Boolean.class)
|
|
||||||
.newInstance(player, offline);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
catch (Exception e) {
|
|
||||||
printErrorMessage();
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
public ISpecialEnderChest newSpecialEnderChest(Player player, boolean offline) {
|
|
||||||
try {
|
|
||||||
Class<?> internalClass = Class.forName("com.lishid.openinv.internal." + version + ".SpecialEnderChest");
|
|
||||||
if (ISpecialEnderChest.class.isAssignableFrom(internalClass)) {
|
|
||||||
return (ISpecialEnderChest) internalClass
|
|
||||||
.getConstructor(Player.class, Boolean.class)
|
|
||||||
.newInstance(player, offline);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
catch (Exception e) {
|
|
||||||
printErrorMessage();
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
private Object createObject(Class<? extends Object> assignableClass, String className) {
|
|
||||||
try {
|
|
||||||
Class<?> internalClass = Class.forName("com.lishid.openinv.internal." + version + "." + className);
|
|
||||||
if (assignableClass.isAssignableFrom(internalClass)) {
|
|
||||||
return internalClass.getConstructor().newInstance();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
catch (Exception e) {
|
|
||||||
printErrorMessage();
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
}
|
|
@@ -1,39 +0,0 @@
|
|||||||
name: OpenInv
|
|
||||||
main: com.lishid.openinv.OpenInv
|
|
||||||
version: ${project.version}
|
|
||||||
author: lishid
|
|
||||||
authors: [Jikoo]
|
|
||||||
description: >
|
|
||||||
This plugin allows you to open a player's inventory as a chest and interact with it in real time.
|
|
||||||
commands:
|
|
||||||
openinv:
|
|
||||||
aliases: [oi, inv, open]
|
|
||||||
description: Open a player's inventory
|
|
||||||
permission: OpenInv.*;OpenInv.openinv
|
|
||||||
usage: |
|
|
||||||
/<command> - Open last person's inventory
|
|
||||||
/<command> <Player> - Open a player's inventory
|
|
||||||
openender:
|
|
||||||
aliases: [oe]
|
|
||||||
description: Opens the enderchest of a player
|
|
||||||
permission: OpenInv.*;OpenInv.openender
|
|
||||||
usage: |
|
|
||||||
/<command> <Player> - Opens a player's enderchest
|
|
||||||
searchinv:
|
|
||||||
aliases: [si]
|
|
||||||
description: Search and list players having a specific item
|
|
||||||
permission: OpenInv.*;OpenInv.search
|
|
||||||
usage: |
|
|
||||||
/<command> <Item> [MinAmount] - Item can be the Item ID or the CraftBukkit Item Name, MinAmount is the minimum amount to be considered.
|
|
||||||
silentchest:
|
|
||||||
aliases: [sc, silent]
|
|
||||||
description: Toggle silent chest function, which hides the animation of a chest when opened or closed, and suppresses the sound.
|
|
||||||
permission: OpenInv.*;OpenInv.silent
|
|
||||||
usage: |
|
|
||||||
/<command> [Check] - Checks whether silent chest is enabled
|
|
||||||
anychest:
|
|
||||||
aliases: [ac]
|
|
||||||
description: Toggle anychest function, which allows opening of blocked chests.
|
|
||||||
permission: OpenInv.*;OpenInv.anychest
|
|
||||||
usage: |
|
|
||||||
/<command> [Check] - Checks whether anychest is enabled
|
|
128
README.MD
128
README.MD
@@ -1,23 +1,125 @@
|
|||||||
## Goals
|
## About
|
||||||
This fork of OpenInv was created when the lag caused by offline player lookups post-UUID migration became too much to bear. Overall, it does not differ much from the original.
|
OpenInv is a [Bukkit plugin](https://dev.bukkit.org/bukkit-plugins/openinv/) which allows users to open and edit anyone's inventory or ender chest - online or not!
|
||||||
|
|
||||||
### Changes of Note
|
## Features
|
||||||
- Removed updater
|
- **OpenInv**: Open anyone's inventory, even if they're offline.
|
||||||
- Removed wand
|
- Read-only mode! No edits allowed! Don't grant the permission `OpenInv.editinv`
|
||||||
- New configuration option `DisableSaving`: Inventory edits will not be saved unless the user is online.
|
- Cross-world support! Don't grant `OpenInv.crossworld`
|
||||||
|
- No self-opening! Don't grant `OpenInv.openself`
|
||||||
|
- Drop items as the player! Place items in the unused slots to the right of the armor to drop them
|
||||||
|
- **OpenEnder**: Open anyone's inventory, even if they're offline.
|
||||||
|
- Read-only mode! No edits allowed! Don't grant `OpenInv.editender`
|
||||||
|
- Cross-world support! Don't grant `OpenInv.crossworld`
|
||||||
|
- No opening others! Don't grant `OpenInv.openenderall`
|
||||||
|
- **SilentChest**: Open containers without displaying an animation or making sound.
|
||||||
|
- **AnyChest**: Open containers, even if blocked by ocelots or blocks.
|
||||||
|
|
||||||
## Previous Versions
|
## Commands
|
||||||
This fork supports any version after 1.4.5. Binaries are available in the [releases tab](https://github.com/Jikoo/OpenInv/releases). Please allow a brief period after the release of a new version for updates.
|
<table width=100%>
|
||||||
|
<tr>
|
||||||
|
<th width=175px>Command</th>
|
||||||
|
<th>Aliases</th>
|
||||||
|
<th>Description</th>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td>/openinv [player]</td>
|
||||||
|
<td>oi, inv, open</td>
|
||||||
|
<td>Open a player's inventory. If unspecified, will select last player opened or own if none opened previously.</td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td>/openender [player]</td>
|
||||||
|
<td>oe</td>
|
||||||
|
<td>Open a player's ender chest. If unspecified, will select last player opened or own if none opened previously.</td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td>/searchinv <item> [minAmount]</td>
|
||||||
|
<td>si</td>
|
||||||
|
<td>Lists all online players that have a certain item in their inventory.</td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td>/searchender <item> [minAmount]</td>
|
||||||
|
<td>se</td>
|
||||||
|
<td>Lists all online players that have a certain item in their ender chest.</td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td>/anychest [check]</td>
|
||||||
|
<td>ac</td>
|
||||||
|
<td>Check or toggle the AnyChest function, allowing opening blocked containers.</td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td>/silentchest [check]</td>
|
||||||
|
<td>sc</td>
|
||||||
|
<td>Check or toggle the SilentChest function, allowing opening containers silently.</td>
|
||||||
|
</tr>
|
||||||
|
</table>
|
||||||
|
|
||||||
|
## Permissions
|
||||||
|
<table>
|
||||||
|
<tr>
|
||||||
|
<th>Node</th>
|
||||||
|
<th>Description</th>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td>OpenInv.*</td>
|
||||||
|
<td>Gives permission to use all of OpenInv.</td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td>OpenInv.openinv</td>
|
||||||
|
<td>Required to use /openinv.</td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td>OpenInv.openself</td>
|
||||||
|
<td>Required to open own inventory.</td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td>OpenInv.editinv</td>
|
||||||
|
<td>Required to make changes to open inventories.</td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td>OpenInv.openender</td>
|
||||||
|
<td>Required to use /openender.</td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td>OpenInv.editender</td>
|
||||||
|
<td>Required to make changes to open ender chests.</td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td>OpenInv.openenderall</td>
|
||||||
|
<td>Allows users to open others' ender chests. Without it, users can only open their own.</td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td>OpenInv.exempt</td>
|
||||||
|
<td>Prevents the player's inventory being opened by others.</td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td>OpenInv.override</td>
|
||||||
|
<td>Allows bypassing of the exempt permission.</td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td>OpenInv.crossworld</td>
|
||||||
|
<td>Allows cross-world usage of /openinv and /openender.</td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td>OpenInv.search</td>
|
||||||
|
<td>Required to use /searchinv and /searchender.</td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td>OpenInv.anychest</td>
|
||||||
|
<td>Required to use /anychest.</td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td>OpenInv.silent</td>
|
||||||
|
<td>Required to use /silentchest.</td>
|
||||||
|
</tr>
|
||||||
|
</table>
|
||||||
|
|
||||||
## For Developers
|
## For Developers
|
||||||
To compile, the relevant Craftbukkit/Spigot jars must be installed in your local repository using the install plugin.
|
To compile, the relevant Craftbukkit/Spigot jars must be installed in your local repository using the install plugin.
|
||||||
Ex: `install:install-file -Dpackaging=jar -Dfile=spigot-1.11-R0.1-SNAPSHOT.jar -DgroupId=org.spigotmc -DartifactId=spigot -Dversion=1.11-R0.1-SNAPSHOT`
|
Ex: `mvn install:install-file -Dpackaging=jar -Dfile=spigot-1.11-R0.1-SNAPSHOT.jar -DgroupId=org.spigotmc -DartifactId=spigot -Dversion=1.11-R0.1-SNAPSHOT`
|
||||||
|
|
||||||
Compiling OpenInv for a specific version is very easy - just compile the correct module.
|
To compile for a specific version or set of versions, you'll need to use a profile. Provided profiles are `latest`, `modern` (versions 1.8+), and `all`. Select an existing profile using the `-P` argument (ex: `mvn clean package -am -P all`) or make your own. For more information, check out the [official guide](http://maven.apache.org/guides/introduction/introduction-to-profiles.html).
|
||||||
|
|
||||||
Compiling for a set of versions is slightly more complex. You'll need to use a profile for the versions you want to compile. Provided profiles are latest, modern (versions 1.7.10+), and all. For more information, check out the [official guide](http://maven.apache.org/guides/introduction/introduction-to-profiles.html).
|
The final file is target/OpenInv.jar
|
||||||
|
|
||||||
Regarding deprecation: Any deprecated methods will be removed in the next minor revision bump.
|
|
||||||
|
|
||||||
## License
|
## License
|
||||||
```
|
```
|
||||||
|
@@ -8,8 +8,8 @@
|
|||||||
<version>1.0-SNAPSHOT</version>
|
<version>1.0-SNAPSHOT</version>
|
||||||
</parent>
|
</parent>
|
||||||
|
|
||||||
<artifactId>openinvcore</artifactId>
|
<artifactId>openinvapi</artifactId>
|
||||||
<name>OpenInvCore</name>
|
<name>OpenInvAPI</name>
|
||||||
|
|
||||||
<dependencies>
|
<dependencies>
|
||||||
<dependency>
|
<dependency>
|
||||||
@@ -19,4 +19,5 @@
|
|||||||
<scope>provided</scope>
|
<scope>provided</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
</dependencies>
|
</dependencies>
|
||||||
|
|
||||||
</project>
|
</project>
|
153
api/src/main/java/com/lishid/openinv/IOpenInv.java
Normal file
153
api/src/main/java/com/lishid/openinv/IOpenInv.java
Normal file
@@ -0,0 +1,153 @@
|
|||||||
|
package com.lishid.openinv;
|
||||||
|
|
||||||
|
import com.lishid.openinv.internal.IAnySilentContainer;
|
||||||
|
import com.lishid.openinv.internal.IInventoryAccess;
|
||||||
|
import com.lishid.openinv.internal.ISpecialEnderChest;
|
||||||
|
import com.lishid.openinv.internal.ISpecialPlayerInventory;
|
||||||
|
|
||||||
|
import org.bukkit.OfflinePlayer;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Interface defining behavior for the OpenInv plugin.
|
||||||
|
*
|
||||||
|
* @author Jikoo
|
||||||
|
*/
|
||||||
|
public interface IOpenInv {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Checks if the server version is supported by OpenInv.
|
||||||
|
*
|
||||||
|
* @return true if the server version is supported
|
||||||
|
*/
|
||||||
|
public boolean isSupportedVersion();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the active IInventoryAccess implementation. May return null if the server version is
|
||||||
|
* unsupported.
|
||||||
|
*
|
||||||
|
* @return the IInventoryAccess
|
||||||
|
*/
|
||||||
|
public IInventoryAccess getInventoryAccess();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the active ISilentContainer implementation. May return null if the server version is
|
||||||
|
* unsupported.
|
||||||
|
*
|
||||||
|
* @return the ISilentContainer
|
||||||
|
*/
|
||||||
|
public IAnySilentContainer getAnySilentContainer();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets an ISpecialPlayerInventory for the given Player.
|
||||||
|
*
|
||||||
|
* @param player the Player
|
||||||
|
* @param online true if the Player is currently online
|
||||||
|
* @return the ISpecialPlayerInventory
|
||||||
|
*/
|
||||||
|
public ISpecialPlayerInventory getInventory(Player player, boolean online);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets an ISpecialEnderChest for the given Player.
|
||||||
|
*
|
||||||
|
* @param player the Player
|
||||||
|
* @param online true if the Player is currently online
|
||||||
|
* @return the ISpecialEnderChest
|
||||||
|
*/
|
||||||
|
public ISpecialEnderChest getEnderChest(Player player, boolean online);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Forcibly unload a cached Player's data.
|
||||||
|
*
|
||||||
|
* @param player the OfflinePlayer to unload
|
||||||
|
*/
|
||||||
|
public void unload(OfflinePlayer player);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Check the configuration value for whether or not OpenInv saves player data when unloading
|
||||||
|
* players. This is exclusively for users who do not allow editing of inventories, only viewing,
|
||||||
|
* and wish to prevent any possibility of bugs such as lishid#40. If true, OpenInv will not ever
|
||||||
|
* save any edits made to players.
|
||||||
|
*
|
||||||
|
* @return false unless configured otherwise
|
||||||
|
*/
|
||||||
|
public boolean disableSaving();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Check the configuration value for whether or not OpenInv displays a notification to the user
|
||||||
|
* when a container is activated with SilentChest.
|
||||||
|
*
|
||||||
|
* @return true unless configured otherwise
|
||||||
|
*/
|
||||||
|
public boolean notifySilentChest();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Check the configuration value for whether or not OpenInv displays a notification to the user
|
||||||
|
* when a container is activated with AnyChest.
|
||||||
|
*
|
||||||
|
* @return true unless configured otherwise
|
||||||
|
*/
|
||||||
|
public boolean notifyAnyChest();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets a player's SilentChest setting.
|
||||||
|
*
|
||||||
|
* @param player the OfflinePlayer
|
||||||
|
* @return true if SilentChest is enabled
|
||||||
|
*/
|
||||||
|
public boolean getPlayerSilentChestStatus(OfflinePlayer player);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets a player's SilentChest setting.
|
||||||
|
*
|
||||||
|
* @param player the OfflinePlayer
|
||||||
|
* @param status the status
|
||||||
|
*/
|
||||||
|
public void setPlayerSilentChestStatus(OfflinePlayer player, boolean status);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the provided player's AnyChest setting.
|
||||||
|
*
|
||||||
|
* @param player the OfflinePlayer
|
||||||
|
* @return true if AnyChest is enabled
|
||||||
|
*/
|
||||||
|
public boolean getPlayerAnyChestStatus(OfflinePlayer player);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets a player's AnyChest setting.
|
||||||
|
*
|
||||||
|
* @param player the OfflinePlayer
|
||||||
|
* @param status the status
|
||||||
|
*/
|
||||||
|
public void setPlayerAnyChestStatus(OfflinePlayer player, boolean status);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets a unique identifier by which the OfflinePlayer can be referenced. Using the value
|
||||||
|
* returned to look up a Player will generally be much faster for later implementations.
|
||||||
|
*
|
||||||
|
* @param offline the OfflinePlayer
|
||||||
|
* @return the identifier
|
||||||
|
*/
|
||||||
|
public String getPlayerID(OfflinePlayer offline);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get an OfflinePlayer by name.
|
||||||
|
* <p>
|
||||||
|
* Note: This method is potentially very heavily blocking. It should not ever be called on the
|
||||||
|
* main thread, and if it is, a stack trace will be displayed alerting server owners to the
|
||||||
|
* call.
|
||||||
|
*
|
||||||
|
* @param name the name of the Player
|
||||||
|
* @return the OfflinePlayer with the closest matching name or null if no players have ever logged in
|
||||||
|
*/
|
||||||
|
public OfflinePlayer matchPlayer(String name);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Load a Player from an OfflinePlayer. May return null under some circumstances.
|
||||||
|
*
|
||||||
|
* @param offline the OfflinePlayer to load a Player for
|
||||||
|
* @return the Player
|
||||||
|
*/
|
||||||
|
public Player loadPlayer(final OfflinePlayer offline);
|
||||||
|
|
||||||
|
}
|
@@ -1,9 +1,9 @@
|
|||||||
package com.lishid.openinv.internal;
|
package com.lishid.openinv.internal;
|
||||||
|
|
||||||
import org.bukkit.block.BlockState;
|
import org.bukkit.block.Block;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
public interface IAnySilentContainer extends IAnySilentChest {
|
public interface IAnySilentContainer {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Checks if the given block is a container which can be unblocked or silenced.
|
* Checks if the given block is a container which can be unblocked or silenced.
|
||||||
@@ -11,30 +11,27 @@ public interface IAnySilentContainer extends IAnySilentChest {
|
|||||||
* @param block the BlockState
|
* @param block the BlockState
|
||||||
* @return true if the Block is a supported container
|
* @return true if the Block is a supported container
|
||||||
*/
|
*/
|
||||||
public boolean isAnySilentContainer(BlockState block);
|
public boolean isAnySilentContainer(Block block);
|
||||||
|
|
||||||
/**
|
|
||||||
* Opens the container at the given coordinates for the Player.
|
|
||||||
*
|
|
||||||
* @param player
|
|
||||||
* @param anychest whether compatibility for blocked containers is to be used
|
|
||||||
* @param silentchest whether the container's noise is to be silenced
|
|
||||||
* @param x the x coordinate
|
|
||||||
* @param y the y coordinate
|
|
||||||
* @param z the z coordinate
|
|
||||||
* @return true if the container can be opened
|
|
||||||
*/
|
|
||||||
public boolean activateContainer(Player player, boolean anychest, boolean silentchest, int x, int y, int z);
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Checks if the container at the given coordinates is blocked.
|
* Checks if the container at the given coordinates is blocked.
|
||||||
*
|
*
|
||||||
* @param player the Player opening the container
|
* @param player the Player opening the container
|
||||||
* @param x the x coordinate
|
* @param block the Block
|
||||||
* @param y the y coordinate
|
|
||||||
* @param z the z coordinate
|
|
||||||
* @return true if the container is blocked
|
* @return true if the container is blocked
|
||||||
*/
|
*/
|
||||||
public boolean isAnyContainerNeeded(Player player, int x, int y, int z);
|
public boolean isAnyContainerNeeded(Player player, Block block);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Opens the container at the given coordinates for the Player. If you do not want blocked
|
||||||
|
* containers to open, be sure to check {@link #isAnyContainerNeeded(Player, Block)}
|
||||||
|
* first.
|
||||||
|
*
|
||||||
|
* @param player
|
||||||
|
* @param silentchest whether the container's noise is to be silenced
|
||||||
|
* @param block the Block
|
||||||
|
* @return true if the container can be opened
|
||||||
|
*/
|
||||||
|
public boolean activateContainer(Player player, boolean silentchest, Block block);
|
||||||
|
|
||||||
}
|
}
|
@@ -0,0 +1,57 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (C) 2011-2014 lishid. All rights reserved.
|
||||||
|
*
|
||||||
|
* This program is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation, version 3.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package com.lishid.openinv.internal;
|
||||||
|
|
||||||
|
import org.bukkit.inventory.Inventory;
|
||||||
|
|
||||||
|
public interface IInventoryAccess {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Check if an Inventory is an ISpecialPlayerInventory implementation.
|
||||||
|
*
|
||||||
|
* @param inventory the Inventory
|
||||||
|
* @return true if the Inventory is backed by an ISpecialPlayerInventory
|
||||||
|
*/
|
||||||
|
public boolean isSpecialPlayerInventory(Inventory inventory);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets an ISpecialPlayerInventory from an Inventory or null if the Inventory is not backed by
|
||||||
|
* an ISpecialPlayerInventory.
|
||||||
|
*
|
||||||
|
* @param inventory the Inventory
|
||||||
|
* @return the ISpecialPlayerInventory or null
|
||||||
|
*/
|
||||||
|
public ISpecialPlayerInventory getSpecialPlayerInventory(Inventory inventory);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Check if an Inventory is an ISpecialEnderChest implementation.
|
||||||
|
*
|
||||||
|
* @param inventory the Inventory
|
||||||
|
* @return true if the Inventory is backed by an ISpecialEnderChest
|
||||||
|
*/
|
||||||
|
public boolean isSpecialEnderChest(Inventory inventory);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets an ISpecialEnderChest from an Inventory or null if the Inventory is not backed by an
|
||||||
|
* ISpecialEnderChest.
|
||||||
|
*
|
||||||
|
* @param inventory the Inventory
|
||||||
|
* @return the ISpecialEnderChest or null
|
||||||
|
*/
|
||||||
|
public ISpecialEnderChest getSpecialEnderChest(Inventory inventory);
|
||||||
|
|
||||||
|
}
|
@@ -39,4 +39,12 @@ public interface IPlayerDataManager {
|
|||||||
*/
|
*/
|
||||||
public String getPlayerDataID(OfflinePlayer player);
|
public String getPlayerDataID(OfflinePlayer player);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets an OfflinePlayer by the given unique identifier.
|
||||||
|
*
|
||||||
|
* @param identifier the unique identifier
|
||||||
|
* @return the OfflinePlayer, or null if no exact match was found
|
||||||
|
*/
|
||||||
|
public OfflinePlayer getPlayerByID(String identifier);
|
||||||
|
|
||||||
}
|
}
|
42
assembly/pom.xml
Normal file
42
assembly/pom.xml
Normal file
@@ -0,0 +1,42 @@
|
|||||||
|
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||||
|
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||||
|
<modelVersion>4.0.0</modelVersion>
|
||||||
|
|
||||||
|
<parent>
|
||||||
|
<groupId>com.lishid</groupId>
|
||||||
|
<artifactId>openinvparent</artifactId>
|
||||||
|
<version>1.0-SNAPSHOT</version>
|
||||||
|
</parent>
|
||||||
|
|
||||||
|
<artifactId>openinvassembly</artifactId>
|
||||||
|
<name>OpenInvAssembly</name>
|
||||||
|
|
||||||
|
<build>
|
||||||
|
<directory>../target</directory>
|
||||||
|
<finalName>OpenInv</finalName>
|
||||||
|
|
||||||
|
<plugins>
|
||||||
|
<plugin>
|
||||||
|
<artifactId>maven-assembly-plugin</artifactId>
|
||||||
|
<version>3.0.0</version>
|
||||||
|
<executions>
|
||||||
|
<execution>
|
||||||
|
<id>reactor-uberjar</id>
|
||||||
|
<phase>package</phase>
|
||||||
|
<goals>
|
||||||
|
<goal>single</goal>
|
||||||
|
</goals>
|
||||||
|
<configuration>
|
||||||
|
<appendAssemblyId>false</appendAssemblyId>
|
||||||
|
<descriptors>
|
||||||
|
<descriptor>src/assembly/reactor-uberjar.xml</descriptor>
|
||||||
|
</descriptors>
|
||||||
|
</configuration>
|
||||||
|
</execution>
|
||||||
|
</executions>
|
||||||
|
</plugin>
|
||||||
|
</plugins>
|
||||||
|
|
||||||
|
</build>
|
||||||
|
|
||||||
|
</project>
|
28
assembly/src/assembly/reactor-uberjar.xml
Normal file
28
assembly/src/assembly/reactor-uberjar.xml
Normal file
@@ -0,0 +1,28 @@
|
|||||||
|
<assembly xmlns="http://maven.apache.org/ASSEMBLY/2.0.0"
|
||||||
|
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||||
|
xsi:schemaLocation="http://maven.apache.org/ASSEMBLY/2.0.0 http://maven.apache.org/xsd/assembly-2.0.0.xsd">
|
||||||
|
|
||||||
|
<id>reactor-uberjar</id>
|
||||||
|
|
||||||
|
<formats>
|
||||||
|
<format>jar</format>
|
||||||
|
</formats>
|
||||||
|
|
||||||
|
<includeBaseDirectory>false</includeBaseDirectory>
|
||||||
|
|
||||||
|
<moduleSets>
|
||||||
|
<moduleSet>
|
||||||
|
|
||||||
|
<useAllReactorProjects>true</useAllReactorProjects>
|
||||||
|
|
||||||
|
<binaries>
|
||||||
|
<outputDirectory>/</outputDirectory>
|
||||||
|
<unpack>true</unpack>
|
||||||
|
<!-- unpackOptions must be present or build breaks. -->
|
||||||
|
<unpackOptions/>
|
||||||
|
</binaries>
|
||||||
|
|
||||||
|
</moduleSet>
|
||||||
|
</moduleSets>
|
||||||
|
|
||||||
|
</assembly>
|
@@ -8,27 +8,22 @@
|
|||||||
<version>1.0-SNAPSHOT</version>
|
<version>1.0-SNAPSHOT</version>
|
||||||
</parent>
|
</parent>
|
||||||
|
|
||||||
<artifactId>openinvplugin</artifactId>
|
<artifactId>openinvcommon</artifactId>
|
||||||
<name>OpenInvPlugin</name>
|
<name>OpenInvCommon</name>
|
||||||
|
|
||||||
<repositories>
|
|
||||||
<repository>
|
|
||||||
<id>spigot-repo</id>
|
|
||||||
<url>https://hub.spigotmc.org/nexus/content/groups/public/</url>
|
|
||||||
</repository>
|
|
||||||
</repositories>
|
|
||||||
|
|
||||||
<dependencies>
|
<dependencies>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.bukkit</groupId>
|
<groupId>org.bukkit</groupId>
|
||||||
<artifactId>bukkit</artifactId>
|
<artifactId>bukkit</artifactId>
|
||||||
<version>1.10.2-R0.1-SNAPSHOT</version>
|
<version>1.4.5-R1.0</version>
|
||||||
<scope>provided</scope>
|
<scope>provided</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>com.lishid</groupId>
|
<groupId>com.lishid</groupId>
|
||||||
<artifactId>openinvcore</artifactId>
|
<artifactId>openinvapi</artifactId>
|
||||||
<version>1.0-SNAPSHOT</version>
|
<version>1.0-SNAPSHOT</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
</dependencies>
|
</dependencies>
|
||||||
|
|
||||||
</project>
|
</project>
|
@@ -0,0 +1,186 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (C) 2011-2014 lishid. All rights reserved.
|
||||||
|
*
|
||||||
|
* This program is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation, version 3.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package com.lishid.openinv.util;
|
||||||
|
|
||||||
|
import java.lang.reflect.Constructor;
|
||||||
|
import java.lang.reflect.Field;
|
||||||
|
|
||||||
|
import com.lishid.openinv.internal.IAnySilentContainer;
|
||||||
|
import com.lishid.openinv.internal.IInventoryAccess;
|
||||||
|
import com.lishid.openinv.internal.IPlayerDataManager;
|
||||||
|
import com.lishid.openinv.internal.ISpecialEnderChest;
|
||||||
|
import com.lishid.openinv.internal.ISpecialPlayerInventory;
|
||||||
|
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
import org.bukkit.plugin.Plugin;
|
||||||
|
|
||||||
|
public class InternalAccessor {
|
||||||
|
|
||||||
|
private final Plugin plugin;
|
||||||
|
|
||||||
|
private final String version;
|
||||||
|
private boolean supported = false;
|
||||||
|
|
||||||
|
public InternalAccessor(Plugin plugin) {
|
||||||
|
this.plugin = plugin;
|
||||||
|
|
||||||
|
String packageName = plugin.getServer().getClass().getPackage().getName();
|
||||||
|
version = packageName.substring(packageName.lastIndexOf('.') + 1);
|
||||||
|
|
||||||
|
try {
|
||||||
|
Class.forName("com.lishid.openinv.internal." + version + ".PlayerDataManager");
|
||||||
|
supported = true;
|
||||||
|
} catch (Exception e) {}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the server implementation version. If not initialized, returns the string "null"
|
||||||
|
* instead.
|
||||||
|
*
|
||||||
|
* @return the version, or "null"
|
||||||
|
*/
|
||||||
|
public String getVersion() {
|
||||||
|
return this.version != null ? this.version : "null";
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Checks if the server implementation is supported.
|
||||||
|
*
|
||||||
|
* @return true if initialized for a supported server version
|
||||||
|
*/
|
||||||
|
public boolean isSupported() {
|
||||||
|
return this.supported;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates an instance of the IPlayerDataManager implementation for the current server version,
|
||||||
|
* or null if unsupported.
|
||||||
|
*
|
||||||
|
* @return the IPlayerDataManager
|
||||||
|
*/
|
||||||
|
public IPlayerDataManager newPlayerDataManager() {
|
||||||
|
return createObject(IPlayerDataManager.class, "PlayerDataManager");
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates an instance of the IInventoryAccess implementation for the current server version, or
|
||||||
|
* null if unsupported.
|
||||||
|
*
|
||||||
|
* @return the IInventoryAccess
|
||||||
|
*/
|
||||||
|
public IInventoryAccess newInventoryAccess() {
|
||||||
|
return createObject(IInventoryAccess.class, "InventoryAccess");
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates an instance of the IAnySilentContainer implementation for the current server version,
|
||||||
|
* or null if unsupported.
|
||||||
|
*
|
||||||
|
* @return the IAnySilentContainer
|
||||||
|
*/
|
||||||
|
public IAnySilentContainer newAnySilentContainer() {
|
||||||
|
return createObject(IAnySilentContainer.class, "AnySilentContainer");
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates an instance of the ISpecialPlayerInventory implementation for the given Player, or
|
||||||
|
* null if the current version is unsupported.
|
||||||
|
*
|
||||||
|
* @param player the Player
|
||||||
|
* @param online true if the Player is online
|
||||||
|
* @return the ISpecialPlayerInventory created
|
||||||
|
*/
|
||||||
|
public ISpecialPlayerInventory newSpecialPlayerInventory(Player player, boolean online) {
|
||||||
|
return createObject(ISpecialPlayerInventory.class, "SpecialPlayerInventory", player, online);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates an instance of the ISpecialEnderChest implementation for the given Player, or
|
||||||
|
* null if the current version is unsupported.
|
||||||
|
*
|
||||||
|
* @param player the Player
|
||||||
|
* @param online true if the Player is online
|
||||||
|
* @return the ISpecialEnderChest created
|
||||||
|
*/
|
||||||
|
public ISpecialEnderChest newSpecialEnderChest(Player player, boolean online) {
|
||||||
|
return createObject(ISpecialEnderChest.class, "SpecialEnderChest", player, online);
|
||||||
|
}
|
||||||
|
|
||||||
|
private <T> T createObject(Class<? extends T> assignableClass, String className, Object... params) {
|
||||||
|
try {
|
||||||
|
// Check if internal versioned class exists
|
||||||
|
Class<?> internalClass = Class.forName("com.lishid.openinv.internal." + version + "." + className);
|
||||||
|
if (!assignableClass.isAssignableFrom(internalClass)) {
|
||||||
|
plugin.getLogger().warning("Found class " + internalClass.getName() + " but cannot cast to " + assignableClass.getName());
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Quick return: no parameters, no need to fiddle about finding the correct constructor.
|
||||||
|
if (params.length == 0) {
|
||||||
|
return assignableClass.cast(internalClass.getConstructor().newInstance());
|
||||||
|
}
|
||||||
|
|
||||||
|
// Search constructors for one matching the given parameters
|
||||||
|
nextConstructor: for (Constructor<?> constructor : internalClass.getConstructors()) {
|
||||||
|
Class<?>[] requiredClasses = constructor.getParameterTypes();
|
||||||
|
if (requiredClasses.length != params.length) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
for (int i = 0; i < params.length; ++i) {
|
||||||
|
if (!requiredClasses[i].isAssignableFrom(params[i].getClass())) {
|
||||||
|
continue nextConstructor;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return assignableClass.cast(constructor.newInstance(params));
|
||||||
|
}
|
||||||
|
|
||||||
|
StringBuilder message = new StringBuilder("Found class ").append(internalClass.getName())
|
||||||
|
.append(" but cannot find any matching constructors for [");
|
||||||
|
for (Object object : params) {
|
||||||
|
message.append(object.getClass().getName()).append(", ");
|
||||||
|
}
|
||||||
|
if (params.length > 0) {
|
||||||
|
message.delete(message.length() - 2, message.length());
|
||||||
|
}
|
||||||
|
|
||||||
|
plugin.getLogger().warning(message.append(']').toString());
|
||||||
|
} catch (Exception e) {
|
||||||
|
plugin.getLogger().warning("OpenInv encountered an error with the CraftBukkit version \"" + version + "\". Please look for an updated version of OpenInv.");
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static <T> T grabFieldOfTypeFromObject(Class<T> type, Object object) {
|
||||||
|
// Use reflection to find the iinventory
|
||||||
|
Class<?> clazz = object.getClass();
|
||||||
|
T result = null;
|
||||||
|
for (Field f : clazz.getDeclaredFields()) {
|
||||||
|
f.setAccessible(true);
|
||||||
|
if (type.isAssignableFrom(f.getDeclaringClass())) {
|
||||||
|
try {
|
||||||
|
result = type.cast(f.get(object));
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@@ -0,0 +1,38 @@
|
|||||||
|
package com.lishid.openinv.util;
|
||||||
|
|
||||||
|
import org.bukkit.permissions.Permissible;
|
||||||
|
|
||||||
|
public enum Permissions {
|
||||||
|
|
||||||
|
OPENINV("OpenInv.openinv"),
|
||||||
|
OVERRIDE("OpenInv.override"),
|
||||||
|
EXEMPT("OpenInv.exempt"),
|
||||||
|
CROSSWORLD("OpenInv.crossworld"),
|
||||||
|
SILENT("OpenInv.silent"),
|
||||||
|
ANYCHEST("OpenInv.anychest"),
|
||||||
|
ENDERCHEST("OpenInv.openender"),
|
||||||
|
ENDERCHEST_ALL("OpenInv.openenderall"),
|
||||||
|
SEARCH("OpenInv.search"),
|
||||||
|
EDITINV("OpenInv.editinv"),
|
||||||
|
EDITENDER("OpenInv.editender"),
|
||||||
|
OPENSELF("OpenInv.openself");
|
||||||
|
|
||||||
|
private final String permission;
|
||||||
|
|
||||||
|
private Permissions(String permission) {
|
||||||
|
this.permission = permission;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean hasPermission(Permissible permissible) {
|
||||||
|
String[] parts = permission.split("\\.");
|
||||||
|
String perm = "";
|
||||||
|
for (int i = 0; i < parts.length; i++) {
|
||||||
|
if (permissible.hasPermission(perm + "*")) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
perm += parts[i] + ".";
|
||||||
|
}
|
||||||
|
return permissible.hasPermission(permission);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@@ -4,22 +4,17 @@
|
|||||||
|
|
||||||
<parent>
|
<parent>
|
||||||
<groupId>com.lishid</groupId>
|
<groupId>com.lishid</groupId>
|
||||||
<artifactId>openinvparent</artifactId>
|
<artifactId>openinvinternal</artifactId>
|
||||||
<version>1.0-SNAPSHOT</version>
|
<version>1.0-SNAPSHOT</version>
|
||||||
</parent>
|
</parent>
|
||||||
|
|
||||||
<artifactId>OpenInvCraftbukkit1_4_5</artifactId>
|
<artifactId>openinvadapter1_4_5</artifactId>
|
||||||
<name>OpenInvCraftbukkit1_4_5</name>
|
<name>OpenInvAdapter1_4_5</name>
|
||||||
|
|
||||||
<dependencies>
|
<dependencies>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>com.lishid</groupId>
|
<groupId>com.lishid</groupId>
|
||||||
<artifactId>openinvcore</artifactId>
|
<artifactId>openinvcommon</artifactId>
|
||||||
<version>1.0-SNAPSHOT</version>
|
|
||||||
</dependency>
|
|
||||||
<dependency>
|
|
||||||
<groupId>com.lishid</groupId>
|
|
||||||
<artifactId>openinvplugin</artifactId>
|
|
||||||
<version>1.0-SNAPSHOT</version>
|
<version>1.0-SNAPSHOT</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
@@ -29,4 +24,5 @@
|
|||||||
<scope>provided</scope>
|
<scope>provided</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
</dependencies>
|
</dependencies>
|
||||||
|
|
||||||
</project>
|
</project>
|
@@ -0,0 +1,158 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (C) 2011-2014 lishid. All rights reserved.
|
||||||
|
*
|
||||||
|
* This program is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation, version 3.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package com.lishid.openinv.internal.v1_4_5;
|
||||||
|
|
||||||
|
import com.lishid.openinv.internal.IAnySilentContainer;
|
||||||
|
|
||||||
|
import org.bukkit.ChatColor;
|
||||||
|
import org.bukkit.Material;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
|
// Volatile
|
||||||
|
import net.minecraft.server.v1_4_5.AxisAlignedBB;
|
||||||
|
import net.minecraft.server.v1_4_5.BlockEnderChest;
|
||||||
|
import net.minecraft.server.v1_4_5.EntityOcelot;
|
||||||
|
import net.minecraft.server.v1_4_5.EntityPlayer;
|
||||||
|
import net.minecraft.server.v1_4_5.IInventory;
|
||||||
|
import net.minecraft.server.v1_4_5.InventoryEnderChest;
|
||||||
|
import net.minecraft.server.v1_4_5.InventoryLargeChest;
|
||||||
|
import net.minecraft.server.v1_4_5.Packet100OpenWindow;
|
||||||
|
import net.minecraft.server.v1_4_5.TileEntityChest;
|
||||||
|
import net.minecraft.server.v1_4_5.TileEntityEnderChest;
|
||||||
|
import net.minecraft.server.v1_4_5.World;
|
||||||
|
|
||||||
|
import org.bukkit.craftbukkit.v1_4_5.entity.CraftPlayer;
|
||||||
|
|
||||||
|
public class AnySilentContainer implements IAnySilentContainer {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isAnySilentContainer(org.bukkit.block.Block block) {
|
||||||
|
return block.getType() == Material.ENDER_CHEST || block.getState() instanceof org.bukkit.block.Chest;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isAnyContainerNeeded(Player p, org.bukkit.block.Block block) {
|
||||||
|
// FOR REFERENCE, LOOK AT net.minecraft.server.BlockChest
|
||||||
|
EntityPlayer player = ((CraftPlayer) p).getHandle();
|
||||||
|
World world = player.world;
|
||||||
|
|
||||||
|
if (block instanceof BlockEnderChest) {
|
||||||
|
// Ender chests are not blocked by ocelots.
|
||||||
|
return world.t(block.getX(), block.getY() + 1, block.getZ());
|
||||||
|
}
|
||||||
|
|
||||||
|
// If block or ocelot on top
|
||||||
|
if (isBlockedChest(world, block.getX(), block.getY() + 1, block.getZ())) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
int id = world.getTypeId(block.getX(), block.getY(), block.getZ());
|
||||||
|
|
||||||
|
// If block next to chest is chest and has a block or ocelot on top
|
||||||
|
if (world.getTypeId(block.getX(), block.getY(), block.getZ() + 1) == id) {
|
||||||
|
return isBlockedChest(world, block.getX(), block.getY() + 1, block.getZ() + 1);
|
||||||
|
} else if(world.getTypeId(block.getX(), block.getY(), block.getZ() - 1) == id) {
|
||||||
|
return isBlockedChest(world, block.getX(), block.getY() + 1, block.getZ() - 1);
|
||||||
|
} else if (world.getTypeId(block.getX() + 1, block.getY(), block.getZ()) == id) {
|
||||||
|
return isBlockedChest(world, block.getX() + 1, block.getY() + 1, block.getZ());
|
||||||
|
} else if (world.getTypeId(block.getX() - 1, block.getY(), block.getZ()) == id) {
|
||||||
|
return isBlockedChest(world, block.getX() - 1, block.getY() + 1, block.getZ());
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
private boolean isBlockedChest(World world, int x, int y, int z) {
|
||||||
|
return world.t(x, y + 1, z) || hasOcelotOnTop(world, x, y, z);
|
||||||
|
}
|
||||||
|
|
||||||
|
private boolean hasOcelotOnTop(World world, int x, int y, int z) {
|
||||||
|
for (Object localEntity : world.a(EntityOcelot.class,
|
||||||
|
AxisAlignedBB.a(x, y + 1, z, x + 1, y + 2, z + 1))) {
|
||||||
|
EntityOcelot localEntityOcelot = (EntityOcelot) localEntity;
|
||||||
|
if (localEntityOcelot.isSitting()) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean activateContainer(Player p, boolean silentchest, org.bukkit.block.Block block) {
|
||||||
|
|
||||||
|
EntityPlayer player = ((CraftPlayer) p).getHandle();
|
||||||
|
|
||||||
|
// Silent ender chest is API-only
|
||||||
|
if (silentchest && block.getType() == Material.ENDER_CHEST) {
|
||||||
|
p.openInventory(p.getEnderChest());
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
World world = player.world;
|
||||||
|
Object tile = world.getTileEntity(block.getX(), block.getY(), block.getZ());
|
||||||
|
|
||||||
|
if (tile == null) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (tile instanceof TileEntityEnderChest) {
|
||||||
|
// Anychest ender chest. See net.minecraft.server.BlockEnderChest
|
||||||
|
InventoryEnderChest enderChest = player.getEnderChest();
|
||||||
|
enderChest.a((TileEntityEnderChest) tile);
|
||||||
|
player.openContainer(enderChest);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!(tile instanceof IInventory)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
int id = world.getTypeId(block.getX(), block.getY(), block.getZ());
|
||||||
|
|
||||||
|
if (world.getTypeId(block.getX(), block.getY(), block.getZ() + 1) == id) {
|
||||||
|
tile = new InventoryLargeChest("Large chest", (IInventory) tile, (TileEntityChest) world.getTileEntity(block.getX(), block.getY(), block.getZ() + 1));
|
||||||
|
} else if (world.getTypeId(block.getX(), block.getY(), block.getZ() - 1) == id) {
|
||||||
|
tile = new InventoryLargeChest("Large chest", (TileEntityChest) world.getTileEntity(block.getX(), block.getY(), block.getZ() - 1), (IInventory) tile);
|
||||||
|
} else if (world.getTypeId(block.getX() + 1, block.getY(), block.getZ()) == id) {
|
||||||
|
tile = new InventoryLargeChest("Large chest", (IInventory) tile, (TileEntityChest) world.getTileEntity(block.getX() + 1, block.getY(), block.getZ()));
|
||||||
|
} else if (world.getTypeId(block.getX() - 1, block.getY(), block.getZ()) == id) {
|
||||||
|
tile = new InventoryLargeChest("Large chest", (TileEntityChest) world.getTileEntity(block.getX() - 1, block.getY(), block.getZ()), (IInventory) tile);
|
||||||
|
}
|
||||||
|
|
||||||
|
boolean returnValue = false;
|
||||||
|
if (!silentchest) {
|
||||||
|
player.openContainer((IInventory) tile);
|
||||||
|
returnValue = true;
|
||||||
|
} else {
|
||||||
|
try {
|
||||||
|
int windowId = player.nextContainerCounter();
|
||||||
|
player.netServerHandler.sendPacket(new Packet100OpenWindow(windowId, 0, ((IInventory) tile).getName(), ((IInventory) tile).getSize()));
|
||||||
|
player.activeContainer = new SilentContainerChest(player.inventory, ((IInventory) tile));
|
||||||
|
player.activeContainer.windowId = windowId;
|
||||||
|
player.activeContainer.addSlotListener(player);
|
||||||
|
returnValue = true;
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
p.sendMessage(ChatColor.RED + "Error while sending silent chest.");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return returnValue;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@@ -0,0 +1,79 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (C) 2011-2014 lishid. All rights reserved.
|
||||||
|
*
|
||||||
|
* This program is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation, version 3.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package com.lishid.openinv.internal.v1_4_5;
|
||||||
|
|
||||||
|
import com.lishid.openinv.internal.IInventoryAccess;
|
||||||
|
import com.lishid.openinv.internal.ISpecialEnderChest;
|
||||||
|
import com.lishid.openinv.internal.ISpecialPlayerInventory;
|
||||||
|
import com.lishid.openinv.util.InternalAccessor;
|
||||||
|
|
||||||
|
import org.bukkit.inventory.Inventory;
|
||||||
|
|
||||||
|
// Volatile
|
||||||
|
import net.minecraft.server.v1_4_5.IInventory;
|
||||||
|
|
||||||
|
import org.bukkit.craftbukkit.v1_4_5.inventory.CraftInventory;
|
||||||
|
|
||||||
|
public class InventoryAccess implements IInventoryAccess {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isSpecialPlayerInventory(Inventory inventory) {
|
||||||
|
if (inventory instanceof CraftInventory) {
|
||||||
|
return ((CraftInventory) inventory).getInventory() instanceof ISpecialPlayerInventory;
|
||||||
|
}
|
||||||
|
return InternalAccessor.grabFieldOfTypeFromObject(IInventory.class, inventory) instanceof ISpecialPlayerInventory;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public ISpecialPlayerInventory getSpecialPlayerInventory(Inventory inventory) {
|
||||||
|
IInventory inv;
|
||||||
|
if (inventory instanceof CraftInventory) {
|
||||||
|
inv = ((CraftInventory) inventory).getInventory();
|
||||||
|
} else {
|
||||||
|
inv = InternalAccessor.grabFieldOfTypeFromObject(IInventory.class, inventory);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (inv instanceof SpecialPlayerInventory) {
|
||||||
|
return (SpecialPlayerInventory) inv;
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isSpecialEnderChest(Inventory inventory) {
|
||||||
|
if (inventory instanceof CraftInventory) {
|
||||||
|
return ((CraftInventory) inventory).getInventory() instanceof ISpecialEnderChest;
|
||||||
|
}
|
||||||
|
return InternalAccessor.grabFieldOfTypeFromObject(IInventory.class, inventory) instanceof ISpecialEnderChest;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public ISpecialEnderChest getSpecialEnderChest(Inventory inventory) {
|
||||||
|
IInventory inv;
|
||||||
|
if (inventory instanceof CraftInventory) {
|
||||||
|
inv = ((CraftInventory) inventory).getInventory();
|
||||||
|
} else {
|
||||||
|
inv = InternalAccessor.grabFieldOfTypeFromObject(IInventory.class, inventory);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (inv instanceof SpecialEnderChest) {
|
||||||
|
return (SpecialEnderChest) inv;
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@@ -33,25 +33,40 @@ public class PlayerDataManager implements IPlayerDataManager {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Player loadPlayer(OfflinePlayer offline) {
|
public Player loadPlayer(OfflinePlayer offline) {
|
||||||
|
// Ensure the player has data
|
||||||
|
if (offline == null || !offline.hasPlayedBefore()) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
MinecraftServer server = ((CraftServer) Bukkit.getServer()).getServer();
|
MinecraftServer server = ((CraftServer) Bukkit.getServer()).getServer();
|
||||||
|
|
||||||
// Create an entity to load the player data
|
// Create an entity to load the player data
|
||||||
EntityPlayer entity = new EntityPlayer(server, server.getWorldServer(0), offline.getName(), new ItemInWorldManager(server.getWorldServer(0)));
|
EntityPlayer entity = new EntityPlayer(server, server.getWorldServer(0), offline.getName(),
|
||||||
|
new ItemInWorldManager(server.getWorldServer(0)));
|
||||||
|
|
||||||
// Get the bukkit entity
|
// Get the bukkit entity
|
||||||
Player target = (entity == null) ? null : entity.getBukkitEntity();
|
Player target = (entity == null) ? null : entity.getBukkitEntity();
|
||||||
if (target != null) {
|
if (target != null) {
|
||||||
// Load data
|
// Load data
|
||||||
target.loadData();
|
target.loadData();
|
||||||
|
}
|
||||||
// Return the entity
|
// Return the entity
|
||||||
return target;
|
return target;
|
||||||
}
|
}
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getPlayerDataID(OfflinePlayer player) {
|
public String getPlayerDataID(OfflinePlayer player) {
|
||||||
return player.getName();
|
return player.getName();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public OfflinePlayer getPlayerByID(String identifier) {
|
||||||
|
OfflinePlayer player = Bukkit.getOfflinePlayer(identifier);
|
||||||
|
// Ensure player is a real player, otherwise return null
|
||||||
|
if (player == null || !player.hasPlayedBefore() && !player.isOnline()) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
return player;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
@@ -20,16 +20,15 @@ package com.lishid.openinv.internal.v1_4_5;
|
|||||||
import net.minecraft.server.v1_4_5.ContainerChest;
|
import net.minecraft.server.v1_4_5.ContainerChest;
|
||||||
import net.minecraft.server.v1_4_5.EntityHuman;
|
import net.minecraft.server.v1_4_5.EntityHuman;
|
||||||
import net.minecraft.server.v1_4_5.IInventory;
|
import net.minecraft.server.v1_4_5.IInventory;
|
||||||
|
import net.minecraft.server.v1_4_5.ItemStack;
|
||||||
import net.minecraft.server.v1_4_5.PlayerInventory;
|
import net.minecraft.server.v1_4_5.PlayerInventory;
|
||||||
|
|
||||||
public class SilentContainerChest extends ContainerChest {
|
public class SilentContainerChest extends ContainerChest {
|
||||||
public IInventory inv;
|
|
||||||
|
|
||||||
public SilentContainerChest(IInventory i1, IInventory i2) {
|
public SilentContainerChest(IInventory i1, IInventory i2) {
|
||||||
super(i1, i2);
|
super(i1, i2);
|
||||||
inv = i2;
|
// Send close signal
|
||||||
// close signal
|
i2.f();
|
||||||
inv.f();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -38,8 +37,10 @@ public class SilentContainerChest extends ContainerChest {
|
|||||||
PlayerInventory playerinventory = entityHuman.inventory;
|
PlayerInventory playerinventory = entityHuman.inventory;
|
||||||
|
|
||||||
if (playerinventory.getCarried() != null) {
|
if (playerinventory.getCarried() != null) {
|
||||||
entityHuman.drop(playerinventory.getCarried());
|
ItemStack carried = playerinventory.getCarried();
|
||||||
playerinventory.setCarried(null);
|
playerinventory.setCarried(null);
|
||||||
|
entityHuman.drop(carried);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
@@ -41,13 +41,14 @@ public class SpecialEnderChest extends InventorySubcontainer implements IInvento
|
|||||||
|
|
||||||
private final InventoryEnderChest enderChest;
|
private final InventoryEnderChest enderChest;
|
||||||
private final CraftInventory inventory = new CraftInventory(this);
|
private final CraftInventory inventory = new CraftInventory(this);
|
||||||
public List<HumanEntity> transaction = new ArrayList<HumanEntity>();
|
private final List<HumanEntity> transaction = new ArrayList<HumanEntity>();
|
||||||
public boolean playerOnline = false;
|
private boolean playerOnline = false;
|
||||||
private CraftPlayer owner;
|
private CraftPlayer owner;
|
||||||
private int maxStack = MAX_STACK;
|
private int maxStack = MAX_STACK;
|
||||||
|
|
||||||
public SpecialEnderChest(Player p, Boolean online) {
|
public SpecialEnderChest(Player p, Boolean online) {
|
||||||
super(((CraftPlayer) p).getHandle().getEnderChest().getName(), ((CraftPlayer) p).getHandle().getEnderChest().getSize());
|
super(((CraftPlayer) p).getHandle().getEnderChest().getName(),
|
||||||
|
((CraftPlayer) p).getHandle().getEnderChest().getSize());
|
||||||
CraftPlayer player = (CraftPlayer) p;
|
CraftPlayer player = (CraftPlayer) p;
|
||||||
this.enderChest = player.getHandle().getEnderChest();
|
this.enderChest = player.getHandle().getEnderChest();
|
||||||
this.owner = player;
|
this.owner = player;
|
||||||
@@ -68,8 +69,7 @@ public class SpecialEnderChest extends InventorySubcontainer implements IInvento
|
|||||||
Field field = playerEnderChest.getClass().getField("items");
|
Field field = playerEnderChest.getClass().getField("items");
|
||||||
field.setAccessible(true);
|
field.setAccessible(true);
|
||||||
field.set(playerEnderChest, this.items);
|
field.set(playerEnderChest, this.items);
|
||||||
}
|
} catch (Exception e) {}
|
||||||
catch (Exception e) {}
|
|
||||||
playerOnline = true;
|
playerOnline = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
@@ -4,22 +4,17 @@
|
|||||||
|
|
||||||
<parent>
|
<parent>
|
||||||
<groupId>com.lishid</groupId>
|
<groupId>com.lishid</groupId>
|
||||||
<artifactId>openinvparent</artifactId>
|
<artifactId>openinvinternal</artifactId>
|
||||||
<version>1.0-SNAPSHOT</version>
|
<version>1.0-SNAPSHOT</version>
|
||||||
</parent>
|
</parent>
|
||||||
|
|
||||||
<artifactId>OpenInvCraftbukkit1_4_6</artifactId>
|
<artifactId>openinvadapter1_4_6</artifactId>
|
||||||
<name>OpenInvCraftbukkit1_4_6</name>
|
<name>OpenInvAdapter1_4_6</name>
|
||||||
|
|
||||||
<dependencies>
|
<dependencies>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>com.lishid</groupId>
|
<groupId>com.lishid</groupId>
|
||||||
<artifactId>openinvcore</artifactId>
|
<artifactId>openinvcommon</artifactId>
|
||||||
<version>1.0-SNAPSHOT</version>
|
|
||||||
</dependency>
|
|
||||||
<dependency>
|
|
||||||
<groupId>com.lishid</groupId>
|
|
||||||
<artifactId>openinvplugin</artifactId>
|
|
||||||
<version>1.0-SNAPSHOT</version>
|
<version>1.0-SNAPSHOT</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
@@ -29,4 +24,5 @@
|
|||||||
<scope>provided</scope>
|
<scope>provided</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
</dependencies>
|
</dependencies>
|
||||||
|
|
||||||
</project>
|
</project>
|
@@ -0,0 +1,158 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (C) 2011-2014 lishid. All rights reserved.
|
||||||
|
*
|
||||||
|
* This program is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation, version 3.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package com.lishid.openinv.internal.v1_4_6;
|
||||||
|
|
||||||
|
import com.lishid.openinv.internal.IAnySilentContainer;
|
||||||
|
|
||||||
|
import org.bukkit.ChatColor;
|
||||||
|
import org.bukkit.Material;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
|
// Volatile
|
||||||
|
import net.minecraft.server.v1_4_6.AxisAlignedBB;
|
||||||
|
import net.minecraft.server.v1_4_6.BlockEnderChest;
|
||||||
|
import net.minecraft.server.v1_4_6.EntityOcelot;
|
||||||
|
import net.minecraft.server.v1_4_6.EntityPlayer;
|
||||||
|
import net.minecraft.server.v1_4_6.IInventory;
|
||||||
|
import net.minecraft.server.v1_4_6.InventoryEnderChest;
|
||||||
|
import net.minecraft.server.v1_4_6.InventoryLargeChest;
|
||||||
|
import net.minecraft.server.v1_4_6.Packet100OpenWindow;
|
||||||
|
import net.minecraft.server.v1_4_6.TileEntityChest;
|
||||||
|
import net.minecraft.server.v1_4_6.TileEntityEnderChest;
|
||||||
|
import net.minecraft.server.v1_4_6.World;
|
||||||
|
|
||||||
|
import org.bukkit.craftbukkit.v1_4_6.entity.CraftPlayer;
|
||||||
|
|
||||||
|
public class AnySilentContainer implements IAnySilentContainer {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isAnySilentContainer(org.bukkit.block.Block block) {
|
||||||
|
return block.getType() == Material.ENDER_CHEST || block.getState() instanceof org.bukkit.block.Chest;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isAnyContainerNeeded(Player p, org.bukkit.block.Block block) {
|
||||||
|
// FOR REFERENCE, LOOK AT net.minecraft.server.BlockChest
|
||||||
|
EntityPlayer player = ((CraftPlayer) p).getHandle();
|
||||||
|
World world = player.world;
|
||||||
|
|
||||||
|
if (block instanceof BlockEnderChest) {
|
||||||
|
// Ender chests are not blocked by ocelots.
|
||||||
|
return world.t(block.getX(), block.getY() + 1, block.getZ());
|
||||||
|
}
|
||||||
|
|
||||||
|
// If block or ocelot on top
|
||||||
|
if (isBlockedChest(world, block.getX(), block.getY() + 1, block.getZ())) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
int id = world.getTypeId(block.getX(), block.getY(), block.getZ());
|
||||||
|
|
||||||
|
// If block next to chest is chest and has a block or ocelot on top
|
||||||
|
if (world.getTypeId(block.getX(), block.getY(), block.getZ() + 1) == id) {
|
||||||
|
return isBlockedChest(world, block.getX(), block.getY() + 1, block.getZ() + 1);
|
||||||
|
} else if(world.getTypeId(block.getX(), block.getY(), block.getZ() - 1) == id) {
|
||||||
|
return isBlockedChest(world, block.getX(), block.getY() + 1, block.getZ() - 1);
|
||||||
|
} else if (world.getTypeId(block.getX() + 1, block.getY(), block.getZ()) == id) {
|
||||||
|
return isBlockedChest(world, block.getX() + 1, block.getY() + 1, block.getZ());
|
||||||
|
} else if (world.getTypeId(block.getX() - 1, block.getY(), block.getZ()) == id) {
|
||||||
|
return isBlockedChest(world, block.getX() - 1, block.getY() + 1, block.getZ());
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
private boolean isBlockedChest(World world, int x, int y, int z) {
|
||||||
|
return world.t(x, y + 1, z) || hasOcelotOnTop(world, x, y, z);
|
||||||
|
}
|
||||||
|
|
||||||
|
private boolean hasOcelotOnTop(World world, int x, int y, int z) {
|
||||||
|
for (Object localEntity : world.a(EntityOcelot.class,
|
||||||
|
AxisAlignedBB.a(x, y + 1, z, x + 1, y + 2, z + 1))) {
|
||||||
|
EntityOcelot localEntityOcelot = (EntityOcelot) localEntity;
|
||||||
|
if (localEntityOcelot.isSitting()) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean activateContainer(Player p, boolean silentchest, org.bukkit.block.Block block) {
|
||||||
|
|
||||||
|
EntityPlayer player = ((CraftPlayer) p).getHandle();
|
||||||
|
|
||||||
|
// Silent ender chest is API-only
|
||||||
|
if (silentchest && block.getType() == Material.ENDER_CHEST) {
|
||||||
|
p.openInventory(p.getEnderChest());
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
World world = player.world;
|
||||||
|
Object tile = world.getTileEntity(block.getX(), block.getY(), block.getZ());
|
||||||
|
|
||||||
|
if (tile == null) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (tile instanceof TileEntityEnderChest) {
|
||||||
|
// Anychest ender chest. See net.minecraft.server.BlockEnderChest
|
||||||
|
InventoryEnderChest enderChest = player.getEnderChest();
|
||||||
|
enderChest.a((TileEntityEnderChest) tile);
|
||||||
|
player.openContainer(enderChest);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!(tile instanceof IInventory)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
int id = world.getTypeId(block.getX(), block.getY(), block.getZ());
|
||||||
|
|
||||||
|
if (world.getTypeId(block.getX(), block.getY(), block.getZ() + 1) == id) {
|
||||||
|
tile = new InventoryLargeChest("Large chest", (IInventory) tile, (TileEntityChest) world.getTileEntity(block.getX(), block.getY(), block.getZ() + 1));
|
||||||
|
} else if (world.getTypeId(block.getX(), block.getY(), block.getZ() - 1) == id) {
|
||||||
|
tile = new InventoryLargeChest("Large chest", (TileEntityChest) world.getTileEntity(block.getX(), block.getY(), block.getZ() - 1), (IInventory) tile);
|
||||||
|
} else if (world.getTypeId(block.getX() + 1, block.getY(), block.getZ()) == id) {
|
||||||
|
tile = new InventoryLargeChest("Large chest", (IInventory) tile, (TileEntityChest) world.getTileEntity(block.getX() + 1, block.getY(), block.getZ()));
|
||||||
|
} else if (world.getTypeId(block.getX() - 1, block.getY(), block.getZ()) == id) {
|
||||||
|
tile = new InventoryLargeChest("Large chest", (TileEntityChest) world.getTileEntity(block.getX() - 1, block.getY(), block.getZ()), (IInventory) tile);
|
||||||
|
}
|
||||||
|
|
||||||
|
boolean returnValue = false;
|
||||||
|
if (!silentchest) {
|
||||||
|
player.openContainer((IInventory) tile);
|
||||||
|
returnValue = true;
|
||||||
|
} else {
|
||||||
|
try {
|
||||||
|
int windowId = player.nextContainerCounter();
|
||||||
|
player.playerConnection.sendPacket(new Packet100OpenWindow(windowId, 0, ((IInventory) tile).getName(), ((IInventory) tile).getSize()));
|
||||||
|
player.activeContainer = new SilentContainerChest(player.inventory, ((IInventory) tile));
|
||||||
|
player.activeContainer.windowId = windowId;
|
||||||
|
player.activeContainer.addSlotListener(player);
|
||||||
|
returnValue = true;
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
p.sendMessage(ChatColor.RED + "Error while sending silent chest.");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return returnValue;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@@ -0,0 +1,79 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (C) 2011-2014 lishid. All rights reserved.
|
||||||
|
*
|
||||||
|
* This program is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation, version 3.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package com.lishid.openinv.internal.v1_4_6;
|
||||||
|
|
||||||
|
import com.lishid.openinv.internal.IInventoryAccess;
|
||||||
|
import com.lishid.openinv.internal.ISpecialEnderChest;
|
||||||
|
import com.lishid.openinv.internal.ISpecialPlayerInventory;
|
||||||
|
import com.lishid.openinv.util.InternalAccessor;
|
||||||
|
|
||||||
|
import org.bukkit.inventory.Inventory;
|
||||||
|
|
||||||
|
// Volatile
|
||||||
|
import net.minecraft.server.v1_4_6.IInventory;
|
||||||
|
|
||||||
|
import org.bukkit.craftbukkit.v1_4_6.inventory.CraftInventory;
|
||||||
|
|
||||||
|
public class InventoryAccess implements IInventoryAccess {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isSpecialPlayerInventory(Inventory inventory) {
|
||||||
|
if (inventory instanceof CraftInventory) {
|
||||||
|
return ((CraftInventory) inventory).getInventory() instanceof ISpecialPlayerInventory;
|
||||||
|
}
|
||||||
|
return InternalAccessor.grabFieldOfTypeFromObject(IInventory.class, inventory) instanceof ISpecialPlayerInventory;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public ISpecialPlayerInventory getSpecialPlayerInventory(Inventory inventory) {
|
||||||
|
IInventory inv;
|
||||||
|
if (inventory instanceof CraftInventory) {
|
||||||
|
inv = ((CraftInventory) inventory).getInventory();
|
||||||
|
} else {
|
||||||
|
inv = InternalAccessor.grabFieldOfTypeFromObject(IInventory.class, inventory);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (inv instanceof SpecialPlayerInventory) {
|
||||||
|
return (SpecialPlayerInventory) inv;
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isSpecialEnderChest(Inventory inventory) {
|
||||||
|
if (inventory instanceof CraftInventory) {
|
||||||
|
return ((CraftInventory) inventory).getInventory() instanceof ISpecialEnderChest;
|
||||||
|
}
|
||||||
|
return InternalAccessor.grabFieldOfTypeFromObject(IInventory.class, inventory) instanceof ISpecialEnderChest;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public ISpecialEnderChest getSpecialEnderChest(Inventory inventory) {
|
||||||
|
IInventory inv;
|
||||||
|
if (inventory instanceof CraftInventory) {
|
||||||
|
inv = ((CraftInventory) inventory).getInventory();
|
||||||
|
} else {
|
||||||
|
inv = InternalAccessor.grabFieldOfTypeFromObject(IInventory.class, inventory);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (inv instanceof SpecialEnderChest) {
|
||||||
|
return (SpecialEnderChest) inv;
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@@ -33,25 +33,40 @@ public class PlayerDataManager implements IPlayerDataManager {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Player loadPlayer(OfflinePlayer offline) {
|
public Player loadPlayer(OfflinePlayer offline) {
|
||||||
|
// Ensure the player has data
|
||||||
|
if (offline == null || !offline.hasPlayedBefore()) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
MinecraftServer server = ((CraftServer) Bukkit.getServer()).getServer();
|
MinecraftServer server = ((CraftServer) Bukkit.getServer()).getServer();
|
||||||
|
|
||||||
// Create an entity to load the player data
|
// Create an entity to load the player data
|
||||||
EntityPlayer entity = new EntityPlayer(server, server.getWorldServer(0), offline.getName(), new PlayerInteractManager(server.getWorldServer(0)));
|
EntityPlayer entity = new EntityPlayer(server, server.getWorldServer(0), offline.getName(),
|
||||||
|
new PlayerInteractManager(server.getWorldServer(0)));
|
||||||
|
|
||||||
// Get the bukkit entity
|
// Get the bukkit entity
|
||||||
Player target = (entity == null) ? null : entity.getBukkitEntity();
|
Player target = (entity == null) ? null : entity.getBukkitEntity();
|
||||||
if (target != null) {
|
if (target != null) {
|
||||||
// Load data
|
// Load data
|
||||||
target.loadData();
|
target.loadData();
|
||||||
|
}
|
||||||
// Return the entity
|
// Return the entity
|
||||||
return target;
|
return target;
|
||||||
}
|
}
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getPlayerDataID(OfflinePlayer player) {
|
public String getPlayerDataID(OfflinePlayer player) {
|
||||||
return player.getName();
|
return player.getName();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public OfflinePlayer getPlayerByID(String identifier) {
|
||||||
|
OfflinePlayer player = Bukkit.getOfflinePlayer(identifier);
|
||||||
|
// Ensure player is a real player, otherwise return null
|
||||||
|
if (player == null || !player.hasPlayedBefore() && !player.isOnline()) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
return player;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
@@ -20,16 +20,15 @@ package com.lishid.openinv.internal.v1_4_6;
|
|||||||
import net.minecraft.server.v1_4_6.ContainerChest;
|
import net.minecraft.server.v1_4_6.ContainerChest;
|
||||||
import net.minecraft.server.v1_4_6.EntityHuman;
|
import net.minecraft.server.v1_4_6.EntityHuman;
|
||||||
import net.minecraft.server.v1_4_6.IInventory;
|
import net.minecraft.server.v1_4_6.IInventory;
|
||||||
|
import net.minecraft.server.v1_4_6.ItemStack;
|
||||||
import net.minecraft.server.v1_4_6.PlayerInventory;
|
import net.minecraft.server.v1_4_6.PlayerInventory;
|
||||||
|
|
||||||
public class SilentContainerChest extends ContainerChest {
|
public class SilentContainerChest extends ContainerChest {
|
||||||
public IInventory inv;
|
|
||||||
|
|
||||||
public SilentContainerChest(IInventory i1, IInventory i2) {
|
public SilentContainerChest(IInventory i1, IInventory i2) {
|
||||||
super(i1, i2);
|
super(i1, i2);
|
||||||
inv = i2;
|
// Send close signal
|
||||||
// close signal
|
i2.f();
|
||||||
inv.f();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -38,8 +37,10 @@ public class SilentContainerChest extends ContainerChest {
|
|||||||
PlayerInventory playerinventory = entityHuman.inventory;
|
PlayerInventory playerinventory = entityHuman.inventory;
|
||||||
|
|
||||||
if (playerinventory.getCarried() != null) {
|
if (playerinventory.getCarried() != null) {
|
||||||
entityHuman.drop(playerinventory.getCarried());
|
ItemStack carried = playerinventory.getCarried();
|
||||||
playerinventory.setCarried(null);
|
playerinventory.setCarried(null);
|
||||||
|
entityHuman.drop(carried);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
@@ -41,13 +41,14 @@ public class SpecialEnderChest extends InventorySubcontainer implements IInvento
|
|||||||
|
|
||||||
private final InventoryEnderChest enderChest;
|
private final InventoryEnderChest enderChest;
|
||||||
private final CraftInventory inventory = new CraftInventory(this);
|
private final CraftInventory inventory = new CraftInventory(this);
|
||||||
public List<HumanEntity> transaction = new ArrayList<HumanEntity>();
|
private final List<HumanEntity> transaction = new ArrayList<HumanEntity>();
|
||||||
public boolean playerOnline = false;
|
private boolean playerOnline = false;
|
||||||
private CraftPlayer owner;
|
private CraftPlayer owner;
|
||||||
private int maxStack = MAX_STACK;
|
private int maxStack = MAX_STACK;
|
||||||
|
|
||||||
public SpecialEnderChest(Player p, Boolean online) {
|
public SpecialEnderChest(Player p, Boolean online) {
|
||||||
super(((CraftPlayer) p).getHandle().getEnderChest().getName(), ((CraftPlayer) p).getHandle().getEnderChest().getSize());
|
super(((CraftPlayer) p).getHandle().getEnderChest().getName(),
|
||||||
|
((CraftPlayer) p).getHandle().getEnderChest().getSize());
|
||||||
CraftPlayer player = (CraftPlayer) p;
|
CraftPlayer player = (CraftPlayer) p;
|
||||||
this.enderChest = player.getHandle().getEnderChest();
|
this.enderChest = player.getHandle().getEnderChest();
|
||||||
this.owner = player;
|
this.owner = player;
|
||||||
@@ -68,8 +69,7 @@ public class SpecialEnderChest extends InventorySubcontainer implements IInvento
|
|||||||
Field field = playerEnderChest.getClass().getField("items");
|
Field field = playerEnderChest.getClass().getField("items");
|
||||||
field.setAccessible(true);
|
field.setAccessible(true);
|
||||||
field.set(playerEnderChest, this.items);
|
field.set(playerEnderChest, this.items);
|
||||||
}
|
} catch (Exception e) {}
|
||||||
catch (Exception e) {}
|
|
||||||
playerOnline = true;
|
playerOnline = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
@@ -86,16 +86,14 @@ public class SpecialPlayerInventory extends PlayerInventory implements ISpecialP
|
|||||||
if (i >= is.length) {
|
if (i >= is.length) {
|
||||||
i -= is.length;
|
i -= is.length;
|
||||||
is = this.armor;
|
is = this.armor;
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
i = getReversedItemSlotNum(i);
|
i = getReversedItemSlotNum(i);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (i >= is.length) {
|
if (i >= is.length) {
|
||||||
i -= is.length;
|
i -= is.length;
|
||||||
is = this.extra;
|
is = this.extra;
|
||||||
}
|
} else if (is == this.armor) {
|
||||||
else if (is == this.armor) {
|
|
||||||
i = getReversedArmorSlotNum(i);
|
i = getReversedArmorSlotNum(i);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -109,16 +107,14 @@ public class SpecialPlayerInventory extends PlayerInventory implements ISpecialP
|
|||||||
if (i >= is.length) {
|
if (i >= is.length) {
|
||||||
i -= is.length;
|
i -= is.length;
|
||||||
is = this.armor;
|
is = this.armor;
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
i = getReversedItemSlotNum(i);
|
i = getReversedItemSlotNum(i);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (i >= is.length) {
|
if (i >= is.length) {
|
||||||
i -= is.length;
|
i -= is.length;
|
||||||
is = this.extra;
|
is = this.extra;
|
||||||
}
|
} else if (is == this.armor) {
|
||||||
else if (is == this.armor) {
|
|
||||||
i = getReversedArmorSlotNum(i);
|
i = getReversedArmorSlotNum(i);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -129,8 +125,7 @@ public class SpecialPlayerInventory extends PlayerInventory implements ISpecialP
|
|||||||
itemstack = is[i];
|
itemstack = is[i];
|
||||||
is[i] = null;
|
is[i] = null;
|
||||||
return itemstack;
|
return itemstack;
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
itemstack = is[i].a(j);
|
itemstack = is[i].a(j);
|
||||||
if (is[i].count == 0) {
|
if (is[i].count == 0) {
|
||||||
is[i] = null;
|
is[i] = null;
|
||||||
@@ -139,10 +134,9 @@ public class SpecialPlayerInventory extends PlayerInventory implements ISpecialP
|
|||||||
return itemstack;
|
return itemstack;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else {
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ItemStack splitWithoutUpdate(int i) {
|
public ItemStack splitWithoutUpdate(int i) {
|
||||||
@@ -151,16 +145,14 @@ public class SpecialPlayerInventory extends PlayerInventory implements ISpecialP
|
|||||||
if (i >= is.length) {
|
if (i >= is.length) {
|
||||||
i -= is.length;
|
i -= is.length;
|
||||||
is = this.armor;
|
is = this.armor;
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
i = getReversedItemSlotNum(i);
|
i = getReversedItemSlotNum(i);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (i >= is.length) {
|
if (i >= is.length) {
|
||||||
i -= is.length;
|
i -= is.length;
|
||||||
is = this.extra;
|
is = this.extra;
|
||||||
}
|
} else if (is == this.armor) {
|
||||||
else if (is == this.armor) {
|
|
||||||
i = getReversedArmorSlotNum(i);
|
i = getReversedArmorSlotNum(i);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -170,10 +162,9 @@ public class SpecialPlayerInventory extends PlayerInventory implements ISpecialP
|
|||||||
is[i] = null;
|
is[i] = null;
|
||||||
return itemstack;
|
return itemstack;
|
||||||
}
|
}
|
||||||
else {
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void setItem(int i, ItemStack itemstack) {
|
public void setItem(int i, ItemStack itemstack) {
|
||||||
@@ -182,16 +173,14 @@ public class SpecialPlayerInventory extends PlayerInventory implements ISpecialP
|
|||||||
if (i >= is.length) {
|
if (i >= is.length) {
|
||||||
i -= is.length;
|
i -= is.length;
|
||||||
is = this.armor;
|
is = this.armor;
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
i = getReversedItemSlotNum(i);
|
i = getReversedItemSlotNum(i);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (i >= is.length) {
|
if (i >= is.length) {
|
||||||
i -= is.length;
|
i -= is.length;
|
||||||
is = this.extra;
|
is = this.extra;
|
||||||
}
|
} else if (is == this.armor) {
|
||||||
else if (is == this.armor) {
|
|
||||||
i = getReversedArmorSlotNum(i);
|
i = getReversedArmorSlotNum(i);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -207,22 +196,25 @@ public class SpecialPlayerInventory extends PlayerInventory implements ISpecialP
|
|||||||
}
|
}
|
||||||
|
|
||||||
private int getReversedItemSlotNum(int i) {
|
private int getReversedItemSlotNum(int i) {
|
||||||
if (i >= 27)
|
if (i >= 27) {
|
||||||
return i - 27;
|
return i - 27;
|
||||||
else
|
}
|
||||||
return i + 9;
|
return i + 9;
|
||||||
}
|
}
|
||||||
|
|
||||||
private int getReversedArmorSlotNum(int i) {
|
private int getReversedArmorSlotNum(int i) {
|
||||||
if (i == 0)
|
if (i == 0) {
|
||||||
return 3;
|
return 3;
|
||||||
if (i == 1)
|
}
|
||||||
|
if (i == 1) {
|
||||||
return 2;
|
return 2;
|
||||||
if (i == 2)
|
}
|
||||||
|
if (i == 2) {
|
||||||
return 1;
|
return 1;
|
||||||
if (i == 3)
|
}
|
||||||
|
if (i == 3) {
|
||||||
return 0;
|
return 0;
|
||||||
else
|
}
|
||||||
return i;
|
return i;
|
||||||
}
|
}
|
||||||
|
|
68
internal/pom.xml
Normal file
68
internal/pom.xml
Normal file
@@ -0,0 +1,68 @@
|
|||||||
|
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||||
|
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||||
|
<modelVersion>4.0.0</modelVersion>
|
||||||
|
|
||||||
|
<parent>
|
||||||
|
<groupId>com.lishid</groupId>
|
||||||
|
<artifactId>openinvparent</artifactId>
|
||||||
|
<version>1.0-SNAPSHOT</version>
|
||||||
|
</parent>
|
||||||
|
|
||||||
|
<artifactId>openinvinternal</artifactId>
|
||||||
|
<name>OpenInvInternal</name>
|
||||||
|
|
||||||
|
<packaging>pom</packaging>
|
||||||
|
|
||||||
|
<profiles>
|
||||||
|
|
||||||
|
<profile>
|
||||||
|
<id>latest</id>
|
||||||
|
<modules>
|
||||||
|
<module>v1_11_R1</module>
|
||||||
|
</modules>
|
||||||
|
</profile>
|
||||||
|
|
||||||
|
<profile>
|
||||||
|
<id>modern</id>
|
||||||
|
<modules>
|
||||||
|
<module>v1_8_R1</module>
|
||||||
|
<module>v1_8_R2</module>
|
||||||
|
<module>v1_8_R3</module>
|
||||||
|
<module>v1_9_R1</module>
|
||||||
|
<module>v1_9_R2</module>
|
||||||
|
<module>v1_10_R1</module>
|
||||||
|
<module>v1_11_R1</module>
|
||||||
|
</modules>
|
||||||
|
</profile>
|
||||||
|
|
||||||
|
<profile>
|
||||||
|
<id>all</id>
|
||||||
|
<modules>
|
||||||
|
<module>1_4_5</module>
|
||||||
|
<module>1_4_6</module>
|
||||||
|
<module>v1_4_R1</module>
|
||||||
|
<!-- 1_5_R1 was never released -->
|
||||||
|
<module>v1_5_R2</module>
|
||||||
|
<module>v1_5_R3</module>
|
||||||
|
<!-- 1_6_R1 also had no tagged releases, remove? -->
|
||||||
|
<module>v1_6_R1</module>
|
||||||
|
<module>v1_6_R2</module>
|
||||||
|
<module>v1_6_R3</module>
|
||||||
|
<!-- TODO: Recompile CB for 1_7_R1 through 1_7_R4, currently using whatever jars worked -->
|
||||||
|
<module>v1_7_R1</module>
|
||||||
|
<module>v1_7_R2</module>
|
||||||
|
<module>v1_7_R3</module>
|
||||||
|
<module>v1_7_R4</module>
|
||||||
|
<module>v1_8_R1</module>
|
||||||
|
<module>v1_8_R2</module>
|
||||||
|
<module>v1_8_R3</module>
|
||||||
|
<module>v1_9_R1</module>
|
||||||
|
<module>v1_9_R2</module>
|
||||||
|
<module>v1_10_R1</module>
|
||||||
|
<module>v1_11_R1</module>
|
||||||
|
</modules>
|
||||||
|
</profile>
|
||||||
|
|
||||||
|
</profiles>
|
||||||
|
|
||||||
|
</project>
|
@@ -4,22 +4,17 @@
|
|||||||
|
|
||||||
<parent>
|
<parent>
|
||||||
<groupId>com.lishid</groupId>
|
<groupId>com.lishid</groupId>
|
||||||
<artifactId>openinvparent</artifactId>
|
<artifactId>openinvinternal</artifactId>
|
||||||
<version>1.0-SNAPSHOT</version>
|
<version>1.0-SNAPSHOT</version>
|
||||||
</parent>
|
</parent>
|
||||||
|
|
||||||
<artifactId>OpenInvCraftbukkit1_10_R1</artifactId>
|
<artifactId>openinvadapter1_10_R1</artifactId>
|
||||||
<name>OpenInvCraftbukkit1_10_R1</name>
|
<name>OpenInvAdapter1_10_R1</name>
|
||||||
|
|
||||||
<dependencies>
|
<dependencies>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>com.lishid</groupId>
|
<groupId>com.lishid</groupId>
|
||||||
<artifactId>openinvcore</artifactId>
|
<artifactId>openinvcommon</artifactId>
|
||||||
<version>1.0-SNAPSHOT</version>
|
|
||||||
</dependency>
|
|
||||||
<dependency>
|
|
||||||
<groupId>com.lishid</groupId>
|
|
||||||
<artifactId>openinvplugin</artifactId>
|
|
||||||
<version>1.0-SNAPSHOT</version>
|
<version>1.0-SNAPSHOT</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
@@ -29,4 +24,5 @@
|
|||||||
<scope>provided</scope>
|
<scope>provided</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
</dependencies>
|
</dependencies>
|
||||||
|
|
||||||
</project>
|
</project>
|
@@ -0,0 +1,209 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (C) 2011-2014 lishid. All rights reserved.
|
||||||
|
*
|
||||||
|
* This program is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation, version 3.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package com.lishid.openinv.internal.v1_10_R1;
|
||||||
|
|
||||||
|
import com.lishid.openinv.internal.IAnySilentContainer;
|
||||||
|
|
||||||
|
import org.bukkit.ChatColor;
|
||||||
|
import org.bukkit.Material;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
|
// Volatile
|
||||||
|
import net.minecraft.server.v1_10_R1.AxisAlignedBB;
|
||||||
|
import net.minecraft.server.v1_10_R1.Block;
|
||||||
|
import net.minecraft.server.v1_10_R1.BlockChest;
|
||||||
|
import net.minecraft.server.v1_10_R1.BlockChest.Type;
|
||||||
|
import net.minecraft.server.v1_10_R1.BlockEnderChest;
|
||||||
|
import net.minecraft.server.v1_10_R1.BlockPosition;
|
||||||
|
import net.minecraft.server.v1_10_R1.Container;
|
||||||
|
import net.minecraft.server.v1_10_R1.Entity;
|
||||||
|
import net.minecraft.server.v1_10_R1.EntityOcelot;
|
||||||
|
import net.minecraft.server.v1_10_R1.EntityPlayer;
|
||||||
|
import net.minecraft.server.v1_10_R1.EnumDirection;
|
||||||
|
import net.minecraft.server.v1_10_R1.IInventory;
|
||||||
|
import net.minecraft.server.v1_10_R1.ITileInventory;
|
||||||
|
import net.minecraft.server.v1_10_R1.InventoryEnderChest;
|
||||||
|
import net.minecraft.server.v1_10_R1.InventoryLargeChest;
|
||||||
|
import net.minecraft.server.v1_10_R1.PacketPlayOutOpenWindow;
|
||||||
|
import net.minecraft.server.v1_10_R1.StatisticList;
|
||||||
|
import net.minecraft.server.v1_10_R1.TileEntity;
|
||||||
|
import net.minecraft.server.v1_10_R1.TileEntityChest;
|
||||||
|
import net.minecraft.server.v1_10_R1.TileEntityEnderChest;
|
||||||
|
import net.minecraft.server.v1_10_R1.World;
|
||||||
|
|
||||||
|
import org.bukkit.craftbukkit.v1_10_R1.entity.CraftPlayer;
|
||||||
|
|
||||||
|
public class AnySilentContainer implements IAnySilentContainer {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isAnySilentContainer(org.bukkit.block.Block block) {
|
||||||
|
return block.getType() == Material.ENDER_CHEST || block.getState() instanceof org.bukkit.block.Chest;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isAnyContainerNeeded(Player p, org.bukkit.block.Block b) {
|
||||||
|
EntityPlayer player = ((CraftPlayer) p).getHandle();
|
||||||
|
World world = player.world;
|
||||||
|
BlockPosition blockPosition = new BlockPosition(b.getX(), b.getY(), b.getZ());
|
||||||
|
Block block = world.getType(blockPosition).getBlock();
|
||||||
|
|
||||||
|
if (block instanceof BlockEnderChest) {
|
||||||
|
// Ender chests are not blocked by ocelots.
|
||||||
|
return world.getType(blockPosition.up()).m();
|
||||||
|
}
|
||||||
|
|
||||||
|
// Check if chest is blocked or has an ocelot on top
|
||||||
|
if (isBlockedChest(world, blockPosition)) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Check for matching adjacent chests that are blocked or have an ocelot on top
|
||||||
|
for (EnumDirection localEnumDirection : EnumDirection.EnumDirectionLimit.HORIZONTAL) {
|
||||||
|
BlockPosition localBlockPosition = blockPosition.shift(localEnumDirection);
|
||||||
|
Block localBlock = world.getType(localBlockPosition).getBlock();
|
||||||
|
|
||||||
|
if (localBlock != block) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
TileEntity localTileEntity = world.getTileEntity(localBlockPosition);
|
||||||
|
if (!(localTileEntity instanceof TileEntityChest)) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (isBlockedChest(world, localBlockPosition)) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
private boolean isBlockedChest(World world, BlockPosition blockPosition) {
|
||||||
|
// For reference, loot at net.minecraft.server.BlockChest
|
||||||
|
return world.getType(blockPosition.up()).l() || hasOcelotOnTop(world, blockPosition);
|
||||||
|
}
|
||||||
|
|
||||||
|
private boolean hasOcelotOnTop(World world, BlockPosition blockPosition) {
|
||||||
|
for (Entity localEntity : world.a(EntityOcelot.class,
|
||||||
|
new AxisAlignedBB(blockPosition.getX(), blockPosition.getY() + 1,
|
||||||
|
blockPosition.getZ(), blockPosition.getX() + 1, blockPosition.getY() + 2,
|
||||||
|
blockPosition.getZ() + 1))) {
|
||||||
|
EntityOcelot localEntityOcelot = (EntityOcelot) localEntity;
|
||||||
|
if (localEntityOcelot.isSitting()) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean activateContainer(Player p, boolean silentchest, org.bukkit.block.Block b) {
|
||||||
|
|
||||||
|
EntityPlayer player = ((CraftPlayer) p).getHandle();
|
||||||
|
|
||||||
|
// Silent ender chest is pretty much API-only
|
||||||
|
if (silentchest && b.getType() == Material.ENDER_CHEST) {
|
||||||
|
p.openInventory(p.getEnderChest());
|
||||||
|
player.b(StatisticList.X);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
World world = player.world;
|
||||||
|
BlockPosition blockPosition = new BlockPosition(b.getX(), b.getY(), b.getZ());
|
||||||
|
Object tile = world.getTileEntity(blockPosition);
|
||||||
|
|
||||||
|
if (tile == null) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (tile instanceof TileEntityEnderChest) {
|
||||||
|
// Anychest ender chest. See net.minecraft.server.BlockEnderChest
|
||||||
|
InventoryEnderChest enderChest = player.getEnderChest();
|
||||||
|
enderChest.a((TileEntityEnderChest) tile);
|
||||||
|
player.openContainer(enderChest);
|
||||||
|
player.b(StatisticList.X);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!(tile instanceof IInventory)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
Block block = world.getType(blockPosition).getBlock();
|
||||||
|
Container container = null;
|
||||||
|
|
||||||
|
if (block instanceof BlockChest) {
|
||||||
|
for (EnumDirection localEnumDirection : EnumDirection.EnumDirectionLimit.HORIZONTAL) {
|
||||||
|
BlockPosition localBlockPosition = blockPosition.shift(localEnumDirection);
|
||||||
|
Block localBlock = world.getType(localBlockPosition).getBlock();
|
||||||
|
|
||||||
|
if (localBlock != block) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
TileEntity localTileEntity = world.getTileEntity(localBlockPosition);
|
||||||
|
if (!(localTileEntity instanceof TileEntityChest)) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ((localEnumDirection == EnumDirection.WEST) || (localEnumDirection == EnumDirection.NORTH)) {
|
||||||
|
tile = new InventoryLargeChest("container.chestDouble",
|
||||||
|
(TileEntityChest) localTileEntity, (ITileInventory) tile);
|
||||||
|
} else {
|
||||||
|
tile = new InventoryLargeChest("container.chestDouble",
|
||||||
|
(ITileInventory) tile, (TileEntityChest) localTileEntity);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (silentchest) {
|
||||||
|
container = new SilentContainerChest(player.inventory, ((IInventory) tile), player);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (((BlockChest) block).g == Type.BASIC) {
|
||||||
|
player.b(StatisticList.ac);
|
||||||
|
} else if (((BlockChest) block).g == Type.TRAP) {
|
||||||
|
player.b(StatisticList.W);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
boolean returnValue = false;
|
||||||
|
final IInventory iInventory = (IInventory) tile;
|
||||||
|
|
||||||
|
if (!silentchest || container == null) {
|
||||||
|
player.openContainer(iInventory);
|
||||||
|
returnValue = true;
|
||||||
|
} else {
|
||||||
|
try {
|
||||||
|
int windowId = player.nextContainerCounter();
|
||||||
|
player.playerConnection.sendPacket(new PacketPlayOutOpenWindow(windowId, iInventory.getName(), iInventory.getScoreboardDisplayName(), iInventory.getSize()));
|
||||||
|
player.activeContainer = container;
|
||||||
|
player.activeContainer.windowId = windowId;
|
||||||
|
player.activeContainer.addSlotListener(player);
|
||||||
|
returnValue = true;
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
p.sendMessage(ChatColor.RED + "Error while sending silent chest.");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return returnValue;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@@ -0,0 +1,79 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (C) 2011-2014 lishid. All rights reserved.
|
||||||
|
*
|
||||||
|
* This program is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation, version 3.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package com.lishid.openinv.internal.v1_10_R1;
|
||||||
|
|
||||||
|
import com.lishid.openinv.internal.IInventoryAccess;
|
||||||
|
import com.lishid.openinv.internal.ISpecialEnderChest;
|
||||||
|
import com.lishid.openinv.internal.ISpecialPlayerInventory;
|
||||||
|
import com.lishid.openinv.util.InternalAccessor;
|
||||||
|
|
||||||
|
import org.bukkit.inventory.Inventory;
|
||||||
|
|
||||||
|
// Volatile
|
||||||
|
import net.minecraft.server.v1_10_R1.IInventory;
|
||||||
|
|
||||||
|
import org.bukkit.craftbukkit.v1_10_R1.inventory.CraftInventory;
|
||||||
|
|
||||||
|
public class InventoryAccess implements IInventoryAccess {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isSpecialPlayerInventory(Inventory inventory) {
|
||||||
|
if (inventory instanceof CraftInventory) {
|
||||||
|
return ((CraftInventory) inventory).getInventory() instanceof ISpecialPlayerInventory;
|
||||||
|
}
|
||||||
|
return InternalAccessor.grabFieldOfTypeFromObject(IInventory.class, inventory) instanceof ISpecialPlayerInventory;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public ISpecialPlayerInventory getSpecialPlayerInventory(Inventory inventory) {
|
||||||
|
IInventory inv;
|
||||||
|
if (inventory instanceof CraftInventory) {
|
||||||
|
inv = ((CraftInventory) inventory).getInventory();
|
||||||
|
} else {
|
||||||
|
inv = InternalAccessor.grabFieldOfTypeFromObject(IInventory.class, inventory);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (inv instanceof SpecialPlayerInventory) {
|
||||||
|
return (SpecialPlayerInventory) inv;
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isSpecialEnderChest(Inventory inventory) {
|
||||||
|
if (inventory instanceof CraftInventory) {
|
||||||
|
return ((CraftInventory) inventory).getInventory() instanceof ISpecialEnderChest;
|
||||||
|
}
|
||||||
|
return InternalAccessor.grabFieldOfTypeFromObject(IInventory.class, inventory) instanceof ISpecialEnderChest;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public ISpecialEnderChest getSpecialEnderChest(Inventory inventory) {
|
||||||
|
IInventory inv;
|
||||||
|
if (inventory instanceof CraftInventory) {
|
||||||
|
inv = ((CraftInventory) inventory).getInventory();
|
||||||
|
} else {
|
||||||
|
inv = InternalAccessor.grabFieldOfTypeFromObject(IInventory.class, inventory);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (inv instanceof SpecialEnderChest) {
|
||||||
|
return (SpecialEnderChest) inv;
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@@ -16,6 +16,8 @@
|
|||||||
|
|
||||||
package com.lishid.openinv.internal.v1_10_R1;
|
package com.lishid.openinv.internal.v1_10_R1;
|
||||||
|
|
||||||
|
import java.util.UUID;
|
||||||
|
|
||||||
import com.lishid.openinv.internal.IPlayerDataManager;
|
import com.lishid.openinv.internal.IPlayerDataManager;
|
||||||
|
|
||||||
import com.mojang.authlib.GameProfile;
|
import com.mojang.authlib.GameProfile;
|
||||||
@@ -35,28 +37,46 @@ public class PlayerDataManager implements IPlayerDataManager {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Player loadPlayer(OfflinePlayer offline) {
|
public Player loadPlayer(OfflinePlayer offline) {
|
||||||
|
// Ensure player has data
|
||||||
if (offline == null || !offline.hasPlayedBefore()) {
|
if (offline == null || !offline.hasPlayedBefore()) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Create a profile and entity to load the player data
|
||||||
GameProfile profile = new GameProfile(offline.getUniqueId(), offline.getName());
|
GameProfile profile = new GameProfile(offline.getUniqueId(), offline.getName());
|
||||||
MinecraftServer server = ((CraftServer) Bukkit.getServer()).getServer();
|
MinecraftServer server = ((CraftServer) Bukkit.getServer()).getServer();
|
||||||
// Create an entity to load the player data
|
EntityPlayer entity = new EntityPlayer(server, server.getWorldServer(0), profile,
|
||||||
EntityPlayer entity = new EntityPlayer(server, server.getWorldServer(0), profile, new PlayerInteractManager(server.getWorldServer(0)));
|
new PlayerInteractManager(server.getWorldServer(0)));
|
||||||
|
|
||||||
// Get the bukkit entity
|
// Get the bukkit entity
|
||||||
Player target = (entity == null) ? null : entity.getBukkitEntity();
|
Player target = (entity == null) ? null : entity.getBukkitEntity();
|
||||||
if (target != null) {
|
if (target != null) {
|
||||||
// Load data
|
// Load data
|
||||||
target.loadData();
|
target.loadData();
|
||||||
|
}
|
||||||
// Return the entity
|
// Return the entity
|
||||||
return target;
|
return target;
|
||||||
}
|
}
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getPlayerDataID(OfflinePlayer player) {
|
public String getPlayerDataID(OfflinePlayer player) {
|
||||||
return player.getUniqueId().toString();
|
return player.getUniqueId().toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public OfflinePlayer getPlayerByID(String identifier) {
|
||||||
|
try {
|
||||||
|
UUID uuid = UUID.fromString(identifier);
|
||||||
|
OfflinePlayer player = Bukkit.getOfflinePlayer(uuid);
|
||||||
|
// Ensure player is a real player, otherwise return null
|
||||||
|
if (player == null || !player.hasPlayedBefore() && !player.isOnline()) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
return player;
|
||||||
|
} catch (IllegalArgumentException e) {
|
||||||
|
// Not a UUID
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
@@ -20,16 +20,15 @@ package com.lishid.openinv.internal.v1_10_R1;
|
|||||||
import net.minecraft.server.v1_10_R1.ContainerChest;
|
import net.minecraft.server.v1_10_R1.ContainerChest;
|
||||||
import net.minecraft.server.v1_10_R1.EntityHuman;
|
import net.minecraft.server.v1_10_R1.EntityHuman;
|
||||||
import net.minecraft.server.v1_10_R1.IInventory;
|
import net.minecraft.server.v1_10_R1.IInventory;
|
||||||
|
import net.minecraft.server.v1_10_R1.ItemStack;
|
||||||
import net.minecraft.server.v1_10_R1.PlayerInventory;
|
import net.minecraft.server.v1_10_R1.PlayerInventory;
|
||||||
|
|
||||||
public class SilentContainerChest extends ContainerChest {
|
public class SilentContainerChest extends ContainerChest {
|
||||||
public IInventory inv;
|
|
||||||
|
|
||||||
public SilentContainerChest(IInventory i1, IInventory i2, EntityHuman e1) {
|
public SilentContainerChest(IInventory i1, IInventory i2, EntityHuman e1) {
|
||||||
super(i1, i2, e1);
|
super(i1, i2, e1);
|
||||||
inv = i2;
|
// Send close signal
|
||||||
// close signal
|
i2.closeContainer(e1);
|
||||||
inv.closeContainer(e1);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -38,8 +37,10 @@ public class SilentContainerChest extends ContainerChest {
|
|||||||
PlayerInventory playerinventory = entityHuman.inventory;
|
PlayerInventory playerinventory = entityHuman.inventory;
|
||||||
|
|
||||||
if (playerinventory.getCarried() != null) {
|
if (playerinventory.getCarried() != null) {
|
||||||
entityHuman.drop(playerinventory.getCarried(), false);
|
ItemStack carried = playerinventory.getCarried();
|
||||||
playerinventory.setCarried(null);
|
playerinventory.setCarried(null);
|
||||||
|
entityHuman.drop(carried, false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
@@ -37,10 +37,12 @@ public class SpecialEnderChest extends InventorySubcontainer implements IInvento
|
|||||||
|
|
||||||
private final InventoryEnderChest enderChest;
|
private final InventoryEnderChest enderChest;
|
||||||
private final CraftInventory inventory = new CraftInventory(this);
|
private final CraftInventory inventory = new CraftInventory(this);
|
||||||
public boolean playerOnline = false;
|
private boolean playerOnline = false;
|
||||||
|
|
||||||
public SpecialEnderChest(Player player, Boolean online) {
|
public SpecialEnderChest(Player player, Boolean online) {
|
||||||
super(((CraftPlayer) player).getHandle().getEnderChest().getName(), ((CraftPlayer) player).getHandle().getEnderChest().hasCustomName(), ((CraftPlayer) player).getHandle().getEnderChest().getSize());
|
super(((CraftPlayer) player).getHandle().getEnderChest().getName(),
|
||||||
|
((CraftPlayer) player).getHandle().getEnderChest().hasCustomName(),
|
||||||
|
((CraftPlayer) player).getHandle().getEnderChest().getSize());
|
||||||
CraftPlayer craftPlayer = (CraftPlayer) player;
|
CraftPlayer craftPlayer = (CraftPlayer) player;
|
||||||
this.enderChest = craftPlayer.getHandle().getEnderChest();
|
this.enderChest = craftPlayer.getHandle().getEnderChest();
|
||||||
this.bukkitOwner = craftPlayer;
|
this.bukkitOwner = craftPlayer;
|
||||||
@@ -79,8 +81,7 @@ public class SpecialEnderChest extends InventorySubcontainer implements IInvento
|
|||||||
this.bukkitOwner = player;
|
this.bukkitOwner = player;
|
||||||
CraftPlayer craftPlayer = (CraftPlayer) player;
|
CraftPlayer craftPlayer = (CraftPlayer) player;
|
||||||
setItemArrays(craftPlayer.getHandle().getEnderChest(), this.items);
|
setItemArrays(craftPlayer.getHandle().getEnderChest(), this.items);
|
||||||
}
|
} catch (Exception e) {}
|
||||||
catch (Exception e) {}
|
|
||||||
playerOnline = true;
|
playerOnline = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
@@ -126,16 +126,14 @@ public class SpecialPlayerInventory extends PlayerInventory implements ISpecialP
|
|||||||
if (i >= is.length) {
|
if (i >= is.length) {
|
||||||
i -= is.length;
|
i -= is.length;
|
||||||
is = this.armor;
|
is = this.armor;
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
i = getReversedItemSlotNum(i);
|
i = getReversedItemSlotNum(i);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (i >= is.length) {
|
if (i >= is.length) {
|
||||||
i -= is.length;
|
i -= is.length;
|
||||||
is = this.extraSlots;
|
is = this.extraSlots;
|
||||||
}
|
} else if (is == this.armor) {
|
||||||
else if (is == this.armor) {
|
|
||||||
i = getReversedArmorSlotNum(i);
|
i = getReversedArmorSlotNum(i);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -156,16 +154,14 @@ public class SpecialPlayerInventory extends PlayerInventory implements ISpecialP
|
|||||||
if (i >= is.length) {
|
if (i >= is.length) {
|
||||||
i -= is.length;
|
i -= is.length;
|
||||||
is = this.armor;
|
is = this.armor;
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
i = getReversedItemSlotNum(i);
|
i = getReversedItemSlotNum(i);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (i >= is.length) {
|
if (i >= is.length) {
|
||||||
i -= is.length;
|
i -= is.length;
|
||||||
is = this.extraSlots;
|
is = this.extraSlots;
|
||||||
}
|
} else if (is == this.armor) {
|
||||||
else if (is == this.armor) {
|
|
||||||
i = getReversedArmorSlotNum(i);
|
i = getReversedArmorSlotNum(i);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -181,8 +177,7 @@ public class SpecialPlayerInventory extends PlayerInventory implements ISpecialP
|
|||||||
itemstack = is[i];
|
itemstack = is[i];
|
||||||
is[i] = null;
|
is[i] = null;
|
||||||
return itemstack;
|
return itemstack;
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
itemstack = is[i].cloneAndSubtract(j);
|
itemstack = is[i].cloneAndSubtract(j);
|
||||||
if (is[i].count == 0) {
|
if (is[i].count == 0) {
|
||||||
is[i] = null;
|
is[i] = null;
|
||||||
@@ -191,10 +186,9 @@ public class SpecialPlayerInventory extends PlayerInventory implements ISpecialP
|
|||||||
return itemstack;
|
return itemstack;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else {
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ItemStack splitWithoutUpdate(int i) {
|
public ItemStack splitWithoutUpdate(int i) {
|
||||||
@@ -203,16 +197,14 @@ public class SpecialPlayerInventory extends PlayerInventory implements ISpecialP
|
|||||||
if (i >= is.length) {
|
if (i >= is.length) {
|
||||||
i -= is.length;
|
i -= is.length;
|
||||||
is = this.armor;
|
is = this.armor;
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
i = getReversedItemSlotNum(i);
|
i = getReversedItemSlotNum(i);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (i >= is.length) {
|
if (i >= is.length) {
|
||||||
i -= is.length;
|
i -= is.length;
|
||||||
is = this.extraSlots;
|
is = this.extraSlots;
|
||||||
}
|
} else if (is == this.armor) {
|
||||||
else if (is == this.armor) {
|
|
||||||
i = getReversedArmorSlotNum(i);
|
i = getReversedArmorSlotNum(i);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -227,10 +219,9 @@ public class SpecialPlayerInventory extends PlayerInventory implements ISpecialP
|
|||||||
is[i] = null;
|
is[i] = null;
|
||||||
return itemstack;
|
return itemstack;
|
||||||
}
|
}
|
||||||
else {
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void setItem(int i, ItemStack itemstack) {
|
public void setItem(int i, ItemStack itemstack) {
|
||||||
@@ -239,16 +230,14 @@ public class SpecialPlayerInventory extends PlayerInventory implements ISpecialP
|
|||||||
if (i >= is.length) {
|
if (i >= is.length) {
|
||||||
i -= is.length;
|
i -= is.length;
|
||||||
is = this.armor;
|
is = this.armor;
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
i = getReversedItemSlotNum(i);
|
i = getReversedItemSlotNum(i);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (i >= is.length) {
|
if (i >= is.length) {
|
||||||
i -= is.length;
|
i -= is.length;
|
||||||
is = this.extraSlots;
|
is = this.extraSlots;
|
||||||
}
|
} else if (is == this.armor) {
|
||||||
else if (is == this.armor) {
|
|
||||||
i = getReversedArmorSlotNum(i);
|
i = getReversedArmorSlotNum(i);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -269,22 +258,25 @@ public class SpecialPlayerInventory extends PlayerInventory implements ISpecialP
|
|||||||
}
|
}
|
||||||
|
|
||||||
private int getReversedItemSlotNum(int i) {
|
private int getReversedItemSlotNum(int i) {
|
||||||
if (i >= 27)
|
if (i >= 27) {
|
||||||
return i - 27;
|
return i - 27;
|
||||||
else
|
}
|
||||||
return i + 9;
|
return i + 9;
|
||||||
}
|
}
|
||||||
|
|
||||||
private int getReversedArmorSlotNum(int i) {
|
private int getReversedArmorSlotNum(int i) {
|
||||||
if (i == 0)
|
if (i == 0) {
|
||||||
return 3;
|
return 3;
|
||||||
if (i == 1)
|
}
|
||||||
|
if (i == 1) {
|
||||||
return 2;
|
return 2;
|
||||||
if (i == 2)
|
}
|
||||||
|
if (i == 2) {
|
||||||
return 1;
|
return 1;
|
||||||
if (i == 3)
|
}
|
||||||
|
if (i == 3) {
|
||||||
return 0;
|
return 0;
|
||||||
else
|
}
|
||||||
return i;
|
return i;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -300,4 +292,5 @@ public class SpecialPlayerInventory extends PlayerInventory implements ISpecialP
|
|||||||
public boolean a(EntityHuman entityhuman) {
|
public boolean a(EntityHuman entityhuman) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
@@ -4,22 +4,17 @@
|
|||||||
|
|
||||||
<parent>
|
<parent>
|
||||||
<groupId>com.lishid</groupId>
|
<groupId>com.lishid</groupId>
|
||||||
<artifactId>openinvparent</artifactId>
|
<artifactId>openinvinternal</artifactId>
|
||||||
<version>1.0-SNAPSHOT</version>
|
<version>1.0-SNAPSHOT</version>
|
||||||
</parent>
|
</parent>
|
||||||
|
|
||||||
<artifactId>OpenInvCraftbukkit1_11_R1</artifactId>
|
<artifactId>openinvadapter1_11_R1</artifactId>
|
||||||
<name>OpenInvCraftbukkit1_11_R1</name>
|
<name>OpenInvAdapter1_11_R1</name>
|
||||||
|
|
||||||
<dependencies>
|
<dependencies>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>com.lishid</groupId>
|
<groupId>com.lishid</groupId>
|
||||||
<artifactId>openinvcore</artifactId>
|
<artifactId>openinvcommon</artifactId>
|
||||||
<version>1.0-SNAPSHOT</version>
|
|
||||||
</dependency>
|
|
||||||
<dependency>
|
|
||||||
<groupId>com.lishid</groupId>
|
|
||||||
<artifactId>openinvplugin</artifactId>
|
|
||||||
<version>1.0-SNAPSHOT</version>
|
<version>1.0-SNAPSHOT</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
@@ -29,4 +24,5 @@
|
|||||||
<scope>provided</scope>
|
<scope>provided</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
</dependencies>
|
</dependencies>
|
||||||
|
|
||||||
</project>
|
</project>
|
@@ -18,14 +18,19 @@ package com.lishid.openinv.internal.v1_11_R1;
|
|||||||
|
|
||||||
import com.lishid.openinv.internal.IAnySilentContainer;
|
import com.lishid.openinv.internal.IAnySilentContainer;
|
||||||
|
|
||||||
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.ChatColor;
|
import org.bukkit.ChatColor;
|
||||||
|
import org.bukkit.Material;
|
||||||
|
import org.bukkit.block.BlockState;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
|
import org.bukkit.scheduler.BukkitRunnable;
|
||||||
|
|
||||||
// Volatile
|
// Volatile
|
||||||
import net.minecraft.server.v1_11_R1.AxisAlignedBB;
|
import net.minecraft.server.v1_11_R1.AxisAlignedBB;
|
||||||
import net.minecraft.server.v1_11_R1.Block;
|
import net.minecraft.server.v1_11_R1.Block;
|
||||||
import net.minecraft.server.v1_11_R1.BlockChest;
|
import net.minecraft.server.v1_11_R1.BlockChest;
|
||||||
import net.minecraft.server.v1_11_R1.BlockChest.Type;
|
import net.minecraft.server.v1_11_R1.BlockChest.Type;
|
||||||
|
import net.minecraft.server.v1_11_R1.BlockEnderChest;
|
||||||
import net.minecraft.server.v1_11_R1.BlockPosition;
|
import net.minecraft.server.v1_11_R1.BlockPosition;
|
||||||
import net.minecraft.server.v1_11_R1.BlockShulkerBox;
|
import net.minecraft.server.v1_11_R1.BlockShulkerBox;
|
||||||
import net.minecraft.server.v1_11_R1.Container;
|
import net.minecraft.server.v1_11_R1.Container;
|
||||||
@@ -36,11 +41,13 @@ import net.minecraft.server.v1_11_R1.EnumDirection;
|
|||||||
import net.minecraft.server.v1_11_R1.IBlockData;
|
import net.minecraft.server.v1_11_R1.IBlockData;
|
||||||
import net.minecraft.server.v1_11_R1.IInventory;
|
import net.minecraft.server.v1_11_R1.IInventory;
|
||||||
import net.minecraft.server.v1_11_R1.ITileInventory;
|
import net.minecraft.server.v1_11_R1.ITileInventory;
|
||||||
|
import net.minecraft.server.v1_11_R1.InventoryEnderChest;
|
||||||
import net.minecraft.server.v1_11_R1.InventoryLargeChest;
|
import net.minecraft.server.v1_11_R1.InventoryLargeChest;
|
||||||
import net.minecraft.server.v1_11_R1.PacketPlayOutOpenWindow;
|
import net.minecraft.server.v1_11_R1.PacketPlayOutOpenWindow;
|
||||||
import net.minecraft.server.v1_11_R1.StatisticList;
|
import net.minecraft.server.v1_11_R1.StatisticList;
|
||||||
import net.minecraft.server.v1_11_R1.TileEntity;
|
import net.minecraft.server.v1_11_R1.TileEntity;
|
||||||
import net.minecraft.server.v1_11_R1.TileEntityChest;
|
import net.minecraft.server.v1_11_R1.TileEntityChest;
|
||||||
|
import net.minecraft.server.v1_11_R1.TileEntityEnderChest;
|
||||||
import net.minecraft.server.v1_11_R1.TileEntityShulkerBox;
|
import net.minecraft.server.v1_11_R1.TileEntityShulkerBox;
|
||||||
import net.minecraft.server.v1_11_R1.World;
|
import net.minecraft.server.v1_11_R1.World;
|
||||||
|
|
||||||
@@ -49,125 +56,50 @@ import org.bukkit.craftbukkit.v1_11_R1.entity.CraftPlayer;
|
|||||||
public class AnySilentContainer implements IAnySilentContainer {
|
public class AnySilentContainer implements IAnySilentContainer {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isAnySilentContainer(org.bukkit.block.BlockState block) {
|
public boolean isAnySilentContainer(org.bukkit.block.Block block) {
|
||||||
return block instanceof org.bukkit.block.Chest || block instanceof org.bukkit.block.ShulkerBox;
|
if (block.getType() == Material.ENDER_CHEST) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
BlockState state = block.getState();
|
||||||
|
return state instanceof org.bukkit.block.Chest || state instanceof org.bukkit.block.ShulkerBox;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean activateContainer(Player p, boolean anychest, boolean silentchest, int x, int y, int z) {
|
public boolean isAnyContainerNeeded(Player p, org.bukkit.block.Block b) {
|
||||||
|
|
||||||
EntityPlayer player = ((CraftPlayer) p).getHandle();
|
EntityPlayer player = ((CraftPlayer) p).getHandle();
|
||||||
World world = player.world;
|
World world = player.world;
|
||||||
BlockPosition blockPosition = new BlockPosition(x, y, z);
|
BlockPosition blockPosition = new BlockPosition(b.getX(), b.getY(), b.getZ());
|
||||||
Object tile = world.getTileEntity(blockPosition);
|
Block block = world.getType(blockPosition).getBlock();
|
||||||
|
|
||||||
if (tile == null) {
|
if (block instanceof BlockShulkerBox) {
|
||||||
return false;
|
return isBlockedShulkerBox(world, blockPosition, block);
|
||||||
}
|
}
|
||||||
|
|
||||||
Block block = world.getType(new BlockPosition(x, y, z)).getBlock();
|
if (block instanceof BlockEnderChest) {
|
||||||
Container container = null;
|
// Ender chests are not blocked by ocelots.
|
||||||
|
return world.getType(blockPosition.up()).m();
|
||||||
|
}
|
||||||
|
|
||||||
if (block instanceof BlockChest) {
|
// Check if chest is blocked or has an ocelot on top
|
||||||
BlockChest blockChest = (BlockChest) block;
|
if (isBlockedChest(world, blockPosition)) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
for (EnumDirection enumDirection : EnumDirection.EnumDirectionLimit.HORIZONTAL) {
|
// Check for matching adjacent chests that are blocked or have an ocelot on top
|
||||||
BlockPosition localBlockPosition = blockPosition.shift(enumDirection);
|
for (EnumDirection localEnumDirection : EnumDirection.EnumDirectionLimit.HORIZONTAL) {
|
||||||
|
BlockPosition localBlockPosition = blockPosition.shift(localEnumDirection);
|
||||||
Block localBlock = world.getType(localBlockPosition).getBlock();
|
Block localBlock = world.getType(localBlockPosition).getBlock();
|
||||||
|
|
||||||
if (localBlock != block) {
|
if (localBlock != block) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!anychest && isBlockedChest(world, localBlock, localBlockPosition)) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
TileEntity localTileEntity = world.getTileEntity(localBlockPosition);
|
TileEntity localTileEntity = world.getTileEntity(localBlockPosition);
|
||||||
if (!(localTileEntity instanceof TileEntityChest)) {
|
if (!(localTileEntity instanceof TileEntityChest)) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((enumDirection == EnumDirection.WEST) || (enumDirection == EnumDirection.NORTH)) {
|
if (isBlockedChest(world, localBlockPosition)) {
|
||||||
tile = new InventoryLargeChest("container.chestDouble",
|
|
||||||
(TileEntityChest) localTileEntity, (ITileInventory) tile);
|
|
||||||
} else {
|
|
||||||
tile = new InventoryLargeChest("container.chestDouble",
|
|
||||||
(ITileInventory) tile, (TileEntityChest) localTileEntity);
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (blockChest.g == Type.BASIC)
|
|
||||||
player.b(StatisticList.ac);
|
|
||||||
else if (blockChest.g == Type.TRAP) {
|
|
||||||
player.b(StatisticList.W);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (silentchest) {
|
|
||||||
container = new SilentContainerChest(player.inventory, ((IInventory) tile), player);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (block instanceof BlockShulkerBox) {
|
|
||||||
if (!anychest && isBlockedShulkerBox(world, blockPosition, block)) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
player.b(StatisticList.ae);
|
|
||||||
|
|
||||||
if (silentchest && tile instanceof TileEntityShulkerBox) {
|
|
||||||
// TODO: This fixes sound, but the box is then silent for anyone until the tile entity is recreated
|
|
||||||
SilentContainerShulkerBox.increaseOpenQuantity((TileEntityShulkerBox) tile);
|
|
||||||
container = new SilentContainerShulkerBox(player.inventory, ((IInventory) tile), player);
|
|
||||||
SilentContainerShulkerBox.decreaseOpenQuantity((TileEntityShulkerBox) tile);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
boolean returnValue = false;
|
|
||||||
|
|
||||||
if (!silentchest || container == null) {
|
|
||||||
player.openContainer((IInventory) tile);
|
|
||||||
returnValue = true;
|
|
||||||
} else {
|
|
||||||
try {
|
|
||||||
int windowId = player.nextContainerCounter();
|
|
||||||
player.playerConnection.sendPacket(new PacketPlayOutOpenWindow(windowId, "minecraft:chest", ((IInventory) tile).getScoreboardDisplayName(), ((IInventory) tile).getSize()));
|
|
||||||
player.activeContainer = container;
|
|
||||||
player.activeContainer.windowId = windowId;
|
|
||||||
player.activeContainer.addSlotListener(player);
|
|
||||||
returnValue = true;
|
|
||||||
} catch (Exception e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
p.sendMessage(ChatColor.RED + "Error while sending silent chest.");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
return returnValue;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean isAnyContainerNeeded(Player p, int x, int y, int z) {
|
|
||||||
EntityPlayer player = ((CraftPlayer) p).getHandle();
|
|
||||||
World world = player.world;
|
|
||||||
BlockPosition blockPosition = new BlockPosition(x, y, z);
|
|
||||||
Block block = world.getType(blockPosition).getBlock();
|
|
||||||
|
|
||||||
if (block instanceof BlockShulkerBox) {
|
|
||||||
return isBlockedShulkerBox(world, blockPosition, block);
|
|
||||||
}
|
|
||||||
|
|
||||||
// For reference, loot at net.minecraft.server.BlockChest
|
|
||||||
// Check if chest is blocked or has an ocelot on top
|
|
||||||
if (world.getType(new BlockPosition(x, y + 1, z)).m() || hasOcelotOnTop(world, blockPosition)) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Check for matching adjacent chests that are blocked or have an ocelot on top
|
|
||||||
for (EnumDirection localEnumDirection : EnumDirection.EnumDirectionLimit.HORIZONTAL) {
|
|
||||||
BlockPosition localBlockPosition = blockPosition.shift(localEnumDirection);
|
|
||||||
if (isBlockedChest(world, block, localBlockPosition)) {
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -192,18 +124,15 @@ public class AnySilentContainer implements IAnySilentContainer {
|
|||||||
.a(enumDirection.getAdjacentX(), enumDirection.getAdjacentY(),
|
.a(enumDirection.getAdjacentX(), enumDirection.getAdjacentY(),
|
||||||
enumDirection.getAdjacentZ());
|
enumDirection.getAdjacentZ());
|
||||||
|
|
||||||
return !(world.b(axisAlignedBB.a(blockPosition.shift(enumDirection))));
|
return world.b(axisAlignedBB.a(blockPosition.shift(enumDirection)));
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
private boolean isBlockedChest(World world, Block block, BlockPosition blockPosition) {
|
|
||||||
if (world.getType(blockPosition).getBlock() == block) {
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
return world.getType(blockPosition).m() || hasOcelotOnTop(world, blockPosition);
|
private boolean isBlockedChest(World world, BlockPosition blockPosition) {
|
||||||
|
// For reference, loot at net.minecraft.server.BlockChest
|
||||||
|
return world.getType(blockPosition.up()).m() || hasOcelotOnTop(world, blockPosition);
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean hasOcelotOnTop(World world, BlockPosition blockPosition) {
|
private boolean hasOcelotOnTop(World world, BlockPosition blockPosition) {
|
||||||
@@ -220,22 +149,128 @@ public class AnySilentContainer implements IAnySilentContainer {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* @deprecated Use {@link #activateContainer(Player, boolean, boolean, int, int, int)}.
|
|
||||||
*/
|
|
||||||
@Deprecated
|
|
||||||
@Override
|
@Override
|
||||||
public boolean activateChest(Player player, boolean anychest, boolean silentchest, int x, int y, int z) {
|
public boolean activateContainer(Player p, boolean silentchest, org.bukkit.block.Block b) {
|
||||||
return !activateContainer(player, anychest, silentchest, x, y, z);
|
|
||||||
|
EntityPlayer player = ((CraftPlayer) p).getHandle();
|
||||||
|
|
||||||
|
// Silent ender chest is pretty much API-only
|
||||||
|
if (silentchest && b.getType() == Material.ENDER_CHEST) {
|
||||||
|
p.openInventory(p.getEnderChest());
|
||||||
|
player.b(StatisticList.X);
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
final World world = player.world;
|
||||||
* @deprecated Use {@link #isAnyContainerNeeded(Player, int, int, int)}.
|
final BlockPosition blockPosition = new BlockPosition(b.getX(), b.getY(), b.getZ());
|
||||||
*/
|
Object tile = world.getTileEntity(blockPosition);
|
||||||
@Deprecated
|
|
||||||
|
if (tile == null) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (tile instanceof TileEntityEnderChest) {
|
||||||
|
// Anychest ender chest. See net.minecraft.server.BlockEnderChest
|
||||||
|
InventoryEnderChest enderChest = player.getEnderChest();
|
||||||
|
enderChest.a((TileEntityEnderChest) tile);
|
||||||
|
player.openContainer(enderChest);
|
||||||
|
player.b(StatisticList.X);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!(tile instanceof IInventory)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
Block block = world.getType(blockPosition).getBlock();
|
||||||
|
Container container = null;
|
||||||
|
|
||||||
|
if (block instanceof BlockChest) {
|
||||||
|
BlockChest blockChest = (BlockChest) block;
|
||||||
|
|
||||||
|
for (EnumDirection localEnumDirection : EnumDirection.EnumDirectionLimit.HORIZONTAL) {
|
||||||
|
BlockPosition localBlockPosition = blockPosition.shift(localEnumDirection);
|
||||||
|
Block localBlock = world.getType(localBlockPosition).getBlock();
|
||||||
|
|
||||||
|
if (localBlock != block) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
TileEntity localTileEntity = world.getTileEntity(localBlockPosition);
|
||||||
|
if (!(localTileEntity instanceof TileEntityChest)) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ((localEnumDirection == EnumDirection.WEST) || (localEnumDirection == EnumDirection.NORTH)) {
|
||||||
|
tile = new InventoryLargeChest("container.chestDouble",
|
||||||
|
(TileEntityChest) localTileEntity, (ITileInventory) tile);
|
||||||
|
} else {
|
||||||
|
tile = new InventoryLargeChest("container.chestDouble",
|
||||||
|
(ITileInventory) tile, (TileEntityChest) localTileEntity);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (blockChest.g == Type.BASIC) {
|
||||||
|
player.b(StatisticList.ac);
|
||||||
|
} else if (blockChest.g == Type.TRAP) {
|
||||||
|
player.b(StatisticList.W);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (silentchest) {
|
||||||
|
container = new SilentContainerChest(player.inventory, ((IInventory) tile), player);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (block instanceof BlockShulkerBox) {
|
||||||
|
player.b(StatisticList.ae);
|
||||||
|
|
||||||
|
if (silentchest && tile instanceof TileEntityShulkerBox) {
|
||||||
|
// Set value to current + 1. Ensures consistency later when resetting.
|
||||||
|
SilentContainerShulkerBox.setOpenValue((TileEntityShulkerBox) tile,
|
||||||
|
SilentContainerShulkerBox.getOpenValue((TileEntityShulkerBox) tile) + 1);
|
||||||
|
|
||||||
|
container = new SilentContainerShulkerBox(player.inventory, (IInventory) tile, player);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
boolean returnValue = false;
|
||||||
|
final IInventory iInventory = (IInventory) tile;
|
||||||
|
|
||||||
|
if (!silentchest || container == null) {
|
||||||
|
player.openContainer(iInventory);
|
||||||
|
returnValue = true;
|
||||||
|
} else {
|
||||||
|
try {
|
||||||
|
int windowId = player.nextContainerCounter();
|
||||||
|
player.playerConnection.sendPacket(new PacketPlayOutOpenWindow(windowId, iInventory.getName(), iInventory.getScoreboardDisplayName(), iInventory.getSize()));
|
||||||
|
player.activeContainer = container;
|
||||||
|
player.activeContainer.windowId = windowId;
|
||||||
|
player.activeContainer.addSlotListener(player);
|
||||||
|
returnValue = true;
|
||||||
|
if (tile instanceof TileEntityShulkerBox) {
|
||||||
|
new BukkitRunnable() {
|
||||||
@Override
|
@Override
|
||||||
public boolean isAnyChestNeeded(Player player, int x, int y, int z) {
|
public void run() {
|
||||||
return isAnyContainerNeeded(player, x, y, z);
|
// TODO hacky
|
||||||
|
Object tile = world.getTileEntity(blockPosition);
|
||||||
|
if (!(tile instanceof TileEntityShulkerBox)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
TileEntityShulkerBox box = (TileEntityShulkerBox) tile;
|
||||||
|
// Reset back - we added 1, and calling TileEntityShulkerBox#startOpen adds 1 more.
|
||||||
|
SilentContainerShulkerBox.setOpenValue(box,
|
||||||
|
SilentContainerShulkerBox.getOpenValue((TileEntityShulkerBox) tile) - 2);
|
||||||
|
}
|
||||||
|
}.runTaskLater(Bukkit.getPluginManager().getPlugin("OpenInv"), 2);
|
||||||
|
}
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
p.sendMessage(ChatColor.RED + "Error while sending silent chest.");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return returnValue;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
@@ -0,0 +1,79 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (C) 2011-2014 lishid. All rights reserved.
|
||||||
|
*
|
||||||
|
* This program is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation, version 3.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package com.lishid.openinv.internal.v1_11_R1;
|
||||||
|
|
||||||
|
import com.lishid.openinv.internal.IInventoryAccess;
|
||||||
|
import com.lishid.openinv.internal.ISpecialEnderChest;
|
||||||
|
import com.lishid.openinv.internal.ISpecialPlayerInventory;
|
||||||
|
import com.lishid.openinv.util.InternalAccessor;
|
||||||
|
|
||||||
|
import org.bukkit.inventory.Inventory;
|
||||||
|
|
||||||
|
// Volatile
|
||||||
|
import net.minecraft.server.v1_11_R1.IInventory;
|
||||||
|
|
||||||
|
import org.bukkit.craftbukkit.v1_11_R1.inventory.CraftInventory;
|
||||||
|
|
||||||
|
public class InventoryAccess implements IInventoryAccess {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isSpecialPlayerInventory(Inventory inventory) {
|
||||||
|
if (inventory instanceof CraftInventory) {
|
||||||
|
return ((CraftInventory) inventory).getInventory() instanceof ISpecialPlayerInventory;
|
||||||
|
}
|
||||||
|
return InternalAccessor.grabFieldOfTypeFromObject(IInventory.class, inventory) instanceof ISpecialPlayerInventory;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public ISpecialPlayerInventory getSpecialPlayerInventory(Inventory inventory) {
|
||||||
|
IInventory inv;
|
||||||
|
if (inventory instanceof CraftInventory) {
|
||||||
|
inv = ((CraftInventory) inventory).getInventory();
|
||||||
|
} else {
|
||||||
|
inv = InternalAccessor.grabFieldOfTypeFromObject(IInventory.class, inventory);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (inv instanceof SpecialPlayerInventory) {
|
||||||
|
return (SpecialPlayerInventory) inv;
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isSpecialEnderChest(Inventory inventory) {
|
||||||
|
if (inventory instanceof CraftInventory) {
|
||||||
|
return ((CraftInventory) inventory).getInventory() instanceof ISpecialEnderChest;
|
||||||
|
}
|
||||||
|
return InternalAccessor.grabFieldOfTypeFromObject(IInventory.class, inventory) instanceof ISpecialEnderChest;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public ISpecialEnderChest getSpecialEnderChest(Inventory inventory) {
|
||||||
|
IInventory inv;
|
||||||
|
if (inventory instanceof CraftInventory) {
|
||||||
|
inv = ((CraftInventory) inventory).getInventory();
|
||||||
|
} else {
|
||||||
|
inv = InternalAccessor.grabFieldOfTypeFromObject(IInventory.class, inventory);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (inv instanceof SpecialEnderChest) {
|
||||||
|
return (SpecialEnderChest) inv;
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@@ -16,6 +16,8 @@
|
|||||||
|
|
||||||
package com.lishid.openinv.internal.v1_11_R1;
|
package com.lishid.openinv.internal.v1_11_R1;
|
||||||
|
|
||||||
|
import java.util.UUID;
|
||||||
|
|
||||||
import com.lishid.openinv.internal.IPlayerDataManager;
|
import com.lishid.openinv.internal.IPlayerDataManager;
|
||||||
|
|
||||||
import com.mojang.authlib.GameProfile;
|
import com.mojang.authlib.GameProfile;
|
||||||
@@ -35,28 +37,46 @@ public class PlayerDataManager implements IPlayerDataManager {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Player loadPlayer(OfflinePlayer offline) {
|
public Player loadPlayer(OfflinePlayer offline) {
|
||||||
|
// Ensure player has data
|
||||||
if (offline == null || !offline.hasPlayedBefore()) {
|
if (offline == null || !offline.hasPlayedBefore()) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Create a profile and entity to load the player data
|
||||||
GameProfile profile = new GameProfile(offline.getUniqueId(), offline.getName());
|
GameProfile profile = new GameProfile(offline.getUniqueId(), offline.getName());
|
||||||
MinecraftServer server = ((CraftServer) Bukkit.getServer()).getServer();
|
MinecraftServer server = ((CraftServer) Bukkit.getServer()).getServer();
|
||||||
// Create an entity to load the player data
|
EntityPlayer entity = new EntityPlayer(server, server.getWorldServer(0), profile,
|
||||||
EntityPlayer entity = new EntityPlayer(server, server.getWorldServer(0), profile, new PlayerInteractManager(server.getWorldServer(0)));
|
new PlayerInteractManager(server.getWorldServer(0)));
|
||||||
|
|
||||||
// Get the bukkit entity
|
// Get the bukkit entity
|
||||||
Player target = (entity == null) ? null : entity.getBukkitEntity();
|
Player target = (entity == null) ? null : entity.getBukkitEntity();
|
||||||
if (target != null) {
|
if (target != null) {
|
||||||
// Load data
|
// Load data
|
||||||
target.loadData();
|
target.loadData();
|
||||||
|
}
|
||||||
// Return the entity
|
// Return the entity
|
||||||
return target;
|
return target;
|
||||||
}
|
}
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getPlayerDataID(OfflinePlayer player) {
|
public String getPlayerDataID(OfflinePlayer player) {
|
||||||
return player.getUniqueId().toString();
|
return player.getUniqueId().toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public OfflinePlayer getPlayerByID(String identifier) {
|
||||||
|
try {
|
||||||
|
UUID uuid = UUID.fromString(identifier);
|
||||||
|
OfflinePlayer player = Bukkit.getOfflinePlayer(uuid);
|
||||||
|
// Ensure player is a real player, otherwise return null
|
||||||
|
if (player == null || !player.hasPlayedBefore() && !player.isOnline()) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
return player;
|
||||||
|
} catch (IllegalArgumentException e) {
|
||||||
|
// Not a UUID
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
@@ -28,7 +28,7 @@ public class SilentContainerChest extends ContainerChest {
|
|||||||
public SilentContainerChest(PlayerInventory playerInventory, IInventory iInventory,
|
public SilentContainerChest(PlayerInventory playerInventory, IInventory iInventory,
|
||||||
EntityHuman entityHuman) {
|
EntityHuman entityHuman) {
|
||||||
super(playerInventory, iInventory, entityHuman);
|
super(playerInventory, iInventory, entityHuman);
|
||||||
// close signal
|
// Send close signal
|
||||||
iInventory.closeContainer(entityHuman);
|
iInventory.closeContainer(entityHuman);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -37,9 +37,11 @@ public class SilentContainerChest extends ContainerChest {
|
|||||||
// Don't send close signal twice, might screw up
|
// Don't send close signal twice, might screw up
|
||||||
PlayerInventory playerinventory = entityHuman.inventory;
|
PlayerInventory playerinventory = entityHuman.inventory;
|
||||||
|
|
||||||
if (!playerinventory.getCarried().isEmpty()) {
|
if (playerinventory.getCarried() != ItemStack.a) {
|
||||||
entityHuman.drop(playerinventory.getCarried(), false);
|
ItemStack carried = playerinventory.getCarried();
|
||||||
playerinventory.setCarried(ItemStack.a);
|
playerinventory.setCarried(ItemStack.a);
|
||||||
|
entityHuman.drop(carried, false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
@@ -11,31 +11,7 @@ import net.minecraft.server.v1_11_R1.TileEntityShulkerBox;
|
|||||||
|
|
||||||
public class SilentContainerShulkerBox extends ContainerShulkerBox {
|
public class SilentContainerShulkerBox extends ContainerShulkerBox {
|
||||||
|
|
||||||
private static Field h;
|
private static Field fieldShulkerActionData;
|
||||||
|
|
||||||
private static Field exposeOpenStatus() throws NoSuchFieldException, SecurityException {
|
|
||||||
if (h == null) {
|
|
||||||
h = TileEntityShulkerBox.class.getDeclaredField("h");
|
|
||||||
h.setAccessible(true);
|
|
||||||
}
|
|
||||||
return h;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void increaseOpenQuantity(TileEntityShulkerBox containerShulkerBox) {
|
|
||||||
try {
|
|
||||||
exposeOpenStatus().set(containerShulkerBox, ((Integer) exposeOpenStatus().get(containerShulkerBox)) + 1);
|
|
||||||
} catch (Exception e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void decreaseOpenQuantity(TileEntityShulkerBox containerShulkerBox) {
|
|
||||||
try {
|
|
||||||
exposeOpenStatus().set(containerShulkerBox, ((Integer) exposeOpenStatus().get(containerShulkerBox)) - 1);
|
|
||||||
} catch (Exception e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public SilentContainerShulkerBox(PlayerInventory playerInventory, IInventory iInventory,
|
public SilentContainerShulkerBox(PlayerInventory playerInventory, IInventory iInventory,
|
||||||
EntityHuman entityHuman) {
|
EntityHuman entityHuman) {
|
||||||
@@ -52,4 +28,29 @@ public class SilentContainerShulkerBox extends ContainerShulkerBox {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static Field exposeOpenStatus() throws NoSuchFieldException, SecurityException {
|
||||||
|
if (fieldShulkerActionData == null) {
|
||||||
|
fieldShulkerActionData = TileEntityShulkerBox.class.getDeclaredField("h");
|
||||||
|
fieldShulkerActionData.setAccessible(true);
|
||||||
|
}
|
||||||
|
return fieldShulkerActionData;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void setOpenValue(TileEntityShulkerBox tileShulkerBox, Object value) {
|
||||||
|
try {
|
||||||
|
exposeOpenStatus().set(tileShulkerBox, value);
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Integer getOpenValue(TileEntityShulkerBox tileShulkerBox) {
|
||||||
|
try {
|
||||||
|
return (Integer) exposeOpenStatus().get(tileShulkerBox);
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
@@ -38,10 +38,12 @@ public class SpecialEnderChest extends InventorySubcontainer implements IInvento
|
|||||||
|
|
||||||
private final InventoryEnderChest enderChest;
|
private final InventoryEnderChest enderChest;
|
||||||
private final CraftInventory inventory = new CraftInventory(this);
|
private final CraftInventory inventory = new CraftInventory(this);
|
||||||
public boolean playerOnline = false;
|
private boolean playerOnline = false;
|
||||||
|
|
||||||
public SpecialEnderChest(Player player, Boolean online) {
|
public SpecialEnderChest(Player player, Boolean online) {
|
||||||
super(((CraftPlayer) player).getHandle().getEnderChest().getName(), ((CraftPlayer) player).getHandle().getEnderChest().hasCustomName(), ((CraftPlayer) player).getHandle().getEnderChest().getSize());
|
super(((CraftPlayer) player).getHandle().getEnderChest().getName(),
|
||||||
|
((CraftPlayer) player).getHandle().getEnderChest().hasCustomName(),
|
||||||
|
((CraftPlayer) player).getHandle().getEnderChest().getSize());
|
||||||
CraftPlayer craftPlayer = (CraftPlayer) player;
|
CraftPlayer craftPlayer = (CraftPlayer) player;
|
||||||
this.enderChest = craftPlayer.getHandle().getEnderChest();
|
this.enderChest = craftPlayer.getHandle().getEnderChest();
|
||||||
this.bukkitOwner = craftPlayer;
|
this.bukkitOwner = craftPlayer;
|
||||||
@@ -80,8 +82,7 @@ public class SpecialEnderChest extends InventorySubcontainer implements IInvento
|
|||||||
this.bukkitOwner = player;
|
this.bukkitOwner = player;
|
||||||
CraftPlayer craftPlayer = (CraftPlayer) player;
|
CraftPlayer craftPlayer = (CraftPlayer) player;
|
||||||
setItemLists(craftPlayer.getHandle().getEnderChest(), this.items);
|
setItemLists(craftPlayer.getHandle().getEnderChest(), this.items);
|
||||||
}
|
} catch (Exception e) {}
|
||||||
catch (Exception e) {}
|
|
||||||
playerOnline = true;
|
playerOnline = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
@@ -223,22 +223,25 @@ public class SpecialPlayerInventory extends PlayerInventory implements ISpecialP
|
|||||||
}
|
}
|
||||||
|
|
||||||
private int getReversedItemSlotNum(int i) {
|
private int getReversedItemSlotNum(int i) {
|
||||||
if (i >= 27)
|
if (i >= 27) {
|
||||||
return i - 27;
|
return i - 27;
|
||||||
else
|
}
|
||||||
return i + 9;
|
return i + 9;
|
||||||
}
|
}
|
||||||
|
|
||||||
private int getReversedArmorSlotNum(int i) {
|
private int getReversedArmorSlotNum(int i) {
|
||||||
if (i == 0)
|
if (i == 0) {
|
||||||
return 3;
|
return 3;
|
||||||
if (i == 1)
|
}
|
||||||
|
if (i == 1) {
|
||||||
return 2;
|
return 2;
|
||||||
if (i == 2)
|
}
|
||||||
|
if (i == 2) {
|
||||||
return 1;
|
return 1;
|
||||||
if (i == 3)
|
}
|
||||||
|
if (i == 3) {
|
||||||
return 0;
|
return 0;
|
||||||
else
|
}
|
||||||
return i;
|
return i;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -254,4 +257,5 @@ public class SpecialPlayerInventory extends PlayerInventory implements ISpecialP
|
|||||||
public boolean a(EntityHuman entityhuman) {
|
public boolean a(EntityHuman entityhuman) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
@@ -4,22 +4,17 @@
|
|||||||
|
|
||||||
<parent>
|
<parent>
|
||||||
<groupId>com.lishid</groupId>
|
<groupId>com.lishid</groupId>
|
||||||
<artifactId>openinvparent</artifactId>
|
<artifactId>openinvinternal</artifactId>
|
||||||
<version>1.0-SNAPSHOT</version>
|
<version>1.0-SNAPSHOT</version>
|
||||||
</parent>
|
</parent>
|
||||||
|
|
||||||
<artifactId>OpenInvCraftbukkit1_4_R1</artifactId>
|
<artifactId>openinvadapter1_4_R1</artifactId>
|
||||||
<name>OpenInvCraftbukkit1_4_R1</name>
|
<name>OpenInvAdapter1_4_R1</name>
|
||||||
|
|
||||||
<dependencies>
|
<dependencies>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>com.lishid</groupId>
|
<groupId>com.lishid</groupId>
|
||||||
<artifactId>openinvcore</artifactId>
|
<artifactId>openinvcommon</artifactId>
|
||||||
<version>1.0-SNAPSHOT</version>
|
|
||||||
</dependency>
|
|
||||||
<dependency>
|
|
||||||
<groupId>com.lishid</groupId>
|
|
||||||
<artifactId>openinvplugin</artifactId>
|
|
||||||
<version>1.0-SNAPSHOT</version>
|
<version>1.0-SNAPSHOT</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
@@ -29,4 +24,5 @@
|
|||||||
<scope>provided</scope>
|
<scope>provided</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
</dependencies>
|
</dependencies>
|
||||||
|
|
||||||
</project>
|
</project>
|
@@ -0,0 +1,158 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (C) 2011-2014 lishid. All rights reserved.
|
||||||
|
*
|
||||||
|
* This program is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation, version 3.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package com.lishid.openinv.internal.v1_4_R1;
|
||||||
|
|
||||||
|
import com.lishid.openinv.internal.IAnySilentContainer;
|
||||||
|
|
||||||
|
import org.bukkit.ChatColor;
|
||||||
|
import org.bukkit.Material;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
|
// Volatile
|
||||||
|
import net.minecraft.server.v1_4_R1.AxisAlignedBB;
|
||||||
|
import net.minecraft.server.v1_4_R1.BlockEnderChest;
|
||||||
|
import net.minecraft.server.v1_4_R1.EntityOcelot;
|
||||||
|
import net.minecraft.server.v1_4_R1.EntityPlayer;
|
||||||
|
import net.minecraft.server.v1_4_R1.IInventory;
|
||||||
|
import net.minecraft.server.v1_4_R1.InventoryEnderChest;
|
||||||
|
import net.minecraft.server.v1_4_R1.InventoryLargeChest;
|
||||||
|
import net.minecraft.server.v1_4_R1.Packet100OpenWindow;
|
||||||
|
import net.minecraft.server.v1_4_R1.TileEntityChest;
|
||||||
|
import net.minecraft.server.v1_4_R1.TileEntityEnderChest;
|
||||||
|
import net.minecraft.server.v1_4_R1.World;
|
||||||
|
|
||||||
|
import org.bukkit.craftbukkit.v1_4_R1.entity.CraftPlayer;
|
||||||
|
|
||||||
|
public class AnySilentContainer implements IAnySilentContainer {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isAnySilentContainer(org.bukkit.block.Block block) {
|
||||||
|
return block.getType() == Material.ENDER_CHEST || block.getState() instanceof org.bukkit.block.Chest;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isAnyContainerNeeded(Player p, org.bukkit.block.Block block) {
|
||||||
|
// FOR REFERENCE, LOOK AT net.minecraft.server.BlockChest
|
||||||
|
EntityPlayer player = ((CraftPlayer) p).getHandle();
|
||||||
|
World world = player.world;
|
||||||
|
|
||||||
|
if (block instanceof BlockEnderChest) {
|
||||||
|
// Ender chests are not blocked by ocelots.
|
||||||
|
return world.t(block.getX(), block.getY() + 1, block.getZ());
|
||||||
|
}
|
||||||
|
|
||||||
|
// If block or ocelot on top
|
||||||
|
if (isBlockedChest(world, block.getX(), block.getY() + 1, block.getZ())) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
int id = world.getTypeId(block.getX(), block.getY(), block.getZ());
|
||||||
|
|
||||||
|
// If block next to chest is chest and has a block or ocelot on top
|
||||||
|
if (world.getTypeId(block.getX(), block.getY(), block.getZ() + 1) == id) {
|
||||||
|
return isBlockedChest(world, block.getX(), block.getY() + 1, block.getZ() + 1);
|
||||||
|
} else if(world.getTypeId(block.getX(), block.getY(), block.getZ() - 1) == id) {
|
||||||
|
return isBlockedChest(world, block.getX(), block.getY() + 1, block.getZ() - 1);
|
||||||
|
} else if (world.getTypeId(block.getX() + 1, block.getY(), block.getZ()) == id) {
|
||||||
|
return isBlockedChest(world, block.getX() + 1, block.getY() + 1, block.getZ());
|
||||||
|
} else if (world.getTypeId(block.getX() - 1, block.getY(), block.getZ()) == id) {
|
||||||
|
return isBlockedChest(world, block.getX() - 1, block.getY() + 1, block.getZ());
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
private boolean isBlockedChest(World world, int x, int y, int z) {
|
||||||
|
return world.t(x, y + 1, z) || hasOcelotOnTop(world, x, y, z);
|
||||||
|
}
|
||||||
|
|
||||||
|
private boolean hasOcelotOnTop(World world, int x, int y, int z) {
|
||||||
|
for (Object localEntity : world.a(EntityOcelot.class,
|
||||||
|
AxisAlignedBB.a(x, y + 1, z, x + 1, y + 2, z + 1))) {
|
||||||
|
EntityOcelot localEntityOcelot = (EntityOcelot) localEntity;
|
||||||
|
if (localEntityOcelot.isSitting()) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean activateContainer(Player p, boolean silentchest, org.bukkit.block.Block block) {
|
||||||
|
|
||||||
|
EntityPlayer player = ((CraftPlayer) p).getHandle();
|
||||||
|
|
||||||
|
// Silent ender chest is API-only
|
||||||
|
if (silentchest && block.getType() == Material.ENDER_CHEST) {
|
||||||
|
p.openInventory(p.getEnderChest());
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
World world = player.world;
|
||||||
|
Object tile = world.getTileEntity(block.getX(), block.getY(), block.getZ());
|
||||||
|
|
||||||
|
if (tile == null) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (tile instanceof TileEntityEnderChest) {
|
||||||
|
// Anychest ender chest. See net.minecraft.server.BlockEnderChest
|
||||||
|
InventoryEnderChest enderChest = player.getEnderChest();
|
||||||
|
enderChest.a((TileEntityEnderChest) tile);
|
||||||
|
player.openContainer(enderChest);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!(tile instanceof IInventory)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
int id = world.getTypeId(block.getX(), block.getY(), block.getZ());
|
||||||
|
|
||||||
|
if (world.getTypeId(block.getX(), block.getY(), block.getZ() + 1) == id) {
|
||||||
|
tile = new InventoryLargeChest("Large chest", (IInventory) tile, (TileEntityChest) world.getTileEntity(block.getX(), block.getY(), block.getZ() + 1));
|
||||||
|
} else if (world.getTypeId(block.getX(), block.getY(), block.getZ() - 1) == id) {
|
||||||
|
tile = new InventoryLargeChest("Large chest", (TileEntityChest) world.getTileEntity(block.getX(), block.getY(), block.getZ() - 1), (IInventory) tile);
|
||||||
|
} else if (world.getTypeId(block.getX() + 1, block.getY(), block.getZ()) == id) {
|
||||||
|
tile = new InventoryLargeChest("Large chest", (IInventory) tile, (TileEntityChest) world.getTileEntity(block.getX() + 1, block.getY(), block.getZ()));
|
||||||
|
} else if (world.getTypeId(block.getX() - 1, block.getY(), block.getZ()) == id) {
|
||||||
|
tile = new InventoryLargeChest("Large chest", (TileEntityChest) world.getTileEntity(block.getX() - 1, block.getY(), block.getZ()), (IInventory) tile);
|
||||||
|
}
|
||||||
|
|
||||||
|
boolean returnValue = false;
|
||||||
|
if (!silentchest) {
|
||||||
|
player.openContainer((IInventory) tile);
|
||||||
|
returnValue = true;
|
||||||
|
} else {
|
||||||
|
try {
|
||||||
|
int windowId = player.nextContainerCounter();
|
||||||
|
player.playerConnection.sendPacket(new Packet100OpenWindow(windowId, 0, ((IInventory) tile).getName(), ((IInventory) tile).getSize()));
|
||||||
|
player.activeContainer = new SilentContainerChest(player.inventory, ((IInventory) tile));
|
||||||
|
player.activeContainer.windowId = windowId;
|
||||||
|
player.activeContainer.addSlotListener(player);
|
||||||
|
returnValue = true;
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
p.sendMessage(ChatColor.RED + "Error while sending silent chest.");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return returnValue;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@@ -0,0 +1,79 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (C) 2011-2014 lishid. All rights reserved.
|
||||||
|
*
|
||||||
|
* This program is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation, version 3.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package com.lishid.openinv.internal.v1_4_R1;
|
||||||
|
|
||||||
|
import com.lishid.openinv.internal.IInventoryAccess;
|
||||||
|
import com.lishid.openinv.internal.ISpecialEnderChest;
|
||||||
|
import com.lishid.openinv.internal.ISpecialPlayerInventory;
|
||||||
|
import com.lishid.openinv.util.InternalAccessor;
|
||||||
|
|
||||||
|
import org.bukkit.inventory.Inventory;
|
||||||
|
|
||||||
|
// Volatile
|
||||||
|
import net.minecraft.server.v1_4_R1.IInventory;
|
||||||
|
|
||||||
|
import org.bukkit.craftbukkit.v1_4_R1.inventory.CraftInventory;
|
||||||
|
|
||||||
|
public class InventoryAccess implements IInventoryAccess {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isSpecialPlayerInventory(Inventory inventory) {
|
||||||
|
if (inventory instanceof CraftInventory) {
|
||||||
|
return ((CraftInventory) inventory).getInventory() instanceof ISpecialPlayerInventory;
|
||||||
|
}
|
||||||
|
return InternalAccessor.grabFieldOfTypeFromObject(IInventory.class, inventory) instanceof ISpecialPlayerInventory;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public ISpecialPlayerInventory getSpecialPlayerInventory(Inventory inventory) {
|
||||||
|
IInventory inv;
|
||||||
|
if (inventory instanceof CraftInventory) {
|
||||||
|
inv = ((CraftInventory) inventory).getInventory();
|
||||||
|
} else {
|
||||||
|
inv = InternalAccessor.grabFieldOfTypeFromObject(IInventory.class, inventory);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (inv instanceof SpecialPlayerInventory) {
|
||||||
|
return (SpecialPlayerInventory) inv;
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isSpecialEnderChest(Inventory inventory) {
|
||||||
|
if (inventory instanceof CraftInventory) {
|
||||||
|
return ((CraftInventory) inventory).getInventory() instanceof ISpecialEnderChest;
|
||||||
|
}
|
||||||
|
return InternalAccessor.grabFieldOfTypeFromObject(IInventory.class, inventory) instanceof ISpecialEnderChest;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public ISpecialEnderChest getSpecialEnderChest(Inventory inventory) {
|
||||||
|
IInventory inv;
|
||||||
|
if (inventory instanceof CraftInventory) {
|
||||||
|
inv = ((CraftInventory) inventory).getInventory();
|
||||||
|
} else {
|
||||||
|
inv = InternalAccessor.grabFieldOfTypeFromObject(IInventory.class, inventory);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (inv instanceof SpecialEnderChest) {
|
||||||
|
return (SpecialEnderChest) inv;
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@@ -34,25 +34,40 @@ public class PlayerDataManager implements IPlayerDataManager {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Player loadPlayer(OfflinePlayer offline) {
|
public Player loadPlayer(OfflinePlayer offline) {
|
||||||
|
// Ensure the player has data
|
||||||
|
if (offline == null || !offline.hasPlayedBefore()) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
MinecraftServer server = ((CraftServer) Bukkit.getServer()).getServer();
|
MinecraftServer server = ((CraftServer) Bukkit.getServer()).getServer();
|
||||||
|
|
||||||
// Create an entity to load the player data
|
// Create an entity to load the player data
|
||||||
EntityPlayer entity = new EntityPlayer(server, server.getWorldServer(0), offline.getName(), new PlayerInteractManager(server.getWorldServer(0)));
|
EntityPlayer entity = new EntityPlayer(server, server.getWorldServer(0), offline.getName(),
|
||||||
|
new PlayerInteractManager(server.getWorldServer(0)));
|
||||||
|
|
||||||
// Get the bukkit entity
|
// Get the bukkit entity
|
||||||
Player target = (entity == null) ? null : entity.getBukkitEntity();
|
Player target = (entity == null) ? null : entity.getBukkitEntity();
|
||||||
if (target != null) {
|
if (target != null) {
|
||||||
// Load data
|
// Load data
|
||||||
target.loadData();
|
target.loadData();
|
||||||
|
}
|
||||||
// Return the entity
|
// Return the entity
|
||||||
return target;
|
return target;
|
||||||
}
|
}
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getPlayerDataID(OfflinePlayer player) {
|
public String getPlayerDataID(OfflinePlayer player) {
|
||||||
return player.getName();
|
return player.getName();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public OfflinePlayer getPlayerByID(String identifier) {
|
||||||
|
OfflinePlayer player = Bukkit.getOfflinePlayer(identifier);
|
||||||
|
// Ensure player is a real player, otherwise return null
|
||||||
|
if (player == null || !player.hasPlayedBefore() && !player.isOnline()) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
return player;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
@@ -20,16 +20,15 @@ package com.lishid.openinv.internal.v1_4_R1;
|
|||||||
import net.minecraft.server.v1_4_R1.ContainerChest;
|
import net.minecraft.server.v1_4_R1.ContainerChest;
|
||||||
import net.minecraft.server.v1_4_R1.EntityHuman;
|
import net.minecraft.server.v1_4_R1.EntityHuman;
|
||||||
import net.minecraft.server.v1_4_R1.IInventory;
|
import net.minecraft.server.v1_4_R1.IInventory;
|
||||||
|
import net.minecraft.server.v1_4_R1.ItemStack;
|
||||||
import net.minecraft.server.v1_4_R1.PlayerInventory;
|
import net.minecraft.server.v1_4_R1.PlayerInventory;
|
||||||
|
|
||||||
public class SilentContainerChest extends ContainerChest {
|
public class SilentContainerChest extends ContainerChest {
|
||||||
public IInventory inv;
|
|
||||||
|
|
||||||
public SilentContainerChest(IInventory i1, IInventory i2) {
|
public SilentContainerChest(IInventory i1, IInventory i2) {
|
||||||
super(i1, i2);
|
super(i1, i2);
|
||||||
inv = i2;
|
// Send close signal
|
||||||
// close signal
|
i2.f();
|
||||||
inv.f();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -38,8 +37,10 @@ public class SilentContainerChest extends ContainerChest {
|
|||||||
PlayerInventory playerinventory = entityHuman.inventory;
|
PlayerInventory playerinventory = entityHuman.inventory;
|
||||||
|
|
||||||
if (playerinventory.getCarried() != null) {
|
if (playerinventory.getCarried() != null) {
|
||||||
entityHuman.drop(playerinventory.getCarried());
|
ItemStack carried = playerinventory.getCarried();
|
||||||
playerinventory.setCarried(null);
|
playerinventory.setCarried(null);
|
||||||
|
entityHuman.drop(carried);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
@@ -41,13 +41,14 @@ public class SpecialEnderChest extends InventorySubcontainer implements IInvento
|
|||||||
|
|
||||||
private final InventoryEnderChest enderChest;
|
private final InventoryEnderChest enderChest;
|
||||||
private final CraftInventory inventory = new CraftInventory(this);
|
private final CraftInventory inventory = new CraftInventory(this);
|
||||||
public List<HumanEntity> transaction = new ArrayList<HumanEntity>();
|
private final List<HumanEntity> transaction = new ArrayList<HumanEntity>();
|
||||||
public boolean playerOnline = false;
|
private boolean playerOnline = false;
|
||||||
private CraftPlayer owner;
|
private CraftPlayer owner;
|
||||||
private int maxStack = MAX_STACK;
|
private int maxStack = MAX_STACK;
|
||||||
|
|
||||||
public SpecialEnderChest(Player p, Boolean online) {
|
public SpecialEnderChest(Player p, Boolean online) {
|
||||||
super(((CraftPlayer) p).getHandle().getEnderChest().getName(), ((CraftPlayer) p).getHandle().getEnderChest().getSize());
|
super(((CraftPlayer) p).getHandle().getEnderChest().getName(),
|
||||||
|
((CraftPlayer) p).getHandle().getEnderChest().getSize());
|
||||||
CraftPlayer player = (CraftPlayer) p;
|
CraftPlayer player = (CraftPlayer) p;
|
||||||
this.enderChest = player.getHandle().getEnderChest();
|
this.enderChest = player.getHandle().getEnderChest();
|
||||||
this.owner = player;
|
this.owner = player;
|
||||||
@@ -68,8 +69,7 @@ public class SpecialEnderChest extends InventorySubcontainer implements IInvento
|
|||||||
Field field = playerEnderChest.getClass().getField("items");
|
Field field = playerEnderChest.getClass().getField("items");
|
||||||
field.setAccessible(true);
|
field.setAccessible(true);
|
||||||
field.set(playerEnderChest, this.items);
|
field.set(playerEnderChest, this.items);
|
||||||
}
|
} catch (Exception e) {}
|
||||||
catch (Exception e) {}
|
|
||||||
playerOnline = true;
|
playerOnline = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
@@ -4,22 +4,17 @@
|
|||||||
|
|
||||||
<parent>
|
<parent>
|
||||||
<groupId>com.lishid</groupId>
|
<groupId>com.lishid</groupId>
|
||||||
<artifactId>openinvparent</artifactId>
|
<artifactId>openinvinternal</artifactId>
|
||||||
<version>1.0-SNAPSHOT</version>
|
<version>1.0-SNAPSHOT</version>
|
||||||
</parent>
|
</parent>
|
||||||
|
|
||||||
<artifactId>OpenInvCraftbukkit1_5_R2</artifactId>
|
<artifactId>openinvadapter1_5_R2</artifactId>
|
||||||
<name>OpenInvCraftbukkit1_5_R2</name>
|
<name>OpenInvAdapter1_5_R2</name>
|
||||||
|
|
||||||
<dependencies>
|
<dependencies>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>com.lishid</groupId>
|
<groupId>com.lishid</groupId>
|
||||||
<artifactId>openinvcore</artifactId>
|
<artifactId>openinvcommon</artifactId>
|
||||||
<version>1.0-SNAPSHOT</version>
|
|
||||||
</dependency>
|
|
||||||
<dependency>
|
|
||||||
<groupId>com.lishid</groupId>
|
|
||||||
<artifactId>openinvplugin</artifactId>
|
|
||||||
<version>1.0-SNAPSHOT</version>
|
<version>1.0-SNAPSHOT</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
@@ -29,4 +24,5 @@
|
|||||||
<scope>provided</scope>
|
<scope>provided</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
</dependencies>
|
</dependencies>
|
||||||
|
|
||||||
</project>
|
</project>
|
@@ -0,0 +1,158 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (C) 2011-2014 lishid. All rights reserved.
|
||||||
|
*
|
||||||
|
* This program is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation, version 3.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package com.lishid.openinv.internal.v1_5_R2;
|
||||||
|
|
||||||
|
import com.lishid.openinv.internal.IAnySilentContainer;
|
||||||
|
|
||||||
|
import org.bukkit.ChatColor;
|
||||||
|
import org.bukkit.Material;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
|
// Volatile
|
||||||
|
import net.minecraft.server.v1_5_R2.AxisAlignedBB;
|
||||||
|
import net.minecraft.server.v1_5_R2.BlockEnderChest;
|
||||||
|
import net.minecraft.server.v1_5_R2.EntityOcelot;
|
||||||
|
import net.minecraft.server.v1_5_R2.EntityPlayer;
|
||||||
|
import net.minecraft.server.v1_5_R2.IInventory;
|
||||||
|
import net.minecraft.server.v1_5_R2.InventoryEnderChest;
|
||||||
|
import net.minecraft.server.v1_5_R2.InventoryLargeChest;
|
||||||
|
import net.minecraft.server.v1_5_R2.Packet100OpenWindow;
|
||||||
|
import net.minecraft.server.v1_5_R2.TileEntityChest;
|
||||||
|
import net.minecraft.server.v1_5_R2.TileEntityEnderChest;
|
||||||
|
import net.minecraft.server.v1_5_R2.World;
|
||||||
|
|
||||||
|
import org.bukkit.craftbukkit.v1_5_R2.entity.CraftPlayer;
|
||||||
|
|
||||||
|
public class AnySilentContainer implements IAnySilentContainer {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isAnySilentContainer(org.bukkit.block.Block block) {
|
||||||
|
return block.getType() == Material.ENDER_CHEST || block.getState() instanceof org.bukkit.block.Chest;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isAnyContainerNeeded(Player p, org.bukkit.block.Block block) {
|
||||||
|
// FOR REFERENCE, LOOK AT net.minecraft.server.BlockChest
|
||||||
|
EntityPlayer player = ((CraftPlayer) p).getHandle();
|
||||||
|
World world = player.world;
|
||||||
|
|
||||||
|
if (block instanceof BlockEnderChest) {
|
||||||
|
// Ender chests are not blocked by ocelots.
|
||||||
|
return world.t(block.getX(), block.getY() + 1, block.getZ());
|
||||||
|
}
|
||||||
|
|
||||||
|
// If block or ocelot on top
|
||||||
|
if (isBlockedChest(world, block.getX(), block.getY() + 1, block.getZ())) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
int id = world.getTypeId(block.getX(), block.getY(), block.getZ());
|
||||||
|
|
||||||
|
// If block next to chest is chest and has a block or ocelot on top
|
||||||
|
if (world.getTypeId(block.getX(), block.getY(), block.getZ() + 1) == id) {
|
||||||
|
return isBlockedChest(world, block.getX(), block.getY() + 1, block.getZ() + 1);
|
||||||
|
} else if(world.getTypeId(block.getX(), block.getY(), block.getZ() - 1) == id) {
|
||||||
|
return isBlockedChest(world, block.getX(), block.getY() + 1, block.getZ() - 1);
|
||||||
|
} else if (world.getTypeId(block.getX() + 1, block.getY(), block.getZ()) == id) {
|
||||||
|
return isBlockedChest(world, block.getX() + 1, block.getY() + 1, block.getZ());
|
||||||
|
} else if (world.getTypeId(block.getX() - 1, block.getY(), block.getZ()) == id) {
|
||||||
|
return isBlockedChest(world, block.getX() - 1, block.getY() + 1, block.getZ());
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
private boolean isBlockedChest(World world, int x, int y, int z) {
|
||||||
|
return world.t(x, y + 1, z) || hasOcelotOnTop(world, x, y, z);
|
||||||
|
}
|
||||||
|
|
||||||
|
private boolean hasOcelotOnTop(World world, int x, int y, int z) {
|
||||||
|
for (Object localEntity : world.a(EntityOcelot.class,
|
||||||
|
AxisAlignedBB.a(x, y + 1, z, x + 1, y + 2, z + 1))) {
|
||||||
|
EntityOcelot localEntityOcelot = (EntityOcelot) localEntity;
|
||||||
|
if (localEntityOcelot.isSitting()) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean activateContainer(Player p, boolean silentchest, org.bukkit.block.Block block) {
|
||||||
|
|
||||||
|
EntityPlayer player = ((CraftPlayer) p).getHandle();
|
||||||
|
|
||||||
|
// Silent ender chest is API-only
|
||||||
|
if (silentchest && block.getType() == Material.ENDER_CHEST) {
|
||||||
|
p.openInventory(p.getEnderChest());
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
World world = player.world;
|
||||||
|
Object tile = world.getTileEntity(block.getX(), block.getY(), block.getZ());
|
||||||
|
|
||||||
|
if (tile == null) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (tile instanceof TileEntityEnderChest) {
|
||||||
|
// Anychest ender chest. See net.minecraft.server.BlockEnderChest
|
||||||
|
InventoryEnderChest enderChest = player.getEnderChest();
|
||||||
|
enderChest.a((TileEntityEnderChest) tile);
|
||||||
|
player.openContainer(enderChest);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!(tile instanceof IInventory)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
int id = world.getTypeId(block.getX(), block.getY(), block.getZ());
|
||||||
|
|
||||||
|
if (world.getTypeId(block.getX(), block.getY(), block.getZ() + 1) == id) {
|
||||||
|
tile = new InventoryLargeChest("Large chest", (IInventory) tile, (TileEntityChest) world.getTileEntity(block.getX(), block.getY(), block.getZ() + 1));
|
||||||
|
} else if (world.getTypeId(block.getX(), block.getY(), block.getZ() - 1) == id) {
|
||||||
|
tile = new InventoryLargeChest("Large chest", (TileEntityChest) world.getTileEntity(block.getX(), block.getY(), block.getZ() - 1), (IInventory) tile);
|
||||||
|
} else if (world.getTypeId(block.getX() + 1, block.getY(), block.getZ()) == id) {
|
||||||
|
tile = new InventoryLargeChest("Large chest", (IInventory) tile, (TileEntityChest) world.getTileEntity(block.getX() + 1, block.getY(), block.getZ()));
|
||||||
|
} else if (world.getTypeId(block.getX() - 1, block.getY(), block.getZ()) == id) {
|
||||||
|
tile = new InventoryLargeChest("Large chest", (TileEntityChest) world.getTileEntity(block.getX() - 1, block.getY(), block.getZ()), (IInventory) tile);
|
||||||
|
}
|
||||||
|
|
||||||
|
boolean returnValue = false;
|
||||||
|
if (!silentchest) {
|
||||||
|
player.openContainer((IInventory) tile);
|
||||||
|
returnValue = true;
|
||||||
|
} else {
|
||||||
|
try {
|
||||||
|
int windowId = player.nextContainerCounter();
|
||||||
|
player.playerConnection.sendPacket(new Packet100OpenWindow(windowId, 0, ((IInventory) tile).getName(), ((IInventory) tile).getSize(), true));
|
||||||
|
player.activeContainer = new SilentContainerChest(player.inventory, ((IInventory) tile));
|
||||||
|
player.activeContainer.windowId = windowId;
|
||||||
|
player.activeContainer.addSlotListener(player);
|
||||||
|
returnValue = true;
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
p.sendMessage(ChatColor.RED + "Error while sending silent chest.");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return returnValue;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user