InventoryClose event bug

Discussion in 'Spigot Plugin Development' started by Niko_Ox, Jul 10, 2018.

  1. Hi, my plugin has a problem, on InvetoryCloseEvent when I close for first time gui inventory He opens me 1000 gui at once... Can anyone help me?


    @EventHandler
    public void onInventoryClose(InventoryCloseEvent event) {
    if(event.getInventory().getName().equals(gui.getName())) {
    event.getPlayer().openInventory(gui);
    }
    }
    Ps. I don't want use Bukkit runnable for do this.
     
  2. Not sure what you're asking, but if you simply re-open a GUI each and every time it's closed, you're sort of screwed once you open it.
     
  3. Well, I want create a system that spam a gui every time a player close it, I can't use BukkitRunnable for do this.. So I have used InventoryCloseEvent but when I close the first gui He opens me 1000 gui at once and after doesn't works
     
  4. Add a 1 tick delay. This event gets called before closing the inventory, if you open a new inventory you close the old one, thus an endless loop.
     
    • Like Like x 1
  5. Why would you even want to do that? And what do you mean that you can't use BukkitRunnables to do this?
     
  6. How can I do it?
     
  7. He probably wants to do this for things such as a freeze gui, stopping players from deleting their in-game ghost clients. Or something like that.

    This is for a BukkitRunnable.

    How do you know it opens 1000 gui's at the same time? And, apart from lag it may create, why is this a problem?
     
  8. Google bukkit runnable, and delayed task
     
  9. He doesnt want to use bukkit runnable.
     
  10. Look like an XY problem here. From what I gather you don't want to use the runnable because every time you close an inventory it opens a new one on repeat. But realistically a runnable is the easiest approach to this, what I think the issue may be is that instead of using runTask, you are using runTaskTimer which runs on repeat hence repeatedly opening menus for you.
     
  11. then use a for loop and count 1 tick... bukkitrunnable is just the easiest way to do this. it's not my problem he doesnt want to use 3 extra lines of code in order to make it work.