Excluding player inventory clicks when using dispenser

Discussion in 'Plugin Development' started by darkhelmet, Jan 3, 2013.

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

    darkhelmet

    I'm using onInventoryClick to figure out when an item is placed in or removed from a container. I have working code for chests/furnaces but the code won't work when using a dispenser.

    For the chests/furnaces I check if(event.getSlot() == event.getRawSlot()) and they never match, but this is no longer true when the player is accessing the dispenser. Relevant part of my code:

    Code:
    Inventory inv = event.getInventory();
    InventoryHolder ih = inv.getHolder();
    // Dispenser
    if(ih instanceof Dispenser) {
        Dispenser dispenser = (Dispenser) ih;
        containerLoc = dispenser.getLocation();
        plugin.debug("SLOT: " + event.getSlot());
        plugin.debug("RAW SLOT: " + event.getRawSlot());
    }
     
  2. Offline

    gomeow

    I have been doing a lot with this for my new plugin, give me a few minutes and I will post some code.


    Edit (found it):
    You may need to change it a bit to fit your needs
     
  3. Offline

    darkhelmet

    Repeated from irc for others interested.

    The code you provided is very similar to what I use overall, but it doesn't make a distinction between a dispenser and the player's inventory. I have the same SlotType.CONTAINER check in my code but the following code still fires twice - once for the player inventory click, and then for the dispenser.

    For anyone interested, checking if the slot clicked was < 9 (player inv is 9-35) works:
    http://pastie.org/private/sgyzprmeidzqnlruhhvvqa

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

Share This Page