diff --git a/internal/1_4_5/src/main/java/com/lishid/openinv/internal/v1_4_5/AnySilentContainer.java b/internal/1_4_5/src/main/java/com/lishid/openinv/internal/v1_4_5/AnySilentContainer.java index 3032f6f..be34e71 100644 --- a/internal/1_4_5/src/main/java/com/lishid/openinv/internal/v1_4_5/AnySilentContainer.java +++ b/internal/1_4_5/src/main/java/com/lishid/openinv/internal/v1_4_5/AnySilentContainer.java @@ -25,6 +25,7 @@ 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.Container; import net.minecraft.server.v1_4_5.EntityOcelot; import net.minecraft.server.v1_4_5.EntityPlayer; import net.minecraft.server.v1_4_5.IInventory; @@ -36,6 +37,7 @@ 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; +import org.bukkit.craftbukkit.v1_4_5.event.CraftEventFactory; public class AnySilentContainer implements IAnySilentContainer { @@ -122,37 +124,47 @@ public class AnySilentContainer implements IAnySilentContainer { return false; } + IInventory inventory = (IInventory) tile; 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)); + inventory = new InventoryLargeChest("container.chestDouble", inventory, (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); + inventory = new InventoryLargeChest("container.chestDouble", (TileEntityChest) world.getTileEntity(block.getX(), block.getY(), block.getZ() - 1), inventory); } 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())); + inventory = new InventoryLargeChest("container.chestDouble", inventory, (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); + inventory = new InventoryLargeChest("container.chestDouble", (TileEntityChest) world.getTileEntity(block.getX() - 1, block.getY(), block.getZ()), inventory); } - boolean returnValue = false; + // AnyChest only 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."); - } + player.openContainer(inventory); + return true; } - return returnValue; + // SilentChest + try { + // Call InventoryOpenEvent + Container container = new SilentContainerChest(player.inventory, inventory); + container = CraftEventFactory.callInventoryOpenEvent(player, container); + if (container == null) { + return false; + } + + // Open window + int windowId = player.nextContainerCounter(); + player.netServerHandler.sendPacket(new Packet100OpenWindow(windowId, 0, inventory.getName(), inventory.getSize())); + player.activeContainer = container; + player.activeContainer.windowId = windowId; + player.activeContainer.addSlotListener(player); + + return true; + } catch (Exception e) { + e.printStackTrace(); + p.sendMessage(ChatColor.RED + "Error while sending silent container."); + return false; + } } } diff --git a/internal/1_4_6/src/main/java/com/lishid/openinv/internal/v1_4_6/AnySilentContainer.java b/internal/1_4_6/src/main/java/com/lishid/openinv/internal/v1_4_6/AnySilentContainer.java index e0f7696..20a33a1 100644 --- a/internal/1_4_6/src/main/java/com/lishid/openinv/internal/v1_4_6/AnySilentContainer.java +++ b/internal/1_4_6/src/main/java/com/lishid/openinv/internal/v1_4_6/AnySilentContainer.java @@ -25,6 +25,7 @@ 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.Container; import net.minecraft.server.v1_4_6.EntityOcelot; import net.minecraft.server.v1_4_6.EntityPlayer; import net.minecraft.server.v1_4_6.IInventory; @@ -36,6 +37,7 @@ 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; +import org.bukkit.craftbukkit.v1_4_6.event.CraftEventFactory; public class AnySilentContainer implements IAnySilentContainer { @@ -122,37 +124,47 @@ public class AnySilentContainer implements IAnySilentContainer { return false; } + IInventory inventory = (IInventory) tile; 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)); + inventory = new InventoryLargeChest("container.chestDouble", inventory, (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); + inventory = new InventoryLargeChest("container.chestDouble", (TileEntityChest) world.getTileEntity(block.getX(), block.getY(), block.getZ() - 1), inventory); } 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())); + inventory = new InventoryLargeChest("container.chestDouble", inventory, (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); + inventory = new InventoryLargeChest("container.chestDouble", (TileEntityChest) world.getTileEntity(block.getX() - 1, block.getY(), block.getZ()), inventory); } - boolean returnValue = false; + // AnyChest only 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."); - } + player.openContainer(inventory); + return true; } - return returnValue; + // SilentChest + try { + // Call InventoryOpenEvent + Container container = new SilentContainerChest(player.inventory, inventory); + container = CraftEventFactory.callInventoryOpenEvent(player, container); + if (container == null) { + return false; + } + + // Open window + int windowId = player.nextContainerCounter(); + player.playerConnection.sendPacket(new Packet100OpenWindow(windowId, 0, inventory.getName(), inventory.getSize())); + player.activeContainer = container; + player.activeContainer.windowId = windowId; + player.activeContainer.addSlotListener(player); + + return true; + } catch (Exception e) { + e.printStackTrace(); + p.sendMessage(ChatColor.RED + "Error while sending silent container."); + return false; + } } } diff --git a/internal/v1_10_R1/src/main/java/com/lishid/openinv/internal/v1_10_R1/AnySilentContainer.java b/internal/v1_10_R1/src/main/java/com/lishid/openinv/internal/v1_10_R1/AnySilentContainer.java index 36c3ae9..8dca3aa 100644 --- a/internal/v1_10_R1/src/main/java/com/lishid/openinv/internal/v1_10_R1/AnySilentContainer.java +++ b/internal/v1_10_R1/src/main/java/com/lishid/openinv/internal/v1_10_R1/AnySilentContainer.java @@ -26,7 +26,6 @@ import org.bukkit.entity.Player; 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; @@ -34,7 +33,6 @@ 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; @@ -46,6 +44,7 @@ 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; +import org.bukkit.craftbukkit.v1_10_R1.event.CraftEventFactory; public class AnySilentContainer implements IAnySilentContainer { @@ -141,10 +140,11 @@ public class AnySilentContainer implements IAnySilentContainer { return true; } - if (!(tile instanceof IInventory)) { + if (!(tile instanceof ITileInventory)) { return false; } + ITileInventory tileInventory = (ITileInventory) tile; Block block = world.getType(blockPosition).getBlock(); Container container = null; @@ -163,47 +163,54 @@ public class AnySilentContainer implements IAnySilentContainer { } if ((localEnumDirection == EnumDirection.WEST) || (localEnumDirection == EnumDirection.NORTH)) { - tile = new InventoryLargeChest("container.chestDouble", - (TileEntityChest) localTileEntity, (ITileInventory) tile); + tileInventory = new InventoryLargeChest("container.chestDouble", + (TileEntityChest) localTileEntity, tileInventory); } else { - tile = new InventoryLargeChest("container.chestDouble", - (ITileInventory) tile, (TileEntityChest) localTileEntity); + tileInventory = new InventoryLargeChest("container.chestDouble", + tileInventory, (TileEntityChest) localTileEntity); } break; } - if (silentchest) { - container = new SilentContainerChest(player.inventory, ((IInventory) tile), player); - } - - if (((BlockChest) block).g == Type.BASIC) { + BlockChest blockChest = (BlockChest) block; + if (blockChest.g == BlockChest.Type.BASIC) { player.b(StatisticList.ac); - } else if (((BlockChest) block).g == Type.TRAP) { + } else if (blockChest.g == BlockChest.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."); + if (silentchest) { + container = new SilentContainerChest(player.inventory, tileInventory, player); } } - return returnValue; + // AnyChest only - SilentChest not active or container unsupported + if (!silentchest || container == null) { + player.openContainer(tileInventory); + return true; + } + + // SilentChest + try { + // Call InventoryOpenEvent + container = CraftEventFactory.callInventoryOpenEvent(player, container, false); + if (container == null) { + return false; + } + + // Open window + int windowId = player.nextContainerCounter(); + player.playerConnection.sendPacket(new PacketPlayOutOpenWindow(windowId, tileInventory.getContainerName(), tileInventory.getScoreboardDisplayName(), tileInventory.getSize())); + player.activeContainer = container; + player.activeContainer.windowId = windowId; + player.activeContainer.addSlotListener(player); + + return true; + } catch (Exception e) { + e.printStackTrace(); + p.sendMessage(ChatColor.RED + "Error while sending silent container."); + return false; + } } } diff --git a/internal/v1_11_R1/src/main/java/com/lishid/openinv/internal/v1_11_R1/AnySilentContainer.java b/internal/v1_11_R1/src/main/java/com/lishid/openinv/internal/v1_11_R1/AnySilentContainer.java index 5028fb9..5464f35 100644 --- a/internal/v1_11_R1/src/main/java/com/lishid/openinv/internal/v1_11_R1/AnySilentContainer.java +++ b/internal/v1_11_R1/src/main/java/com/lishid/openinv/internal/v1_11_R1/AnySilentContainer.java @@ -29,7 +29,6 @@ import org.bukkit.scheduler.BukkitRunnable; import net.minecraft.server.v1_11_R1.AxisAlignedBB; import net.minecraft.server.v1_11_R1.Block; import net.minecraft.server.v1_11_R1.BlockChest; -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.BlockShulkerBox; @@ -51,6 +50,7 @@ import net.minecraft.server.v1_11_R1.TileEntityShulkerBox; import net.minecraft.server.v1_11_R1.World; import org.bukkit.craftbukkit.v1_11_R1.entity.CraftPlayer; +import org.bukkit.craftbukkit.v1_11_R1.event.CraftEventFactory; public class AnySilentContainer implements IAnySilentContainer { @@ -187,13 +187,10 @@ public class AnySilentContainer implements IAnySilentContainer { } ITileInventory tileInventory = (ITileInventory) tile; - 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(); @@ -217,9 +214,10 @@ public class AnySilentContainer implements IAnySilentContainer { break; } - if (blockChest.g == Type.BASIC) { + BlockChest blockChest = (BlockChest) block; + if (blockChest.g == BlockChest.Type.BASIC) { player.b(StatisticList.getStatistic("stat.chestOpened")); - } else if (blockChest.g == Type.TRAP) { + } else if (blockChest.g == BlockChest.Type.TRAP) { player.b(StatisticList.getStatistic("stat.trappedChestTriggered")); } @@ -240,42 +238,51 @@ public class AnySilentContainer implements IAnySilentContainer { } } - boolean returnValue = false; - + // AnyChest only - SilentChest not active or container unsupported if (!silentchest || container == null) { player.openContainer(tileInventory); - returnValue = true; - } else { - try { - int windowId = player.nextContainerCounter(); - player.playerConnection.sendPacket(new PacketPlayOutOpenWindow(windowId, tileInventory.getContainerName(), tileInventory.getScoreboardDisplayName(), tileInventory.getSize())); - player.activeContainer = container; - player.activeContainer.windowId = windowId; - player.activeContainer.addSlotListener(player); - returnValue = true; - if (tile instanceof TileEntityShulkerBox) { - new BukkitRunnable() { - @Override - public void run() { - // 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 true; } - return returnValue; + // SilentChest + try { + // Call InventoryOpenEvent + container = CraftEventFactory.callInventoryOpenEvent(player, container, false); + if (container == null) { + return false; + } + + // Open window + int windowId = player.nextContainerCounter(); + player.playerConnection.sendPacket(new PacketPlayOutOpenWindow(windowId, tileInventory.getContainerName(), tileInventory.getScoreboardDisplayName(), tileInventory.getSize())); + player.activeContainer = container; + player.activeContainer.windowId = windowId; + player.activeContainer.addSlotListener(player); + + // Special handling for shulker boxes - reset value for viewers to what it was initially. + if (tile instanceof TileEntityShulkerBox) { + new BukkitRunnable() { + @Override + public void run() { + // 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); + } + + return true; + } catch (Exception e) { + e.printStackTrace(); + p.sendMessage(ChatColor.RED + "Error while sending silent container."); + return false; + } } } diff --git a/internal/v1_4_R1/src/main/java/com/lishid/openinv/internal/v1_4_R1/AnySilentContainer.java b/internal/v1_4_R1/src/main/java/com/lishid/openinv/internal/v1_4_R1/AnySilentContainer.java index b08e28d..ec1e7b6 100644 --- a/internal/v1_4_R1/src/main/java/com/lishid/openinv/internal/v1_4_R1/AnySilentContainer.java +++ b/internal/v1_4_R1/src/main/java/com/lishid/openinv/internal/v1_4_R1/AnySilentContainer.java @@ -25,6 +25,7 @@ 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.Container; import net.minecraft.server.v1_4_R1.EntityOcelot; import net.minecraft.server.v1_4_R1.EntityPlayer; import net.minecraft.server.v1_4_R1.IInventory; @@ -36,6 +37,7 @@ 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; +import org.bukkit.craftbukkit.v1_4_R1.event.CraftEventFactory; public class AnySilentContainer implements IAnySilentContainer { @@ -122,37 +124,47 @@ public class AnySilentContainer implements IAnySilentContainer { return false; } + IInventory inventory = (IInventory) tile; 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)); + inventory = new InventoryLargeChest("container.chestDouble", inventory, (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); + inventory = new InventoryLargeChest("container.chestDouble", (TileEntityChest) world.getTileEntity(block.getX(), block.getY(), block.getZ() - 1), inventory); } 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())); + inventory = new InventoryLargeChest("container.chestDouble", inventory, (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); + inventory = new InventoryLargeChest("container.chestDouble", (TileEntityChest) world.getTileEntity(block.getX() - 1, block.getY(), block.getZ()), inventory); } - boolean returnValue = false; + // AnyChest only 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."); - } + player.openContainer(inventory); + return true; } - return returnValue; + // SilentChest + try { + // Call InventoryOpenEvent + Container container = new SilentContainerChest(player.inventory, inventory); + container = CraftEventFactory.callInventoryOpenEvent(player, container); + if (container == null) { + return false; + } + + // Open window + int windowId = player.nextContainerCounter(); + player.playerConnection.sendPacket(new Packet100OpenWindow(windowId, 0, inventory.getName(), inventory.getSize())); + player.activeContainer = container; + player.activeContainer.windowId = windowId; + player.activeContainer.addSlotListener(player); + + return true; + } catch (Exception e) { + e.printStackTrace(); + p.sendMessage(ChatColor.RED + "Error while sending silent container."); + return false; + } } } diff --git a/internal/v1_5_R2/src/main/java/com/lishid/openinv/internal/v1_5_R2/AnySilentContainer.java b/internal/v1_5_R2/src/main/java/com/lishid/openinv/internal/v1_5_R2/AnySilentContainer.java index c08b41c..5cb2c26 100644 --- a/internal/v1_5_R2/src/main/java/com/lishid/openinv/internal/v1_5_R2/AnySilentContainer.java +++ b/internal/v1_5_R2/src/main/java/com/lishid/openinv/internal/v1_5_R2/AnySilentContainer.java @@ -25,6 +25,7 @@ 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.Container; import net.minecraft.server.v1_5_R2.EntityOcelot; import net.minecraft.server.v1_5_R2.EntityPlayer; import net.minecraft.server.v1_5_R2.IInventory; @@ -36,6 +37,7 @@ 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; +import org.bukkit.craftbukkit.v1_5_R2.event.CraftEventFactory; public class AnySilentContainer implements IAnySilentContainer { @@ -122,37 +124,47 @@ public class AnySilentContainer implements IAnySilentContainer { return false; } + IInventory inventory = (IInventory) tile; 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)); + inventory = new InventoryLargeChest("container.chestDouble", inventory, (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); + inventory = new InventoryLargeChest("container.chestDouble", (TileEntityChest) world.getTileEntity(block.getX(), block.getY(), block.getZ() - 1), inventory); } 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())); + inventory = new InventoryLargeChest("container.chestDouble", inventory, (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); + inventory = new InventoryLargeChest("container.chestDouble", (TileEntityChest) world.getTileEntity(block.getX() - 1, block.getY(), block.getZ()), inventory); } - boolean returnValue = false; + // AnyChest only 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."); - } + player.openContainer(inventory); + return true; } - return returnValue; + // SilentChest + try { + // Call InventoryOpenEvent + Container container = new SilentContainerChest(player.inventory, inventory); + container = CraftEventFactory.callInventoryOpenEvent(player, container); + if (container == null) { + return false; + } + + // Open window + int windowId = player.nextContainerCounter(); + player.playerConnection.sendPacket(new Packet100OpenWindow(windowId, 0, inventory.getName(), inventory.getSize(), true)); + player.activeContainer = container; + player.activeContainer.windowId = windowId; + player.activeContainer.addSlotListener(player); + + return true; + } catch (Exception e) { + e.printStackTrace(); + p.sendMessage(ChatColor.RED + "Error while sending silent container."); + return false; + } } } diff --git a/internal/v1_5_R3/src/main/java/com/lishid/openinv/internal/v1_5_R3/AnySilentContainer.java b/internal/v1_5_R3/src/main/java/com/lishid/openinv/internal/v1_5_R3/AnySilentContainer.java index ee10a6f..7d011a0 100644 --- a/internal/v1_5_R3/src/main/java/com/lishid/openinv/internal/v1_5_R3/AnySilentContainer.java +++ b/internal/v1_5_R3/src/main/java/com/lishid/openinv/internal/v1_5_R3/AnySilentContainer.java @@ -25,6 +25,7 @@ import org.bukkit.entity.Player; //Volatile import net.minecraft.server.v1_5_R3.AxisAlignedBB; import net.minecraft.server.v1_5_R3.BlockEnderChest; +import net.minecraft.server.v1_5_R3.Container; import net.minecraft.server.v1_5_R3.EntityOcelot; import net.minecraft.server.v1_5_R3.EntityPlayer; import net.minecraft.server.v1_5_R3.IInventory; @@ -36,6 +37,7 @@ import net.minecraft.server.v1_5_R3.TileEntityEnderChest; import net.minecraft.server.v1_5_R3.World; import org.bukkit.craftbukkit.v1_5_R3.entity.CraftPlayer; +import org.bukkit.craftbukkit.v1_5_R3.event.CraftEventFactory; public class AnySilentContainer implements IAnySilentContainer { @@ -122,37 +124,47 @@ public class AnySilentContainer implements IAnySilentContainer { return false; } + IInventory inventory = (IInventory) tile; 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)); + inventory = new InventoryLargeChest("container.chestDouble", inventory, (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); + inventory = new InventoryLargeChest("container.chestDouble", (TileEntityChest) world.getTileEntity(block.getX(), block.getY(), block.getZ() - 1), inventory); } 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())); + inventory = new InventoryLargeChest("container.chestDouble", inventory, (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); + inventory = new InventoryLargeChest("container.chestDouble", (TileEntityChest) world.getTileEntity(block.getX() - 1, block.getY(), block.getZ()), inventory); } - boolean returnValue = false; + // AnyChest only 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."); - } + player.openContainer(inventory); + return true; } - return returnValue; + // SilentChest + try { + // Call InventoryOpenEvent + Container container = new SilentContainerChest(player.inventory, inventory); + container = CraftEventFactory.callInventoryOpenEvent(player, container); + if (container == null) { + return false; + } + + // Open window + int windowId = player.nextContainerCounter(); + player.playerConnection.sendPacket(new Packet100OpenWindow(windowId, 0, inventory.getName(), inventory.getSize(), true)); + player.activeContainer = container; + player.activeContainer.windowId = windowId; + player.activeContainer.addSlotListener(player); + + return true; + } catch (Exception e) { + e.printStackTrace(); + p.sendMessage(ChatColor.RED + "Error while sending silent container."); + return false; + } } } diff --git a/internal/v1_6_R1/src/main/java/com/lishid/openinv/internal/v1_6_R1/AnySilentContainer.java b/internal/v1_6_R1/src/main/java/com/lishid/openinv/internal/v1_6_R1/AnySilentContainer.java index 87c46d6..1a79320 100644 --- a/internal/v1_6_R1/src/main/java/com/lishid/openinv/internal/v1_6_R1/AnySilentContainer.java +++ b/internal/v1_6_R1/src/main/java/com/lishid/openinv/internal/v1_6_R1/AnySilentContainer.java @@ -25,6 +25,7 @@ import org.bukkit.entity.Player; // Volatile import net.minecraft.server.v1_6_R1.AxisAlignedBB; import net.minecraft.server.v1_6_R1.BlockEnderChest; +import net.minecraft.server.v1_6_R1.Container; import net.minecraft.server.v1_6_R1.EntityOcelot; import net.minecraft.server.v1_6_R1.EntityPlayer; import net.minecraft.server.v1_6_R1.IInventory; @@ -36,6 +37,7 @@ import net.minecraft.server.v1_6_R1.TileEntityEnderChest; import net.minecraft.server.v1_6_R1.World; import org.bukkit.craftbukkit.v1_6_R1.entity.CraftPlayer; +import org.bukkit.craftbukkit.v1_6_R1.event.CraftEventFactory; public class AnySilentContainer implements IAnySilentContainer { @@ -122,37 +124,47 @@ public class AnySilentContainer implements IAnySilentContainer { return false; } + IInventory inventory = (IInventory) tile; 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)); + inventory = new InventoryLargeChest("container.chestDouble", inventory, (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); + inventory = new InventoryLargeChest("container.chestDouble", (TileEntityChest) world.getTileEntity(block.getX(), block.getY(), block.getZ() - 1), inventory); } 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())); + inventory = new InventoryLargeChest("container.chestDouble", inventory, (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); + inventory = new InventoryLargeChest("container.chestDouble", (TileEntityChest) world.getTileEntity(block.getX() - 1, block.getY(), block.getZ()), inventory); } - boolean returnValue = false; + // AnyChest only 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."); - } + player.openContainer(inventory); + return true; } - return returnValue; + // SilentChest + try { + // Call InventoryOpenEvent + Container container = new SilentContainerChest(player.inventory, inventory); + container = CraftEventFactory.callInventoryOpenEvent(player, container); + if (container == null) { + return false; + } + + // Open window + int windowId = player.nextContainerCounter(); + player.playerConnection.sendPacket(new Packet100OpenWindow(windowId, 0, inventory.getName(), inventory.getSize(), true)); + player.activeContainer = container; + player.activeContainer.windowId = windowId; + player.activeContainer.addSlotListener(player); + + return true; + } catch (Exception e) { + e.printStackTrace(); + p.sendMessage(ChatColor.RED + "Error while sending silent container."); + return false; + } } } diff --git a/internal/v1_6_R2/src/main/java/com/lishid/openinv/internal/v1_6_R2/AnySilentContainer.java b/internal/v1_6_R2/src/main/java/com/lishid/openinv/internal/v1_6_R2/AnySilentContainer.java index acdef19..ab1ff97 100644 --- a/internal/v1_6_R2/src/main/java/com/lishid/openinv/internal/v1_6_R2/AnySilentContainer.java +++ b/internal/v1_6_R2/src/main/java/com/lishid/openinv/internal/v1_6_R2/AnySilentContainer.java @@ -25,6 +25,7 @@ import org.bukkit.entity.Player; // Volatile import net.minecraft.server.v1_6_R2.AxisAlignedBB; import net.minecraft.server.v1_6_R2.BlockEnderChest; +import net.minecraft.server.v1_6_R2.Container; import net.minecraft.server.v1_6_R2.EntityOcelot; import net.minecraft.server.v1_6_R2.EntityPlayer; import net.minecraft.server.v1_6_R2.IInventory; @@ -36,6 +37,7 @@ import net.minecraft.server.v1_6_R2.TileEntityEnderChest; import net.minecraft.server.v1_6_R2.World; import org.bukkit.craftbukkit.v1_6_R2.entity.CraftPlayer; +import org.bukkit.craftbukkit.v1_6_R2.event.CraftEventFactory; public class AnySilentContainer implements IAnySilentContainer { @@ -122,37 +124,47 @@ public class AnySilentContainer implements IAnySilentContainer { return false; } + IInventory inventory = (IInventory) tile; 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)); + inventory = new InventoryLargeChest("container.chestDouble", inventory, (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); + inventory = new InventoryLargeChest("container.chestDouble", (TileEntityChest) world.getTileEntity(block.getX(), block.getY(), block.getZ() - 1), inventory); } 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())); + inventory = new InventoryLargeChest("container.chestDouble", inventory, (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); + inventory = new InventoryLargeChest("container.chestDouble", (TileEntityChest) world.getTileEntity(block.getX() - 1, block.getY(), block.getZ()), inventory); } - boolean returnValue = false; + // AnyChest only 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."); - } + player.openContainer(inventory); + return true; } - return returnValue; + // SilentChest + try { + // Call InventoryOpenEvent + Container container = new SilentContainerChest(player.inventory, inventory); + container = CraftEventFactory.callInventoryOpenEvent(player, container); + if (container == null) { + return false; + } + + // Open window + int windowId = player.nextContainerCounter(); + player.playerConnection.sendPacket(new Packet100OpenWindow(windowId, 0, inventory.getName(), inventory.getSize(), true)); + player.activeContainer = container; + player.activeContainer.windowId = windowId; + player.activeContainer.addSlotListener(player); + + return true; + } catch (Exception e) { + e.printStackTrace(); + p.sendMessage(ChatColor.RED + "Error while sending silent container."); + return false; + } } } diff --git a/internal/v1_6_R3/src/main/java/com/lishid/openinv/internal/v1_6_R3/AnySilentContainer.java b/internal/v1_6_R3/src/main/java/com/lishid/openinv/internal/v1_6_R3/AnySilentContainer.java index ce37031..d97d39d 100644 --- a/internal/v1_6_R3/src/main/java/com/lishid/openinv/internal/v1_6_R3/AnySilentContainer.java +++ b/internal/v1_6_R3/src/main/java/com/lishid/openinv/internal/v1_6_R3/AnySilentContainer.java @@ -25,6 +25,7 @@ import org.bukkit.entity.Player; // Volatile import net.minecraft.server.v1_6_R3.AxisAlignedBB; import net.minecraft.server.v1_6_R3.BlockEnderChest; +import net.minecraft.server.v1_6_R3.Container; import net.minecraft.server.v1_6_R3.EntityOcelot; import net.minecraft.server.v1_6_R3.EntityPlayer; import net.minecraft.server.v1_6_R3.IInventory; @@ -36,6 +37,7 @@ import net.minecraft.server.v1_6_R3.TileEntityEnderChest; import net.minecraft.server.v1_6_R3.World; import org.bukkit.craftbukkit.v1_6_R3.entity.CraftPlayer; +import org.bukkit.craftbukkit.v1_6_R3.event.CraftEventFactory; public class AnySilentContainer implements IAnySilentContainer { @@ -122,37 +124,47 @@ public class AnySilentContainer implements IAnySilentContainer { return false; } + IInventory inventory = (IInventory) tile; 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)); + inventory = new InventoryLargeChest("container.chestDouble", inventory, (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); + inventory = new InventoryLargeChest("container.chestDouble", (TileEntityChest) world.getTileEntity(block.getX(), block.getY(), block.getZ() - 1), inventory); } 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())); + inventory = new InventoryLargeChest("container.chestDouble", inventory, (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); + inventory = new InventoryLargeChest("container.chestDouble", (TileEntityChest) world.getTileEntity(block.getX() - 1, block.getY(), block.getZ()), inventory); } - boolean returnValue = false; + // AnyChest only 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."); - } + player.openContainer(inventory); + return true; } - return returnValue; + // SilentChest + try { + // Call InventoryOpenEvent + Container container = new SilentContainerChest(player.inventory, inventory); + container = CraftEventFactory.callInventoryOpenEvent(player, container); + if (container == null) { + return false; + } + + // Open window + int windowId = player.nextContainerCounter(); + player.playerConnection.sendPacket(new Packet100OpenWindow(windowId, 0, inventory.getName(), inventory.getSize(), true)); + player.activeContainer = container; + player.activeContainer.windowId = windowId; + player.activeContainer.addSlotListener(player); + + return true; + } catch (Exception e) { + e.printStackTrace(); + p.sendMessage(ChatColor.RED + "Error while sending silent container."); + return false; + } } } diff --git a/internal/v1_7_R1/src/main/java/com/lishid/openinv/internal/v1_7_R1/AnySilentContainer.java b/internal/v1_7_R1/src/main/java/com/lishid/openinv/internal/v1_7_R1/AnySilentContainer.java index 33d70e7..c9e82a1 100644 --- a/internal/v1_7_R1/src/main/java/com/lishid/openinv/internal/v1_7_R1/AnySilentContainer.java +++ b/internal/v1_7_R1/src/main/java/com/lishid/openinv/internal/v1_7_R1/AnySilentContainer.java @@ -26,6 +26,7 @@ import org.bukkit.entity.Player; import net.minecraft.server.v1_7_R1.AxisAlignedBB; import net.minecraft.server.v1_7_R1.Block; import net.minecraft.server.v1_7_R1.BlockEnderChest; +import net.minecraft.server.v1_7_R1.Container; import net.minecraft.server.v1_7_R1.EntityOcelot; import net.minecraft.server.v1_7_R1.EntityPlayer; import net.minecraft.server.v1_7_R1.IInventory; @@ -37,6 +38,7 @@ import net.minecraft.server.v1_7_R1.TileEntityEnderChest; import net.minecraft.server.v1_7_R1.World; import org.bukkit.craftbukkit.v1_7_R1.entity.CraftPlayer; +import org.bukkit.craftbukkit.v1_7_R1.event.CraftEventFactory; public class AnySilentContainer implements IAnySilentContainer { @@ -123,37 +125,47 @@ public class AnySilentContainer implements IAnySilentContainer { return false; } + IInventory inventory = (IInventory) tile; int id = Block.b(world.getType(block.getX(), block.getY(), block.getZ())); if (Block.b(world.getType(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)); + inventory = new InventoryLargeChest("container.chestDouble", inventory, (TileEntityChest) world.getTileEntity(block.getX(), block.getY(), block.getZ() + 1)); } else if(Block.b(world.getType(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); + inventory = new InventoryLargeChest("container.chestDouble", (TileEntityChest) world.getTileEntity(block.getX(), block.getY(), block.getZ() - 1), inventory); } else if (Block.b(world.getType(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())); + inventory = new InventoryLargeChest("container.chestDouble", inventory, (TileEntityChest) world.getTileEntity(block.getX() + 1, block.getY(), block.getZ())); } else if (Block.b(world.getType(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); + inventory = new InventoryLargeChest("container.chestDouble", (TileEntityChest) world.getTileEntity(block.getX() - 1, block.getY(), block.getZ()), inventory); } - boolean returnValue = false; + // AnyChest only if (!silentchest) { - player.openContainer((IInventory) tile); - returnValue = true; - } else { - try { - int windowId = player.nextContainerCounter(); - player.playerConnection.sendPacket(new PacketPlayOutOpenWindow(windowId, 0, ((IInventory) tile).getInventoryName(), ((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."); - } + player.openContainer(inventory); + return true; } - return returnValue; + // SilentChest + try { + // Call InventoryOpenEvent + Container container = new SilentContainerChest(player.inventory, inventory); + container = CraftEventFactory.callInventoryOpenEvent(player, container); + if (container == null) { + return false; + } + + // Open window + int windowId = player.nextContainerCounter(); + player.playerConnection.sendPacket(new PacketPlayOutOpenWindow(windowId, 0, inventory.getInventoryName(), inventory.getSize(), true)); + player.activeContainer = container; + player.activeContainer.windowId = windowId; + player.activeContainer.addSlotListener(player); + + return true; + } catch (Exception e) { + e.printStackTrace(); + p.sendMessage(ChatColor.RED + "Error while sending silent container."); + return false; + } } } diff --git a/internal/v1_7_R2/src/main/java/com/lishid/openinv/internal/v1_7_R2/AnySilentContainer.java b/internal/v1_7_R2/src/main/java/com/lishid/openinv/internal/v1_7_R2/AnySilentContainer.java index 886fa11..ddd5e43 100644 --- a/internal/v1_7_R2/src/main/java/com/lishid/openinv/internal/v1_7_R2/AnySilentContainer.java +++ b/internal/v1_7_R2/src/main/java/com/lishid/openinv/internal/v1_7_R2/AnySilentContainer.java @@ -26,6 +26,7 @@ import org.bukkit.entity.Player; import net.minecraft.server.v1_7_R2.AxisAlignedBB; import net.minecraft.server.v1_7_R2.Block; import net.minecraft.server.v1_7_R2.BlockEnderChest; +import net.minecraft.server.v1_7_R2.Container; import net.minecraft.server.v1_7_R2.EntityOcelot; import net.minecraft.server.v1_7_R2.EntityPlayer; import net.minecraft.server.v1_7_R2.IInventory; @@ -37,6 +38,7 @@ import net.minecraft.server.v1_7_R2.TileEntityEnderChest; import net.minecraft.server.v1_7_R2.World; import org.bukkit.craftbukkit.v1_7_R2.entity.CraftPlayer; +import org.bukkit.craftbukkit.v1_7_R2.event.CraftEventFactory; public class AnySilentContainer implements IAnySilentContainer { @@ -123,37 +125,47 @@ public class AnySilentContainer implements IAnySilentContainer { return false; } + IInventory inventory = (IInventory) tile; int id = Block.b(world.getType(block.getX(), block.getY(), block.getZ())); if (Block.b(world.getType(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)); + inventory = new InventoryLargeChest("container.chestDouble", inventory, (TileEntityChest) world.getTileEntity(block.getX(), block.getY(), block.getZ() + 1)); } else if(Block.b(world.getType(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); + inventory = new InventoryLargeChest("container.chestDouble", (TileEntityChest) world.getTileEntity(block.getX(), block.getY(), block.getZ() - 1), inventory); } else if (Block.b(world.getType(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())); + inventory = new InventoryLargeChest("container.chestDouble", inventory, (TileEntityChest) world.getTileEntity(block.getX() + 1, block.getY(), block.getZ())); } else if (Block.b(world.getType(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); + inventory = new InventoryLargeChest("container.chestDouble", (TileEntityChest) world.getTileEntity(block.getX() - 1, block.getY(), block.getZ()), inventory); } - boolean returnValue = false; + // AnyChest only if (!silentchest) { - player.openContainer((IInventory) tile); - returnValue = true; - } else { - try { - int windowId = player.nextContainerCounter(); - player.playerConnection.sendPacket(new PacketPlayOutOpenWindow(windowId, 0, ((IInventory) tile).getInventoryName(), ((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."); - } + player.openContainer(inventory); + return true; } - return returnValue; + // SilentChest + try { + // Call InventoryOpenEvent + Container container = new SilentContainerChest(player.inventory, inventory); + container = CraftEventFactory.callInventoryOpenEvent(player, container); + if (container == null) { + return false; + } + + // Open window + int windowId = player.nextContainerCounter(); + player.playerConnection.sendPacket(new PacketPlayOutOpenWindow(windowId, 0, inventory.getInventoryName(), inventory.getSize(), true)); + player.activeContainer = container; + player.activeContainer.windowId = windowId; + player.activeContainer.addSlotListener(player); + + return true; + } catch (Exception e) { + e.printStackTrace(); + p.sendMessage(ChatColor.RED + "Error while sending silent container."); + return false; + } } } diff --git a/internal/v1_7_R3/src/main/java/com/lishid/openinv/internal/v1_7_R3/AnySilentContainer.java b/internal/v1_7_R3/src/main/java/com/lishid/openinv/internal/v1_7_R3/AnySilentContainer.java index 3b9c651..d057b01 100644 --- a/internal/v1_7_R3/src/main/java/com/lishid/openinv/internal/v1_7_R3/AnySilentContainer.java +++ b/internal/v1_7_R3/src/main/java/com/lishid/openinv/internal/v1_7_R3/AnySilentContainer.java @@ -26,6 +26,7 @@ import org.bukkit.entity.Player; import net.minecraft.server.v1_7_R3.AxisAlignedBB; import net.minecraft.server.v1_7_R3.Block; import net.minecraft.server.v1_7_R3.BlockEnderChest; +import net.minecraft.server.v1_7_R3.Container; import net.minecraft.server.v1_7_R3.EntityOcelot; import net.minecraft.server.v1_7_R3.EntityPlayer; import net.minecraft.server.v1_7_R3.IInventory; @@ -37,6 +38,7 @@ import net.minecraft.server.v1_7_R3.TileEntityEnderChest; import net.minecraft.server.v1_7_R3.World; import org.bukkit.craftbukkit.v1_7_R3.entity.CraftPlayer; +import org.bukkit.craftbukkit.v1_7_R3.event.CraftEventFactory; public class AnySilentContainer implements IAnySilentContainer { @@ -123,37 +125,47 @@ public class AnySilentContainer implements IAnySilentContainer { return false; } + IInventory inventory = (IInventory) tile; int id = Block.b(world.getType(block.getX(), block.getY(), block.getZ())); if (Block.b(world.getType(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)); + inventory = new InventoryLargeChest("container.chestDouble", inventory, (TileEntityChest) world.getTileEntity(block.getX(), block.getY(), block.getZ() + 1)); } else if(Block.b(world.getType(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); + inventory = new InventoryLargeChest("container.chestDouble", (TileEntityChest) world.getTileEntity(block.getX(), block.getY(), block.getZ() - 1), inventory); } else if (Block.b(world.getType(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())); + inventory = new InventoryLargeChest("container.chestDouble", inventory, (TileEntityChest) world.getTileEntity(block.getX() + 1, block.getY(), block.getZ())); } else if (Block.b(world.getType(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); + inventory = new InventoryLargeChest("container.chestDouble", (TileEntityChest) world.getTileEntity(block.getX() - 1, block.getY(), block.getZ()), inventory); } - boolean returnValue = false; + // AnyChest only if (!silentchest) { - player.openContainer((IInventory) tile); - returnValue = true; - } else { - try { - int windowId = player.nextContainerCounter(); - player.playerConnection.sendPacket(new PacketPlayOutOpenWindow(windowId, 0, ((IInventory) tile).getInventoryName(), ((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."); - } + player.openContainer(inventory); + return true; } - return returnValue; + // SilentChest + try { + // Call InventoryOpenEvent + Container container = new SilentContainerChest(player.inventory, inventory); + container = CraftEventFactory.callInventoryOpenEvent(player, container); + if (container == null) { + return false; + } + + // Open window + int windowId = player.nextContainerCounter(); + player.playerConnection.sendPacket(new PacketPlayOutOpenWindow(windowId, 0, inventory.getInventoryName(), inventory.getSize(), true)); + player.activeContainer = container; + player.activeContainer.windowId = windowId; + player.activeContainer.addSlotListener(player); + + return true; + } catch (Exception e) { + e.printStackTrace(); + p.sendMessage(ChatColor.RED + "Error while sending silent container."); + return false; + } } } diff --git a/internal/v1_7_R4/src/main/java/com/lishid/openinv/internal/v1_7_R4/AnySilentContainer.java b/internal/v1_7_R4/src/main/java/com/lishid/openinv/internal/v1_7_R4/AnySilentContainer.java index 7f804ed..0b2b855 100644 --- a/internal/v1_7_R4/src/main/java/com/lishid/openinv/internal/v1_7_R4/AnySilentContainer.java +++ b/internal/v1_7_R4/src/main/java/com/lishid/openinv/internal/v1_7_R4/AnySilentContainer.java @@ -26,6 +26,7 @@ import org.bukkit.entity.Player; import net.minecraft.server.v1_7_R4.AxisAlignedBB; import net.minecraft.server.v1_7_R4.Block; import net.minecraft.server.v1_7_R4.BlockEnderChest; +import net.minecraft.server.v1_7_R4.Container; import net.minecraft.server.v1_7_R4.EntityOcelot; import net.minecraft.server.v1_7_R4.EntityPlayer; import net.minecraft.server.v1_7_R4.IInventory; @@ -37,6 +38,7 @@ import net.minecraft.server.v1_7_R4.TileEntityEnderChest; import net.minecraft.server.v1_7_R4.World; import org.bukkit.craftbukkit.v1_7_R4.entity.CraftPlayer; +import org.bukkit.craftbukkit.v1_7_R4.event.CraftEventFactory; public class AnySilentContainer implements IAnySilentContainer { @@ -123,37 +125,47 @@ public class AnySilentContainer implements IAnySilentContainer { return false; } + IInventory inventory = (IInventory) tile; int id = Block.getId(world.getType(block.getX(), block.getY(), block.getZ())); if (Block.getId(world.getType(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)); + inventory = new InventoryLargeChest("container.chestDouble", inventory, (TileEntityChest) world.getTileEntity(block.getX(), block.getY(), block.getZ() + 1)); } else if(Block.getId(world.getType(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); + inventory = new InventoryLargeChest("container.chestDouble", (TileEntityChest) world.getTileEntity(block.getX(), block.getY(), block.getZ() - 1), inventory); } else if (Block.getId(world.getType(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())); + inventory = new InventoryLargeChest("container.chestDouble", inventory, (TileEntityChest) world.getTileEntity(block.getX() + 1, block.getY(), block.getZ())); } else if (Block.getId(world.getType(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); + inventory = new InventoryLargeChest("container.chestDouble", (TileEntityChest) world.getTileEntity(block.getX() - 1, block.getY(), block.getZ()), inventory); } - boolean returnValue = false; + // AnyChest only if (!silentchest) { - player.openContainer((IInventory) tile); - returnValue = true; - } else { - try { - int windowId = player.nextContainerCounter(); - player.playerConnection.sendPacket(new PacketPlayOutOpenWindow(windowId, 0, ((IInventory) tile).getInventoryName(), ((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."); - } + player.openContainer(inventory); + return true; } - return returnValue; + // SilentChest + try { + // Call InventoryOpenEvent + Container container = new SilentContainerChest(player.inventory, inventory); + container = CraftEventFactory.callInventoryOpenEvent(player, container); + if (container == null) { + return false; + } + + // Open window + int windowId = player.nextContainerCounter(); + player.playerConnection.sendPacket(new PacketPlayOutOpenWindow(windowId, 0, inventory.getInventoryName(), inventory.getSize(), true)); + player.activeContainer = container; + player.activeContainer.windowId = windowId; + player.activeContainer.addSlotListener(player); + + return true; + } catch (Exception e) { + e.printStackTrace(); + p.sendMessage(ChatColor.RED + "Error while sending silent container."); + return false; + } } } diff --git a/internal/v1_8_R1/src/main/java/com/lishid/openinv/internal/v1_8_R1/AnySilentContainer.java b/internal/v1_8_R1/src/main/java/com/lishid/openinv/internal/v1_8_R1/AnySilentContainer.java index a3768e1..9b2ea34 100644 --- a/internal/v1_8_R1/src/main/java/com/lishid/openinv/internal/v1_8_R1/AnySilentContainer.java +++ b/internal/v1_8_R1/src/main/java/com/lishid/openinv/internal/v1_8_R1/AnySilentContainer.java @@ -32,7 +32,6 @@ import net.minecraft.server.v1_8_R1.Container; import net.minecraft.server.v1_8_R1.EntityOcelot; import net.minecraft.server.v1_8_R1.EntityPlayer; import net.minecraft.server.v1_8_R1.EnumDirection; -import net.minecraft.server.v1_8_R1.IInventory; import net.minecraft.server.v1_8_R1.ITileInventory; import net.minecraft.server.v1_8_R1.InventoryEnderChest; import net.minecraft.server.v1_8_R1.InventoryLargeChest; @@ -43,6 +42,7 @@ import net.minecraft.server.v1_8_R1.TileEntityEnderChest; import net.minecraft.server.v1_8_R1.World; import org.bukkit.craftbukkit.v1_8_R1.entity.CraftPlayer; +import org.bukkit.craftbukkit.v1_8_R1.event.CraftEventFactory; public class AnySilentContainer implements IAnySilentContainer { @@ -141,10 +141,11 @@ public class AnySilentContainer implements IAnySilentContainer { return true; } - if (!(tile instanceof IInventory)) { + if (!(tile instanceof ITileInventory)) { return false; } + ITileInventory tileInventory = (ITileInventory) tile; Block block = world.getType(blockPosition).getBlock(); Container container = null; @@ -168,41 +169,47 @@ public class AnySilentContainer implements IAnySilentContainer { } if ((localEnumDirection == EnumDirection.WEST) || (localEnumDirection == EnumDirection.NORTH)) { - tile = new InventoryLargeChest("container.chestDouble", - (TileEntityChest) localTileEntity, (ITileInventory) tile); + tileInventory = new InventoryLargeChest("container.chestDouble", + (TileEntityChest) localTileEntity, tileInventory); } else { - tile = new InventoryLargeChest("container.chestDouble", - (ITileInventory) tile, (TileEntityChest) localTileEntity); + tileInventory = new InventoryLargeChest("container.chestDouble", + tileInventory, (TileEntityChest) localTileEntity); } break; } if (silentchest) { - container = new SilentContainerChest(player.inventory, ((IInventory) tile), player); + container = new SilentContainerChest(player.inventory, tileInventory, player); } } - boolean returnValue = false; - final IInventory iInventory = (IInventory) tile; - + // AnyChest only - SilentChest not active or container unsupported 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."); - } + player.openContainer(tileInventory); + return true; } - return returnValue; + // SilentChest + try { + // Call InventoryOpenEvent + container = CraftEventFactory.callInventoryOpenEvent(player, container, false); + if (container == null) { + return false; + } + + // Open window + int windowId = player.nextContainerCounter(); + player.playerConnection.sendPacket(new PacketPlayOutOpenWindow(windowId, tileInventory.getContainerName(), tileInventory.getScoreboardDisplayName(), tileInventory.getSize())); + player.activeContainer = container; + player.activeContainer.windowId = windowId; + player.activeContainer.addSlotListener(player); + + return true; + } catch (Exception e) { + e.printStackTrace(); + p.sendMessage(ChatColor.RED + "Error while sending silent container."); + return false; + } } } diff --git a/internal/v1_8_R2/src/main/java/com/lishid/openinv/internal/v1_8_R2/AnySilentContainer.java b/internal/v1_8_R2/src/main/java/com/lishid/openinv/internal/v1_8_R2/AnySilentContainer.java index 564fdcc..eeb18af 100644 --- a/internal/v1_8_R2/src/main/java/com/lishid/openinv/internal/v1_8_R2/AnySilentContainer.java +++ b/internal/v1_8_R2/src/main/java/com/lishid/openinv/internal/v1_8_R2/AnySilentContainer.java @@ -33,7 +33,6 @@ import net.minecraft.server.v1_8_R2.Entity; import net.minecraft.server.v1_8_R2.EntityOcelot; import net.minecraft.server.v1_8_R2.EntityPlayer; import net.minecraft.server.v1_8_R2.EnumDirection; -import net.minecraft.server.v1_8_R2.IInventory; import net.minecraft.server.v1_8_R2.ITileInventory; import net.minecraft.server.v1_8_R2.InventoryEnderChest; import net.minecraft.server.v1_8_R2.InventoryLargeChest; @@ -45,6 +44,7 @@ import net.minecraft.server.v1_8_R2.TileEntityEnderChest; import net.minecraft.server.v1_8_R2.World; import org.bukkit.craftbukkit.v1_8_R2.entity.CraftPlayer; +import org.bukkit.craftbukkit.v1_8_R2.event.CraftEventFactory; public class AnySilentContainer implements IAnySilentContainer { @@ -140,10 +140,11 @@ public class AnySilentContainer implements IAnySilentContainer { return true; } - if (!(tile instanceof IInventory)) { + if (!(tile instanceof ITileInventory)) { return false; } + ITileInventory tileInventory = (ITileInventory) tile; Block block = world.getType(blockPosition).getBlock(); Container container = null; @@ -162,47 +163,54 @@ public class AnySilentContainer implements IAnySilentContainer { } if ((localEnumDirection == EnumDirection.WEST) || (localEnumDirection == EnumDirection.NORTH)) { - tile = new InventoryLargeChest("container.chestDouble", - (TileEntityChest) localTileEntity, (ITileInventory) tile); + tileInventory = new InventoryLargeChest("container.chestDouble", + (TileEntityChest) localTileEntity, tileInventory); } else { - tile = new InventoryLargeChest("container.chestDouble", - (ITileInventory) tile, (TileEntityChest) localTileEntity); + tileInventory = new InventoryLargeChest("container.chestDouble", + tileInventory, (TileEntityChest) localTileEntity); } break; } - if (silentchest) { - container = new SilentContainerChest(player.inventory, ((IInventory) tile), player); - } - - if (((BlockChest) block).b == 0) { + BlockChest blockChest = (BlockChest) block; + if (blockChest.b == 0) { player.b(StatisticList.aa); - } else if (((BlockChest) block).b == 1) { + } else if (blockChest.b == 1) { player.b(StatisticList.U); } - } - 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."); + if (silentchest) { + container = new SilentContainerChest(player.inventory, tileInventory, player); } } - return returnValue; + // AnyChest only - SilentChest not active or container unsupported + if (!silentchest || container == null) { + player.openContainer(tileInventory); + return true; + } + + // SilentChest + try { + // Call InventoryOpenEvent + container = CraftEventFactory.callInventoryOpenEvent(player, container, false); + if (container == null) { + return false; + } + + // Open window + int windowId = player.nextContainerCounter(); + player.playerConnection.sendPacket(new PacketPlayOutOpenWindow(windowId, tileInventory.getContainerName(), tileInventory.getScoreboardDisplayName(), tileInventory.getSize())); + player.activeContainer = container; + player.activeContainer.windowId = windowId; + player.activeContainer.addSlotListener(player); + + return true; + } catch (Exception e) { + e.printStackTrace(); + p.sendMessage(ChatColor.RED + "Error while sending silent container."); + return false; + } } } diff --git a/internal/v1_8_R3/src/main/java/com/lishid/openinv/internal/v1_8_R3/AnySilentContainer.java b/internal/v1_8_R3/src/main/java/com/lishid/openinv/internal/v1_8_R3/AnySilentContainer.java index 6d2f3c3..baa29cc 100644 --- a/internal/v1_8_R3/src/main/java/com/lishid/openinv/internal/v1_8_R3/AnySilentContainer.java +++ b/internal/v1_8_R3/src/main/java/com/lishid/openinv/internal/v1_8_R3/AnySilentContainer.java @@ -33,7 +33,6 @@ import net.minecraft.server.v1_8_R3.Entity; import net.minecraft.server.v1_8_R3.EntityOcelot; import net.minecraft.server.v1_8_R3.EntityPlayer; import net.minecraft.server.v1_8_R3.EnumDirection; -import net.minecraft.server.v1_8_R3.IInventory; import net.minecraft.server.v1_8_R3.ITileInventory; import net.minecraft.server.v1_8_R3.InventoryEnderChest; import net.minecraft.server.v1_8_R3.InventoryLargeChest; @@ -45,6 +44,7 @@ import net.minecraft.server.v1_8_R3.TileEntityEnderChest; import net.minecraft.server.v1_8_R3.World; import org.bukkit.craftbukkit.v1_8_R3.entity.CraftPlayer; +import org.bukkit.craftbukkit.v1_8_R3.event.CraftEventFactory; public class AnySilentContainer implements IAnySilentContainer { @@ -140,10 +140,11 @@ public class AnySilentContainer implements IAnySilentContainer { return true; } - if (!(tile instanceof IInventory)) { + if (!(tile instanceof ITileInventory)) { return false; } + ITileInventory tileInventory = (ITileInventory) tile; Block block = world.getType(blockPosition).getBlock(); Container container = null; @@ -162,47 +163,54 @@ public class AnySilentContainer implements IAnySilentContainer { } if ((localEnumDirection == EnumDirection.WEST) || (localEnumDirection == EnumDirection.NORTH)) { - tile = new InventoryLargeChest("container.chestDouble", - (TileEntityChest) localTileEntity, (ITileInventory) tile); + tileInventory = new InventoryLargeChest("container.chestDouble", + (TileEntityChest) localTileEntity, tileInventory); } else { - tile = new InventoryLargeChest("container.chestDouble", - (ITileInventory) tile, (TileEntityChest) localTileEntity); + tileInventory = new InventoryLargeChest("container.chestDouble", + tileInventory, (TileEntityChest) localTileEntity); } break; } - if (silentchest) { - container = new SilentContainerChest(player.inventory, ((IInventory) tile), player); - } - - if (((BlockChest) block).b == 0) { + BlockChest blockChest = (BlockChest) block; + if (blockChest.b == 0) { player.b(StatisticList.aa); - } else if (((BlockChest) block).b == 1) { + } else if (blockChest.b == 1) { player.b(StatisticList.U); } - } - 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."); + if (silentchest) { + container = new SilentContainerChest(player.inventory, tileInventory, player); } } - return returnValue; + // AnyChest only - SilentChest not active or container unsupported + if (!silentchest || container == null) { + player.openContainer(tileInventory); + return true; + } + + // SilentChest + try { + // Call InventoryOpenEvent + container = CraftEventFactory.callInventoryOpenEvent(player, container, false); + if (container == null) { + return false; + } + + // Open window + int windowId = player.nextContainerCounter(); + player.playerConnection.sendPacket(new PacketPlayOutOpenWindow(windowId, tileInventory.getContainerName(), tileInventory.getScoreboardDisplayName(), tileInventory.getSize())); + player.activeContainer = container; + player.activeContainer.windowId = windowId; + player.activeContainer.addSlotListener(player); + + return true; + } catch (Exception e) { + e.printStackTrace(); + p.sendMessage(ChatColor.RED + "Error while sending silent container."); + return false; + } } } diff --git a/internal/v1_9_R1/src/main/java/com/lishid/openinv/internal/v1_9_R1/AnySilentContainer.java b/internal/v1_9_R1/src/main/java/com/lishid/openinv/internal/v1_9_R1/AnySilentContainer.java index 536f3ae..c9d2c38 100644 --- a/internal/v1_9_R1/src/main/java/com/lishid/openinv/internal/v1_9_R1/AnySilentContainer.java +++ b/internal/v1_9_R1/src/main/java/com/lishid/openinv/internal/v1_9_R1/AnySilentContainer.java @@ -33,7 +33,6 @@ 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.EnumDirection; -import net.minecraft.server.v1_9_R1.IInventory; import net.minecraft.server.v1_9_R1.ITileInventory; import net.minecraft.server.v1_9_R1.InventoryEnderChest; import net.minecraft.server.v1_9_R1.InventoryLargeChest; @@ -45,6 +44,7 @@ import net.minecraft.server.v1_9_R1.TileEntityEnderChest; import net.minecraft.server.v1_9_R1.World; import org.bukkit.craftbukkit.v1_9_R1.entity.CraftPlayer; +import org.bukkit.craftbukkit.v1_9_R1.event.CraftEventFactory; public class AnySilentContainer implements IAnySilentContainer { @@ -140,10 +140,11 @@ public class AnySilentContainer implements IAnySilentContainer { return true; } - if (!(tile instanceof IInventory)) { + if (!(tile instanceof ITileInventory)) { return false; } + ITileInventory tileInventory = (ITileInventory) tile; Block block = world.getType(blockPosition).getBlock(); Container container = null; @@ -162,47 +163,54 @@ public class AnySilentContainer implements IAnySilentContainer { } if ((localEnumDirection == EnumDirection.WEST) || (localEnumDirection == EnumDirection.NORTH)) { - tile = new InventoryLargeChest("container.chestDouble", - (TileEntityChest) localTileEntity, (ITileInventory) tile); + tileInventory = new InventoryLargeChest("container.chestDouble", + (TileEntityChest) localTileEntity, tileInventory); } else { - tile = new InventoryLargeChest("container.chestDouble", - (ITileInventory) tile, (TileEntityChest) localTileEntity); + tileInventory = new InventoryLargeChest("container.chestDouble", + tileInventory, (TileEntityChest) localTileEntity); } break; } - if (silentchest) { - container = new SilentContainerChest(player.inventory, ((IInventory) tile), player); - } - - if (((BlockChest) block).g == BlockChest.Type.BASIC) + BlockChest blockChest = (BlockChest) block; + if (blockChest.g == BlockChest.Type.BASIC) { player.b(StatisticList.ac); - else if (((BlockChest) block).g == BlockChest.Type.TRAP) { + } else if (blockChest.g == BlockChest.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."); + if (silentchest) { + container = new SilentContainerChest(player.inventory, tileInventory, player); } } - return returnValue; + // AnyChest only - SilentChest not active or container unsupported + if (!silentchest || container == null) { + player.openContainer(tileInventory); + return true; + } + + // SilentChest + try { + // Call InventoryOpenEvent + container = CraftEventFactory.callInventoryOpenEvent(player, container, false); + if (container == null) { + return false; + } + + // Open window + int windowId = player.nextContainerCounter(); + player.playerConnection.sendPacket(new PacketPlayOutOpenWindow(windowId, tileInventory.getContainerName(), tileInventory.getScoreboardDisplayName(), tileInventory.getSize())); + player.activeContainer = container; + player.activeContainer.windowId = windowId; + player.activeContainer.addSlotListener(player); + + return true; + } catch (Exception e) { + e.printStackTrace(); + p.sendMessage(ChatColor.RED + "Error while sending silent container."); + return false; + } } } diff --git a/internal/v1_9_R2/src/main/java/com/lishid/openinv/internal/v1_9_R2/AnySilentContainer.java b/internal/v1_9_R2/src/main/java/com/lishid/openinv/internal/v1_9_R2/AnySilentContainer.java index b2a5a09..550cc08 100644 --- a/internal/v1_9_R2/src/main/java/com/lishid/openinv/internal/v1_9_R2/AnySilentContainer.java +++ b/internal/v1_9_R2/src/main/java/com/lishid/openinv/internal/v1_9_R2/AnySilentContainer.java @@ -33,7 +33,6 @@ 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.EnumDirection; -import net.minecraft.server.v1_9_R2.IInventory; import net.minecraft.server.v1_9_R2.ITileInventory; import net.minecraft.server.v1_9_R2.InventoryEnderChest; import net.minecraft.server.v1_9_R2.InventoryLargeChest; @@ -45,6 +44,7 @@ import net.minecraft.server.v1_9_R2.TileEntityEnderChest; import net.minecraft.server.v1_9_R2.World; import org.bukkit.craftbukkit.v1_9_R2.entity.CraftPlayer; +import org.bukkit.craftbukkit.v1_9_R2.event.CraftEventFactory; public class AnySilentContainer implements IAnySilentContainer { @@ -140,10 +140,11 @@ public class AnySilentContainer implements IAnySilentContainer { return true; } - if (!(tile instanceof IInventory)) { + if (!(tile instanceof ITileInventory)) { return false; } + ITileInventory tileInventory = (ITileInventory) tile; Block block = world.getType(blockPosition).getBlock(); Container container = null; @@ -162,47 +163,54 @@ public class AnySilentContainer implements IAnySilentContainer { } if ((localEnumDirection == EnumDirection.WEST) || (localEnumDirection == EnumDirection.NORTH)) { - tile = new InventoryLargeChest("container.chestDouble", - (TileEntityChest) localTileEntity, (ITileInventory) tile); + tileInventory = new InventoryLargeChest("container.chestDouble", + (TileEntityChest) localTileEntity, tileInventory); } else { - tile = new InventoryLargeChest("container.chestDouble", - (ITileInventory) tile, (TileEntityChest) localTileEntity); + tileInventory = new InventoryLargeChest("container.chestDouble", + tileInventory, (TileEntityChest) localTileEntity); } break; } - if (silentchest) { - container = new SilentContainerChest(player.inventory, ((IInventory) tile), player); - } - - if (((BlockChest) block).g == BlockChest.Type.BASIC) { + BlockChest blockChest = (BlockChest) block; + if (blockChest.g == BlockChest.Type.BASIC) { player.b(StatisticList.ac); - } else if (((BlockChest) block).g == BlockChest.Type.TRAP) { + } else if (blockChest.g == BlockChest.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."); + if (silentchest) { + container = new SilentContainerChest(player.inventory, tileInventory, player); } } - return returnValue; + // AnyChest only - SilentChest not active or container unsupported + if (!silentchest || container == null) { + player.openContainer(tileInventory); + return true; + } + + // SilentChest + try { + // Call InventoryOpenEvent + container = CraftEventFactory.callInventoryOpenEvent(player, container, false); + if (container == null) { + return false; + } + + // Open window + int windowId = player.nextContainerCounter(); + player.playerConnection.sendPacket(new PacketPlayOutOpenWindow(windowId, tileInventory.getContainerName(), tileInventory.getScoreboardDisplayName(), tileInventory.getSize())); + player.activeContainer = container; + player.activeContainer.windowId = windowId; + player.activeContainer.addSlotListener(player); + + return true; + } catch (Exception e) { + e.printStackTrace(); + p.sendMessage(ChatColor.RED + "Error while sending silent container."); + return false; + } } }