Ghost Items :/

Discussion in 'Spigot Plugin Development' started by yhl, May 10, 2017.

  1. yhl


  2. This is a common bug I experienced aswell a long time ago. Delay the opening of your new inventory a bit (2 ticks or something), then its more likely to work. I always used an updateInventory() call afterwards, but I guess that one is not really needed.

    The problem is most likely, that the inventories are being edited and swapped within the same tick. The items will only get updated for players viewing your inventory, so when you still have the old one open, the player wont get notified about the new items on the new inventory.
  3. yhl


    So how would I fix it?
  4. Short example:

    Replace line 109-111 in your Listener class with the following:

    final Inventory miner = at.getMiner(p);
    new BukkitRunnable(){public void run(){
    }}.runTaskLater(2L); //Open the inventory 2 ticks delayed
    #4 Friwi, May 10, 2017
    Last edited: May 10, 2017
  5. yhl


    Still does the same thing
  6. Try to update before or after p.openInventory(); with inv.updateInventory(). When that final thing doesn't work im clueless. I didn't check your code towards correctness though... maybe the items don't even get added.
  7. yhl


    Okay I'll try updating it before, and isnt it p.updateInventory(); not inv.updateInventory();?
  8. Yeah, you are right about that, messed that up. Then you only have to try afterwards oc :)
  9. yhl


    Still doesnt work :(
  10. yhl


    Does anyone know how to fix this :/
  11. Check every tick if there is a difference between the inventories, if there is, update the new items in the inventory you want to be updated.

    Something along the lines of this should fix it.

    Code (Text):
    Player player;
        if (player#getInventory()#getContents()#equals(inventory#getContents())) {