Solved InventoryClickEvent causing "ghost" items

Discussion in 'Plugin Development' started by Koanga, Apr 3, 2013.

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

    Koanga

    This has been an issue that has been plaguing me quite some time involving canceling the input of items into an inventory. The item will not actually be put into the inventory, evidenced by it not being shown to other viewers, but it will stay on the player's client view until they click on it or move items around.

    Note, this is not the exact code, but it still produces the exact same results:
    Code:
            if(e.getCursor().getType() != Material.AIR) {
                e.setCancelled(true);
            }
    Basically, the code will only cancel the event when there is an item to be put into the inventory. Canceling causes a "ghost" item to form in the slot where it was placed, even though the event was canceled prior.

    Any help on this is greatly appreciated, as I've been searching around quite a while for a possible solution to this issue.

    EDIT:

    I have also used
    Code:
    e.setResult(Result.DENY);
    to no effect as well. And any sort of manual modification of the outcome (for instance, e.setCursor()) does not come any closer to fixing the issue. At this point, I'm considering it to be a sync issue between the server and client regarding there actually being an item in the slot, rather than it being something else.
     
  2. Offline

    Digi

    player.updateInventory();

    It's not always needed and when needed, in certain cases it works if called directly but in other cases you might need a 1-tick or even a 2-tick delay, you must try and see which case you need, start from calling that directly.

    And yes, the method is deprecated and it's been like that for a long time, there's yet to be a replacement or a fix for the events it is needed for.
     
    Koanga likes this.
  3. Offline

    Koanga

    And to think I was attempting to manually send packets, when all I needed to do was that.
    It, fortunately, does not need a delay to work in my case. Thanks a lot!
     
    microgeek likes this.
Thread Status:
Not open for further replies.

Share This Page