Inventory detection

Discussion in 'Spigot Plugin Development' started by BananaPuncher714, May 17, 2017.

  1. BananaPuncher714


    I am trying to make a custom GUI, and when I attempt to determine whether an inventory click was in the top inventory, it doesn't work. I used Inventory#getTitle() and getName() to get the name, and it seems that the name is always the same, no matter if it's the player inventory or the custom inventory. I tried to get the inventory with e.getInventory() and e.getView.getTopInventory(), but it still doesn't work. I was wondering if this is a bug on my end, or if it's some issue with the server itself. If it's the server, what are some ways that I can detect a custom inventory?
  2. Code (Java):
         * Returns whether the player clicked the top or bottom inventory
         * @since 0.0.1
         * @version 0.0.1
         * @param event The relevant {@link InventoryClickEvent}
         * @return {@code true} for clicking the top, {@code false} otherwise

        public static boolean hasClickedTop(InventoryClickEvent event) {
            return event.getRawSlot() == event.getSlot();

    Make sure to properly debug and handle your edge cases, as well as checking inventory type (you don't want this to execute on villager inventories, for example).
    • Winner Winner x 1
  3. BananaPuncher714


    Ok thanks I will try when I have time.