Next Try with InventoryCloseEvent

Discussion in 'Plugin Development' started by xasz, Mar 30, 2012.

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

    xasz

    Some weeks ago i got the Problem, that i could't trigger a ChestCloseEvent.

    Now i saw this:
    https://bukkit.atlassian.net/browse/BUKKIT-796

    Quote: "InventoryOpenEvent and InventoryCloseEvent do this, and not just for chests."

    I tryed this code, but it didn't work.
    Have you any Idea ?
    Code:
      @EventHandler(priority = EventPriority.NORMAL)
      public void InventoryCloseEvent(InventoryEvent transaction){
        plugin.getServer().broadcastMessage("InventoryClose");
        System.out.println("inventoryclose");
      }
    Thanx
     
  2. Offline

    CorrieKay

    I'd say to try casting the event to InventoryOpen/Close events.

    Code:
    if(event instanceof InventoryCloseEvent){
    InventoryCloseEvent closeEvent = (InventoryCloseEvent)event;
    }
    and working off of closeEvent.
     
  3. Offline

    xasz

    But which method do i have to use then ?
    Code:
      @EventHandler(priority = EventPriority.NORMAL)
      public void <WhichMethoidName>(Event transaction){
        if(event instanceof InventoryCloseEvent){
            InventoryCloseEvent closeEvent = (InventoryCloseEvent)event;
        }
      }

    OK. I got the solution.

    How it worked for me.
    Code:
      @EventHandler(priority = EventPriority.NORMAL)
      public void onInventoryClose(InventoryCloseEvent event){
        plugin.getServer().broadcastMessage("Close Inventory");
      }
     
  4. the name of the method doesn't matter anymore. What matters is the argument, the event.
     
  5. Offline

    xasz

    Ah, ok. then i fully got the new eventsystem. Thought still you have to use right method names. Thanks for that.

    I got now another problem, related to this.

    I now get an Event on Inventory Close, eg. Chest Close.
    But my goal is to get the event related chest.
    From the InventoryCloseEvent i can get the InventoryHolder, but then i do not know what to do.

    event.getInventory().getHolder()

    how can i get from this or the event to the Chest as Block or Chest.

    Thanx for helping me.

    Edit:
    NVM. I can cast the InventoryHolder to a CraftChest.
     
  6. No you don't have to! That's the nice thing about it. Sure you still can, but you don't need to.
     
Thread Status:
Not open for further replies.

Share This Page