InventoryClick doesn't get called on new Window

Discussion in 'Plugin Development' started by Blindhero, Jul 30, 2015.

Thread Status:
Not open for further replies.
  1. Offline

    Blindhero

    Hi, I'm currently coding an InventoryMenu. Until now it worked fine, because i just closed and reopened an inventory if the player clicked an item. for example i just used:
    Code:
    m_Player.closeInventory();
    m_Inventory = Bukkit.createInventory(null, m_Inventory.getSize(), m_aTitles[m_Page]);
    m_Player.openInventory(m_Inventory);
    But this would move the player's cursor to the center, and i didn't like it. So i looked around and found ProtocolLib, where i could send Packets like Open_Window and Set_Slot. The problem is, after the same inventory opened (just with another title) and it got updated, the InventoryClickEvent didn't get called anymore...

    So here is the code for openInventory:
    Show Spoiler

    Code:
    public void openInventory(Player p, Inventory cur, String title)
        {      
            try
            {
                EntityPlayer ep = ((CraftPlayer) p).getHandle();      
                ProtocolManager manager = ProtocolLibrary.getProtocolManager();
                final PacketContainer packet = manager.createPacket(PacketType.Play.Server.OPEN_WINDOW);
                packet.getIntegers().write(0, ep.nextContainerCounter());
                packet.getStrings().write(0, title);
                packet.getIntegers().write(1, cur.getType().ordinal());
                packet.getIntegers().write(2, cur.getSize());
                          
                manager.sendServerPacket(p, packet);
            }
            catch (InvocationTargetException ex)
            {
                ex.printStackTrace();
            }
        }


    and the code for updating the Inventory (i just sent every slot again)
    Show Spoiler

    Code:
        public void sendItem(ItemStack is, Player p, int Slot, int InventoryID)
        {      
            ProtocolManager manager = ProtocolLibrary.getProtocolManager();
            final PacketContainer packet = manager.createPacket(PacketType.Play.Server.SET_SLOT);
            packet.getIntegers().write(0, InventoryID);
            packet.getIntegers().write(1, Slot);
            packet.getItemModifier().write(0, is);
          
            try
            {
                manager.sendServerPacket(p, packet);
            }
            catch (InvocationTargetException ex)
            {
                ex.printStackTrace();
            }
        }
     
  2. Offline

    tommyhoogstra

    Why do you need to use packets for this?
     
  3. Offline

    Blindhero

    First of all i need to learn how to use that lib because it seems that you can do alot of cool stuff with it.
    And in this case as i already said, reopening will move the players cursor to the center. Is there a way to prevent this without packets? If yes, please tell me
     
Thread Status:
Not open for further replies.

Share This Page