InventoryClickEvent - How to check if clicked slot type is ARMOR?

Discussion in 'Plugin Development' started by MrAndeos, Jan 22, 2018.

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



    I'm trying to check if getSlotType() is SlotType.ARMOR and, I can't get it to work... Here is the code:
    1. @EventHandler
    2. public void onInventoryClick(InventoryClickEvent event) {
    3. Player player = (Player)event.getWhoClicked();
    4. if (event.getInventory().getType().equals(InventoryType.PLAYER) || event.getInventory().getType().equals(InventoryType.CREATIVE)) {
    5. ItemStack item = event.getCurrentItem();
    6. if (item == null) {
    7. return;
    8. }
    9. // The code is working to this moment.
    10. if (event.getSlotType().equals(SlotType.ARMOR)) {
    11. event.setCancelled(true);
    12. }
    13. }
    14. }

    How to make this working?

    Sorry for any language mistakes, English is not my native language.
  2. Offline


    Not .equals use ==

    And you've obviously not searched this on Google first because I found 10 other posts like this.

    Sent from my Pixel using Tapatalk
  3. Offline


    I was searching in Google, I tried to use == operator, it's still not working. It seems like event doesn't get canceled. If I put debug message after "if (event.getSlotType() == SlotType.ARMOR)" it sometimes get's displayed, but not always. If I completely remove this If statement, and I left only the "event.setCancelled(true)", it's working, but I want it to affect only the armor slots.
    Last edited: Jan 22, 2018
  4. Offline

    Machine Maker

    If SlotType isnt working (idk why it wouldnt) you could always figure out what the slot number is of the 4 armor slots and try to check if its the armor that way.
  5. Offline


    Still can't get it to work, if I do event.getSlot() == 103 or event.getRawSlot() == 103, or basing on different slot numeration: event.getSlot() == 5 or event.getRawSlot() == 5 (for helmet slot), I'm getting the same thing as with event.getSlotType() == SlotType.ARMOR...
Thread Status:
Not open for further replies.

Share This Page