get Block from InventoryOpenEvent

Discussion in 'Plugin Development' started by Codisimus, Mar 28, 2012.

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

    Codisimus

    I need to know when a Player opens a Chest. Currently I assume that they open it when the right click a chest. I figured it would be better to use onPlayerOpenInventory but I do not know how to figure out what Block the Inventory belongs to. The API did not help. If someone knows how to do this I would appreciate the help, or maybe the way I have not is ideal. Plugin is PhatLoots. Here is the source for my Listener class.
    Thanks, Codisimus
     
  2. Offline

    nisovin

    You would use the InventoryOpenEvent. It has a getInventory() method, which returns an Inventory, which has a getHolder() method, which returns an InventoryHolder, which can be cast to a Chest, which is a BlockState, which has a getBlock() method.
     
    Casier and Codisimus like this.
  3. Offline

    Codisimus

    Thanks for the quick response, I guess I should've notice the Inventory Holder, but thanks for clearing that up.

    Ok, so I how can I be sure that the Holder is a Chest? I can check if instanceof DoubleChest but not a single Chest?

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: May 24, 2016
Thread Status:
Not open for further replies.

Share This Page