Checking if a player has an inventory open

Discussion in 'Plugin Development' started by Rixterz, Apr 19, 2017.

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

    Rixterz

    Hi,

    Is there any way to tell whether a play has an inventory open with a direct check as opposed to the following:

    InventoryOpenEvent: invOpen = true;
    InventoryCloseEvent: invOpen = false;

    Thanks

    Rix
     
  2. I think
    Code:
     if(player.getOpenInventory != null) 
    should do it.
     
    MCMastery likes this.
  3. Offline

    Caderape2

    @MisterMel player.getInventory() will never be null.

    @Rixterz I don't get exactly what you are trying to do
     
  4. Offline

    Rixterz

    @MisterMel p.getOpenInventory() always returns their player inventory regardless whether it's open or not

    @Caderape2 I would like to check whether a player has an inventory open, on their screen, at a given time, rather than keeping a log based on InventoryOpen/Close events.
     
  5. Offline

    GRocksMc

    I know it's not what you want, but you should use InventoryOpenEvent and InventoryCloseEvent and store it in a hashmap <UUID, Boolean>.
     
  6. Oh lol dint know that. Couldnt test it because i was on mobile.

    Or you could just use a List. :p
    Also, if the player's game crashes while in a inventory it will still think its in a inventory because the player never closed the inventory. You will have to make sure all this kinda stuff doesnt happen.
     
    Last edited: Apr 19, 2017
Thread Status:
Not open for further replies.

Share This Page