Getting placed item in InventoryClickEvent

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

  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 (Text):
        @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 (Text):
     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. If you are testing it in creative mode, that might be the issue. InventoryClickEvents are messed up with creative mode. Try testing it in survival (assuming your players will be in survival)
     
  3. Have you looked at this?
    Code (Text):
    e.getClickedItem()
     
  4. I believe;

    Code (Text):
    e.getWhoClicked().getItemOnCursor()
     
    • Useful Useful x 1