How to detect when dispenser inventory is closed?

Discussion in 'Plugin Development' started by Etsijä, Apr 27, 2014.

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

    Etsijä

    Simple question, for which I do not seem to find an answer: in my code I have currently

    Code:java
    1. @EventHandler
    2. public void onDispenserInteract(final PlayerInteractEvent event) {
    3. Block b = event.getClickedBlock();
    4.  
    5. if (b != null && b.getType() == Material.DISPENSER) {
    6. ...
    7. }
    8. }


    This event fires when the dispenser inventory is opened with a right-click. Is there a way to detect when and where (in the world) it is closed? InventoryCloseEvent doesn't seem to be the answer, since it relates to the player inventory, not the dispenser.
     
  2. Offline

    Deleted user

    Try using InventoryCloseEvent.getInventory().getType().
     
  3. Offline

    Etsijä

    Yes, that would give me the time when an inventory of a dispenser is closed, but how would I be able to get the location?
     
  4. Offline

    Deleted user

    Try using InventoryCloseEvent.getInventory().getLocation().
     
  5. Offline

    Etsijä

    I already checked, and there is no such method.
     
  6. Offline

    Onlineids


    Code:java
    1. @EventHandler
    2. public void onClose(InventoryCloseEvent e){
    3. if(e.getInventory().getType().equals(InventoryType.DISPENSER)){
    4. //They closed a dispenser
    5. }
    6. }
     
  7. Offline

    Gater12

  8. Offline

    Etsijä

    Gater12: seems you've nailed it. Thank you.
     
Thread Status:
Not open for further replies.

Share This Page