Solved Is it possible to get the chest in InventoryClickEvent?

Discussion in 'Plugin Development' started by gomeow, Dec 28, 2012.

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

    gomeow

    I need to get the location of a chest inventory.

    Code:java
    1. @EventHandler
    2. public void onInvClick(InventoryClickEvent event) {
    3. if(!(event.getWhoClicked() instanceof Player)) return; //Make sure it was a player.
    4. if(event.getSlotType() != SlotType.CONTAINER) return; //Make sure it is the chest's inventory.
    5. if(!(event.getInventory().getType() == InventoryType.CHEST)) return; //Make sure it was a chest.
    6. Player p = (Player) event.getWhoClicked();
    7. if(event.getInventory().getItem(event.getSlot()) != null) { //Make sure it was a withdrawal.
    8. Location chestLoc = ?;
    9. }
    10. }
     
  2. Offline

    caldabeast

    I *think* (sudo-code)

    Code:java
    1.  
    2. InventoryHolder ih = event.getInventory().getHolder();
    3. if(ih instanceof Block){
    4. Location chestLoc = ((Block)ih).getLocation();
    5. }
    6.  


    Some variant of that could work.
     
    xGhOsTkiLLeRx and gomeow like this.
  3. Offline

    gomeow

    Works, thanks!
     
    caldabeast likes this.
  4. Offline

    caldabeast

    How much of that code was right?
     
  5. Offline

    gomeow

    I changed it around quite a bit for what I need, such as testing if it was a chest/double chest, but that code should work
     
    caldabeast likes this.
  6. Offline

    lzravanger

    Now try to do it with a beacon and have fun. It requires getting the view, the viewing player, his line of sight, and then checking to see if that line of sight matches up with a beacon.
     
  7. Offline

    fireblast709

    @Izravanger ...? The holder of the inventory is the block, so not a clue what you want there ;D
     
  8. Offline

    lzravanger

    It wasn't working that way for me, but my way works so I'm happy, i can optimize it in a bit if I want to.
     
Thread Status:
Not open for further replies.

Share This Page