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.
This commit is contained in:
Jikoo 2017-01-10 14:12:58 -05:00
parent ef486032f1
commit 2f7d3bc235
19 changed files with 656 additions and 459 deletions

View file

@ -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;
}
}
}

View file

@ -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;
}
}
}

View file

@ -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;
}
}
}

View file

@ -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;
}
}
}

View file

@ -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;
}
}
}

View file

@ -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;
}
}
}

View file

@ -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;
}
}
}

View file

@ -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;
}
}
}

View file

@ -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;
}
}
}

View file

@ -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;
}
}
}

View file

@ -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;
}
}
}

View file

@ -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;
}
}
}

View file

@ -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;
}
}
}

View file

@ -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;
}
}
}

View file

@ -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;
}
}
}

View file

@ -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;
}
}
}

View file

@ -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;
}
}
}

View file

@ -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;
}
}
}

View file

@ -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;
}
}
}