InventoryCloseEvent inventory.getContents() empty

Discussion in 'Spigot Plugin Development' started by Mrten, May 29, 2016.

  1. I'm trying to get the contents of an inventory in the InventoryCloseEvent, but even if I fill the whole inventory, inventory.getContents() doesn't contain items.

    This is my code:
    Code (Text):
        public void onInventoryClose(InventoryCloseEvent event) {
            Inventory inventory = event.getInventory();
            for (int i = 0; i < inventory.getSize(); i++) {
                ItemStack item = inventory.getItem(i);
                if (item != null) {
                } else {
                    Bukkit.broadcastMessage("null - " + i);
    All it does is show "null - 0-26". Is this a bug in Spigot or am I missing something?
  2. Try looping through the inventory's contents, rather then iterating through until you reach the size.
  3. Using for(ItemStack item : inventory.getContents()) { ... } has the same result.
  4. Turns out that InventoryClickEvent is not even fired in the inventory. Also dropping items or moving items in the player inventory does not work. After closing the inventory everything reverts on an inventory update.