Solved 1.14.4 getting clicked item

Discussion in 'Plugin Development' started by johnny_boy, Apr 15, 2020.

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

    johnny_boy

    im listening on the InventoryClickEvent and i have tried so many methods of getting the clicked item but it either returns AIR or null.. How do I find the clicked item in an inventory ?
     
  2. Offline

    timtower Moderator Moderator

  3. Offline

    johnny_boy

    Code:Java
    1.  
    2. System.out.println("item that was clicked: " + e.getWhoClicked().getItemOnCursor());
    3. System.out.println("item that was clicked: " + e.getCursor());
    4. System.out.println("item that was clicked: " + e.getInventory().getItem(e.getRawSlot));
    5.  


    are just a few examples.. and here's my listener class:
    Code:Java
    1.  
    2. @EventHandler(priority = EventPriority.HIGHEST)
    3. public void onInventoryClick(InventoryClickEvent e) {
    4. Player pl = (Player) e.getWhoClicked();
    5. if (playerStates.containsKey(pl.getUniqueId()) == true) {
    6. String displayName = plugin.config.getString("discoarmor.armor.name");
    7. System.out.println("display name: " + displayName);
    8. System.out.println("item that was clicked: " + e.getWhoClicked().getItemOnCursor());
    9. if (e.getWhoClicked().getItemOnCursor().getItemMeta().getDisplayName() == displayName) {
    10. System.out.println("cancelled event");
    11. e.setCancelled(true);
    12. }
    13. }
    14. }
    15.  
     
  4. Offline

    timtower Moderator Moderator

    @johnny_boy Strings are compared with equals or equalsIgnoreCase, == won't work
     
  5. Offline

    johnny_boy

    good point thank you but i still can't get the item that the cursor is on - it always returns air / null .. know what the method is ?
     
  6. Offline

    timtower Moderator Moderator

  7. Offline

    johnny_boy

    EDIT: Turns out e.getCursor() only gets the item the cursor is holding in survival mode, thanks for the help regardless :)
     
    Last edited: Apr 15, 2020
Thread Status:
Not open for further replies.

Share This Page