Cancelling the InventoryClickEvent

Discussion in 'Plugin Development' started by bobacadodl, Feb 6, 2013.

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

    bobacadodl

    So in my plugin, I'm opening up a virtual chest inventory for the player. I want the player to be able to move around items in the top inventory, but not in the bottom inventory(the player's inventory). I also don't want them to be able to take items from the top inventory and put them into their inventory.

    So, in my plugin I detect which inventory they click in, and if it is the bottom inventory, cancel it.
    Code:
    @EventHandler(priority=EventPriority.HIGHEST, ignoreCancelled=false)
        public void onInventoryClick(InventoryClickEvent e){
            if(e.getInventory().getTitle().equals(inv.getTitle())){
                if(e.getRawSlot()<54){
                    e.setCancelled(false);
                }
            }
        }
    (I'm normally canceling ALL inventoryClickEvents in a different listener class. That's why I am only UNCANCELLING if it is in the top inventory.)

    When players close this inventory, I'm unregistering this listener.

    The problem that is occurring is that players are able to drag items from the top inventory into their bottom inventory. Also, when the inventory is closed, the OTHER inventoryInteractListener which cancels all inventory interact events seems to stop working.
     
  2. Offline

    DJSanderrr

    bobacadodl i thoutgh maybe check if th invslot is MORE. Than 54
     
  3. Offline

    arrexe

    Try using a single listener, but before it decides whether or not to cancel the event, check if your custom inventory is open.

    Not 100% sure, but it sounds like it would be much more efficient and less complicated.
     
  4. Offline

    bobacadodl

    I was thinking about trying this, it might work..

    DJSanderrr No....
     
  5. Offline

    DJSanderrr

    Okay sorry then i guess i dont understand what you mean.
     
Thread Status:
Not open for further replies.

Share This Page