From 2f7d3bc235663f7a8dbbae4c33310c935466d813 Mon Sep 17 00:00:00 2001 From: Jikoo Date: Tue, 10 Jan 2017 14:12:58 -0500 Subject: [PATCH] Call InventoryOpenEvent when using SilentChest Backport fix for incorrect parameter as well, just in case. Fixed 1.7 and lower forcing all chests' default names to be "Large chest" instead of the translatable string. --- .../internal/v1_4_5/AnySilentContainer.java | 52 +++++++----- .../internal/v1_4_6/AnySilentContainer.java | 52 +++++++----- .../internal/v1_10_R1/AnySilentContainer.java | 69 +++++++++------- .../internal/v1_11_R1/AnySilentContainer.java | 81 ++++++++++--------- .../internal/v1_4_R1/AnySilentContainer.java | 52 +++++++----- .../internal/v1_5_R2/AnySilentContainer.java | 52 +++++++----- .../internal/v1_5_R3/AnySilentContainer.java | 52 +++++++----- .../internal/v1_6_R1/AnySilentContainer.java | 52 +++++++----- .../internal/v1_6_R2/AnySilentContainer.java | 52 +++++++----- .../internal/v1_6_R3/AnySilentContainer.java | 52 +++++++----- .../internal/v1_7_R1/AnySilentContainer.java | 52 +++++++----- .../internal/v1_7_R2/AnySilentContainer.java | 52 +++++++----- .../internal/v1_7_R3/AnySilentContainer.java | 52 +++++++----- .../internal/v1_7_R4/AnySilentContainer.java | 52 +++++++----- .../internal/v1_8_R1/AnySilentContainer.java | 57 +++++++------ .../internal/v1_8_R2/AnySilentContainer.java | 68 +++++++++------- .../internal/v1_8_R3/AnySilentContainer.java | 68 +++++++++------- .../internal/v1_9_R1/AnySilentContainer.java | 68 +++++++++------- .../internal/v1_9_R2/AnySilentContainer.java | 68 +++++++++------- 19 files changed, 650 insertions(+), 453 deletions(-) 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 3032f6fd..be34e71f 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 @@ // 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.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 boolean activateContainer(Player p, boolean silentchest, org.bukkit.block 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 e0f76961..20a33a14 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 @@ // 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.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 boolean activateContainer(Player p, boolean silentchest, org.bukkit.block 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 36c3ae92..8dca3aa9 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 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.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.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 boolean activateContainer(Player p, boolean silentchest, org.bukkit.block 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 boolean activateContainer(Player p, boolean silentchest, org.bukkit.block } 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 = new SilentContainerChest(player.inventory, tileInventory, player); + } + } + // 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_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 5028fb9c..5464f353 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 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.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 boolean activateContainer(Player p, boolean silentchest, org.bukkit.block } 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 boolean activateContainer(Player p, boolean silentchest, org.bukkit.block 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 boolean activateContainer(Player p, boolean silentchest, org.bukkit.block } } - 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); + 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); + + // 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; } - }.runTaskLater(Bukkit.getPluginManager().getPlugin("OpenInv"), 2); - } - } catch (Exception e) { - e.printStackTrace(); - p.sendMessage(ChatColor.RED + "Error while sending silent chest."); + 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 returnValue; + 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 b08e28de..ec1e7b6c 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 @@ // 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.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 boolean activateContainer(Player p, boolean silentchest, org.bukkit.block 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 c08b41c8..5cb2c26f 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 @@ // 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.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 boolean activateContainer(Player p, boolean silentchest, org.bukkit.block 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 ee10a6fd..7d011a07 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 @@ //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.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 boolean activateContainer(Player p, boolean silentchest, org.bukkit.block 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 87c46d69..1a793205 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 @@ // 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.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 boolean activateContainer(Player p, boolean silentchest, org.bukkit.block 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 acdef19a..ab1ff97c 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 @@ // 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.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 boolean activateContainer(Player p, boolean silentchest, org.bukkit.block 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 ce370313..d97d39d9 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 @@ // 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.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 boolean activateContainer(Player p, boolean silentchest, org.bukkit.block 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 33d70e75..c9e82a18 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 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.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 boolean activateContainer(Player p, boolean silentchest, org.bukkit.block 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 886fa11a..ddd5e437 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 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.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 boolean activateContainer(Player p, boolean silentchest, org.bukkit.block 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 3b9c651b..d057b010 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 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.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 boolean activateContainer(Player p, boolean silentchest, org.bukkit.block 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 7f804ed7..0b2b855d 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 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.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 boolean activateContainer(Player p, boolean silentchest, org.bukkit.block 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 a3768e1e..9b2ea343 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.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.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 boolean activateContainer(Player p, boolean silentchest, org.bukkit.block 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 boolean activateContainer(Player p, boolean silentchest, org.bukkit.block } 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 564fdcc6..eeb18af7 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.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.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 boolean activateContainer(Player p, boolean silentchest, org.bukkit.block 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 boolean activateContainer(Player p, boolean silentchest, org.bukkit.block } 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 = new SilentContainerChest(player.inventory, tileInventory, player); + } + } + // 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_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 6d2f3c34..baa29cc0 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.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.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 boolean activateContainer(Player p, boolean silentchest, org.bukkit.block 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 boolean activateContainer(Player p, boolean silentchest, org.bukkit.block } 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 = new SilentContainerChest(player.inventory, tileInventory, player); + } + } + // 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_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 536f3ae1..c9d2c386 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.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.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 boolean activateContainer(Player p, boolean silentchest, org.bukkit.block 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 boolean activateContainer(Player p, boolean silentchest, org.bukkit.block } 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 = new SilentContainerChest(player.inventory, tileInventory, player); + } + } + // 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_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 b2a5a092..550cc085 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.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.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 boolean activateContainer(Player p, boolean silentchest, org.bukkit.block 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 boolean activateContainer(Player p, boolean silentchest, org.bukkit.block } 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 = new SilentContainerChest(player.inventory, tileInventory, player); + } + } + // 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; + } } }