Checking if player opens their inventory.

Discussion in 'Spigot Plugin Development' started by VrektHF, May 26, 2016.

  1. Hello so I've had this problem for awhile now, how would I go about checking this?

    InventoryOpenEvent does not fire for the players inventory. I've also tried:

    Code (Text):
     
    if (player.getOpenInventory() instanceof PlayerInventory) {

    }
     
    Does not work. I know this is possible, would I use packets, and which one? I already have experience with ProtocolLib and have it setup.

    Thanks for all the help.
     
  2. Doc

    Doc

  3. Did you register the event?
     
    • Agree Agree x 1
  4. if its doesn't work it means that you don't made it correctly don't just tell that please read the read if he don't read the thread he won't tell you a great answear indeed for me.


    Code (Java):
    InventoryOpenEvent

    if(e.getInventory() instanceof PlayerInventory) {
    // do something
    }
     
    #5 MadMaxCookie, May 26, 2016
    Last edited: May 26, 2016
  5. It's unfortunately not possible to tell whether or not the player actually has their inventory open, and it's always considered open.
     
  6. then do this thing inside the event
    Code (Java):
    Player p = (Player) e.getPlayer();
    p.closeInventory(Inventory inventory);
     
    • Optimistic Optimistic x 1
  7. How is that going to help?
    1) The player inventory is in a constant open state.
    2) He still wouldn't be able to tell if they opened their inventory
     
  8. you can tell it from the inventoryopenevent using if (e.getInventory()) // get the inventory opened by player.
     
  9. Yes. But he's talking about the player's own inventory, which is never closed nor opened, meaning it's in a constant open state. And he wants to know whether or not the player has their inventory open.
     
  10. uhhmm kay. doesn't need the event since then.
     
  11. Ah, well that sucks, anyways thanks Nexuz.
     
  12. All you can do is probably to close the inventory when the player clicks an item ...
     
  13. Notchian clients send a packet when they open the inventory so the server can handle the archievement. Capture that using protocollib and profitö
     
  14. I've though of doing that, theres also an event, but I feel as if its ghetto in a way. Thanks anyway!