Solved How to differentiate two slots with the same getSlot() value?

Discussion in 'Plugin Development' started by Jakre, Jul 27, 2016.

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

    Jakre

    Hello,

    I am working on GUI menu, but I have a problem with recognizing slots in menu and slots in inventory.

    [​IMG]

    The yellow crosses symbolise the slots with the same getSlot() value, which is 1. I got that value via this code:

    Code:
    public void onGameGUIClick(InventoryClickEvent event) {
        if(!event.getInventory().getName().equalsIgnoreCase("Game Menu"))
            return;
      
        if(event.getSlotType().equals(SlotType.OUTSIDE))
            return;
      
        Player player = (Player) event.getWhoClicked();
        event.setCancelled(true);
      
        if(event.getCurrentItem() == null || event.getCurrentItem().getType() == Material.AIR || !event.getCurrentItem().hasItemMeta()) {
            if(event.getSlot() < 45 && event.getInventory().getType() != InventoryType.PLAYER) {
                player.sendMessage("You clicked on slot: " + event.getSlot());
            }
            return;
        }
    }
    What I want to do is an action which happens only when the player clicks on some of the 45 slots in "Game Menu" inventory. Now the action happens always, when the player clicks on the empty slot.


    How can I differentiate which slots are in the menu?
     
    Last edited: Jul 27, 2016
  2. Offline

    Corndogoz

    Check getClickedInventory(I think thats the method name.)
     
  3. Offline

    Zombie_Striker

    @Jakre
    Get the inventory view (should be something like Event.getView() ) and check whether it was the top inventory or the bottom inventory. Do this by checking if the itemstack that was placed in slot X is the same as the itemstack in the top inventory at slot X. If they are the same, then the clicked inventory was the top on. If not, then it is the bottom one.
     
  4. Offline

    Jakre

    @Zombie_Striker @Corndogoz
    Thank you very much for your help. I figured out an easier solution. Now I get unique IDs for each slot using getRawSlot().

    Code:
    event.getRawSlot() < event.getInventory().getSize();
     
Thread Status:
Not open for further replies.

Share This Page