Search code examples
bukkitinventory

Event when moving itemstack to other inventory


Every time a player issues a specific command, a virtual inventory is being generated from the contents of a MySQL table and then shown to the player. That's working fine.

Now, when the player is moving items from this virtual inventory to his own Inventory, it should check if the items are still in the database. If not, the event should be cancelled. And when the player moves items from his inventory to the virtual inventory, they should be added to the database table.

I have no problem with the MySQL queries, but I don't know which EventHandler I should use for the events (Player Inv -> Virtual Inv, Virtual Inv -> Player Inv). Bukkit Inventory Events

InventoryMoveItemEvent would be perfect, but it's only called when blocks (hoppers, dispensers, etc.) move items, not players.

InventoryClickEvent is no solution, because there are many different possibilities to move the items to another inventory:

  • Shift-clicking would call the event only once
  • Picking the item up and using the cursor for moving it to the other inventory would call the event twice.
  • Picking up an itemstack and spreading its items across the other inventory would call InventoryClickEvent and InventoryDragEvent.
  • and so on...

Anyone got an idea how I could solve this problem?


Solution

  • I have a simple solution to this, Use the InventoryCloseEvent and then check on close if the inventory contents are the same as what was in the database, if not then update the database with the new inventory and vice versa.