Inventory Close Event and Cursor Items

Discussion in 'Plugin Development' started by x2nec, Mar 18, 2013.

Thread Status:
Not open for further replies.
  1. Hey, I was wondering if, when the inventorycloseevent is fired - is there anyway to make any itemstacks on the cursor at the time drop back into the inventory it came from? At the moment, I have something that opens two player inventories so that one can take from the other (like /invsee in essentials). The only thing is I don't want the cursor item to just drop when inventory is closed on it. Is there anyway to do this?

    Thanks, -x3nec
     
  2. Offline

    chasechocolate

    Just cancel the event after checking if the inventories compare.
     
  3. You can't cancel InventoryCloseEvent because it's only a notification from the client.

    You could try to get the cursor items and add them to the inventory then set the cursor to null.
     
  4. Okay but I have two player inventories open, so I have no idea how to tell which one the cursor itemstack came from?
     
  5. First test if you can get the item and store it in the player's inventory then clear it so it doesn't drop, if that works then you can worry about detecting from which inventory it originated.
     
  6. Yes but that's the problem bit :p I'm capable of doing the first part easily, it's just the knowing which inventory it came from..
     
  7. You need a Map<String, Inventory> to store which inventory the item in the cursor originated from.

    First you need to see when they actually get an item in their cursor and try to see what clicks don't actually drop the entire cursor so you can ignore those.
    You'll have to print messages with event's data to figure that out.

    Some cases that I can think of:
    - click a non-null slot with left click would pick up an item
    - click a null slot with right click would place an item if it's only 1 amount
    - click a non-null slot with right click would update the stack if they're the same (item.isSimilar()) or it will replace the item if they're not
    - shift+left/rightclick would usually send the clicked item in the other inventory, these should be ignored I guess
    ...and Like I said, you should do some serious testing to figure it out :p

    There's the problem with missing middle-click detection and the new MC 1.5 inventory drag, double click and stuff aren't fully detectable.
     
Thread Status:
Not open for further replies.

Share This Page