Getting placed item in InventoryClickEvent

Discussion in 'Plugin Development' started by TheMinecraftKnight, Jun 1, 2017.

Thread Status:
Not open for further replies.
  1. Hey. I am trying to make a plugin where players can deposit one item into an inventory, and then the item is saved to the config file. I've made a nine slot inventory and filled up all except one slot. Now, here's my code for my InventoryClickEvent listener

    Code:
        @EventHandler
        public void invClick(InventoryClickEvent e) {
            if (e.getClickedInventory().equals(Create.menu)) {
                if (e.getAction().equals(InventoryAction.PLACE_ALL)) {
                    e.getWhoClicked().getInventory().addItem(e.getCurrentItem()); //for debugging
                } else {
                    e.setCancelled(true);
                }
            }
        }
    What I'm having trouble with is getting the item. If I do
    Code:
     e.getInventory().getItem(e.getSlot());
    
    it returns null, and the first code just returns Material.AIR

    How can I get the item that they placed in the inventory?
     
  2. Offline

    Caderape2

    @TheMinecraftKnight So you know what is the slot ?
    Listen on inventoryClose then get the item at the slot, check if it's not null and save to the config
     
  3. @Caderape2 Yeah, I know the slot. They can only deposit the item in one slot, so yeah I do. That should work.
     
Thread Status:
Not open for further replies.

Share This Page