getCursor() Returning item with no ItemMeta

Discussion in 'Plugin Development' started by jeph0, May 20, 2021.

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

    jeph0

    Hello, I'm new to bukkit and writing my first plugin, so I may be missing something obvious, but I can't figure this out. When I execute this event listener (designed to detect when an item with a persistent data key is moved to another inventory), the item object returned by getCursor() has no ItemMeta object. The item itself seems to still have this meta, as seen in the below screenshot and proven by other areas of code in which the hasKey() method works properly (This method simply checks if the item has the specified key as a persistantData key).

    Code:
            @EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
            public void onClick(InventoryClickEvent event) {
               
                //ItemStack item = Optional.ofNullable(event.getCursor()).orElse(event.getCurrentItem());
                ItemStack item = event.getCursor();
                if (item == null) {item = event.getCurrentItem();} //Breakpoint after here
               
                if (item == null || event.getResult() == Event.Result.DENY || !KeyHelper.hasKey(item, DeathCompass.getCompassKey())) {
                    return;
                }
                DeathCompass compass = DeathCompass.getCompass(item);
               
                switch (event.getAction()) {
                case PLACE_ALL:
                case PLACE_SOME:
                case PLACE_ONE:
                    compass.setInventory(event.getClickedInventory());
                    break;
                case MOVE_TO_OTHER_INVENTORY:
                    if (event.getClickedInventory().equals(event.getView().getTopInventory())) {
                        compass.setInventory(event.getView().getBottomInventory());
                    } else {
                        compass.setInventory(event.getView().getTopInventory());
                    }
                   
                    break;
                default:
                    break;
               
                }
            }
    Here is what getCursor() is returning:
    upload_2021-5-20_22-5-43.png
    And here is what the Client sees:
    upload_2021-5-20_22-8-20.png

    Please let me know is there is anything else I can do to help figure this out! I'm probably missing something obvious, but I thought I'd ask because I'm new to bukkit
    Thanks!
     
  2. Offline

    Kars

    You have getCurrentItem and getCursor in your code both, please confirm the expected one is triggered.
     
  3. Offline

    jeph0

    Yes, I moved the breakpoint before getCurrentItem() is triggered and nothing changed
     
  4. Offline

    Kars

    @jeph0 i take it hasItemMeta() returns false then as well?
     
  5. Offline

    KarimAKL

    @jeph0 I believe you are confusing #getCursor() and #getCurrentItem().
    The item clicked is #getCurrentItem() and the item you are clicking (e.g. when moving an item) with is #getCursor().
     
  6. Offline

    jeph0

    Apon further inspection, it appears that both are not returning any real itemStacks at all. The Material is AIR and no other info is given...
    HOWEVER, somehow the program now works as intended... I only changed a line for debugging, and it seems to function as it should. This may just be an issue with my debugger, as I see no change in the breakpoint output.

    Thanks everyone.
     
Thread Status:
Not open for further replies.

Share This Page