Solved Inventory Click Event (need help)

Discussion in 'Plugin Development' started by InflamedSebi, Sep 27, 2013.

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

    InflamedSebi

    I try to get the inventory that was clicked due to an InventoryView contains 2 inventories ...
    there is an:
    event.getInventory();
    but the documentation said

    public Inventory getInventory()
    Gets the primary Inventory involved in this transaction
    Returns:
    The upper inventory.


    So it will return the upper inventory? but how do i get the inventory that was clicked?
     
  2. Offline

    amhokies

    InflamedSebi
    It means that it gets the inventory that the player is interacting with. For instance, if they are in a chest, brewing stand, etc, it will return that inventory instead of the player's.
     
  3. Offline

    InflamedSebi

    amhokies sure ... the upper one ... but i want to know how do i get the inventory that the player was clicking in ...

    this can be the upper one but also the lower one ...
     
  4. Offline

    amhokies

    Code:java
    1. event.getWhoClicked().getInventory();

    Gets the player's inventory.
    Code:java
    1. event.getInventory();

    Gets the inventory that the player has open, whether it is a chest or whatever, no matter if the player clicked in their own inventory or the other inventory.
     
  5. Offline

    InflamedSebi

    amhokies
    i already know how to get the inventories but thats not what i asked for ... if the player clicked on the upper inventory i want to do something ... but if he clicked on the lower inventory (his) it just should cancel the event ...

    but i cant find out wich inventory was clicked ... and thats what i was asking ... how to figure out which inventory was clicked ...
     
  6. Offline

    Loogeh

    InflamedSebi I did it by checking if the slot id clicked was between certain values. Just find out what the values are and then check if the clicked slot's id is within the range.
     
  7. You can use getRawSlotId() and getSlotId() to check this:
    Code:java
    1. if (event.getRawSlotId() == event.getSlotId()) {
    2. doWhatYouWantWithTheUpperInventory();
    3. }
    4. else {
    5. doWhatYouWantWithTheLowerInventory();
    6. }
     
Thread Status:
Not open for further replies.

Share This Page