public void openInventory(InventoryView inventory) { if (!(getHandle() instanceof EntityPlayer)) return; // TODO: NPC support? if (((EntityPlayer) getHandle()).playerConnection == null) return; if (getHandle().activeContainer != getHandle().defaultContainer) { // fire INVENTORY_CLOSE if one already open ((EntityPlayer) getHandle()) .playerConnection.handleContainerClose( new Packet101CloseWindow(getHandle().activeContainer.windowId)); } EntityPlayer player = (EntityPlayer) getHandle(); Container container; if (inventory instanceof CraftInventoryView) { container = ((CraftInventoryView) inventory).getHandle(); } else { container = new CraftContainer(inventory, player.nextContainerCounter()); } // Trigger an INVENTORY_OPEN event container = CraftEventFactory.callInventoryOpenEvent(player, container); if (container == null) { return; } // Now open the window InventoryType type = inventory.getType(); int windowType = CraftContainer.getNotchInventoryType(type); String title = inventory.getTitle(); int size = inventory.getTopInventory().getSize(); player.playerConnection.sendPacket( new Packet100OpenWindow(container.windowId, windowType, title, size, false)); player.activeContainer = container; player.activeContainer.addSlotListener(player); }
private void openCustomInventory(Inventory inventory, EntityPlayer player, int windowType) { if (player.playerConnection == null) return; Container container = new CraftContainer(inventory, this, player.nextContainerCounter()); container = CraftEventFactory.callInventoryOpenEvent(player, container); if (container == null) return; String title = container.getBukkitView().getTitle(); int size = container.getBukkitView().getTopInventory().getSize(); player.playerConnection.sendPacket( new Packet100OpenWindow(container.windowId, windowType, title, size, true)); getHandle().activeContainer = container; getHandle().activeContainer.addSlotListener(player); }