[HELP NEEDED] InventoryCloseEvent Help

Discussion in 'Spigot Plugin Development' started by dyenxunit, Jul 1, 2015.

  1. Hi, I have been struggling to figure out why the InventoryCloseEvent in my code runs when the player opens the inventory Confirmation this is a GUI menu. I want the code to run when the player closes the inventory instead of when it opens. Can someone please help me and thank you.

    Simple Explanation: When ever i open the gui with the name "Confirmation" it runes the code below, but i want it only to run when the gui is closed

    Code (Text):
         public void invCloseEvent(InventoryCloseEvent e) {
         final Player p = (Player) e.getPlayer();
                 Bukkit.getScheduler().scheduleSyncDelayedTask(plugin, new Runnable() {
                 public void run() {

                 }, 1L);
    #1 dyenxunit, Jul 1, 2015
    Last edited: Jul 1, 2015
  2. You could put players in an ArrayList when they join the server, and add an if statement in your code to see if they are in the list, if they are in the list, then do nothing and take them out of the list, so when they close there inventory, they won't be in the list and the event will do something.And then add them back to the list. Don't forget to remove them from the list when they leave the server aswell.

    Do you need an example?
  3. Are you opening this inventory from another? Because if for example you click an item to open a new inventory that first inventory has to close.
  4. Yea i closed the inventory then the second inventory opens and that second inventory is causing the code to run first
  5. Try delaying the opening of the second inventory by a tick. Ie schedule it in a task with no delay.
  6. @dyenxunit post the code you use to open the inventory.
  7. Code (Text):
  8. Do you do anything else after that? (Perhaps you want to cancel the event as well)
  9. Are you sure that there's any event called InventoryCloseEvent?
  10. Nope there is nothing after that not even a cancel event
  11. Yes