Solved Menu system bugging out InvClickEvent

Discussion in 'Plugin Development' started by JeroenV, Apr 4, 2013.

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

    JeroenV

    Hello,

    I think everyone who has tried to create a menu system knows that when changing from one inventory to another you have to put a slight delayed scheduler on it to make sure you don't bug out the InvClickEvent. However currently I'm noticing that after players have used the menu system which is just ended either manually or using player.closeInventory() their InvClickEvent is bugged out when opening their own inventory.

    It stops them from doing anything. I've been looking what could be causing it but I don't quite understand, I thought the bug occured when you opened one menu to fast over another one. But sometimes players open their own inventory like 5 minutes after having used the menu.


    Hoping to find someone here that has already encountered this bug and knows how to deal with it.

    EDIT:
    After debugging this for a while, I've noticed that this happens after I've used player.closeInventory().


    Thanks in advance,
    Jero

    Solved:
    It appears you also have to put a 1/20th second delay on player.closeInventory() to prevent it from bugging your own inventory.

    Code:
        public void closeInventory(final Player player){
                Bukkit.getScheduler().scheduleSyncDelayedTask(plugin, new Runnable() {
               
                  @Override
                  public void run() {
                     
                  player.closeInventory();
                       
                  }
                  },1L);
        }
    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: May 31, 2016
Thread Status:
Not open for further replies.

Share This Page