Hi, I'm looking for a way to check if a player is moving an object. For example when you are moving an item from inventory to a chest, To better understand during this if the inventory is closed the object is left on the ground... Like this. Thanks
Using the InventoryClickEvent is probably your best choice. You then would need to keep track of when a player picks up an item and places it. What are you trying to accomplish? There could be better ways about going this.
Thanks for the reply. I'm looking for a way to close a chest when a player is more distant than a number of blocks. For example, if a chest is opened, going down the stairs after a while it should close due to the distance. All this without dropping the object on the ground, but putting it back in the inventory.
If you're dealing with the default Minecraft distance, and you only don't want the blocks to drop. You could just use InventoryCloseEvent, and get the item from the player's cursor. (If it still drops you may need to cancel the event, and manually close it after) If you want a custom distance, you could maybe store the players that clicked on items with the location of the container in some kind of list and checking on PlayerMoveEvent if the distance between the container and where the player is is greater than your value. Then get the item on the cursor of the player, and add that to their inventory. Then close the inventory manually. Checking if a List contains a player every time on PlayerMoveEvent doesn't sound very efficient, but I wouldn't know how you would go about checking it otherwise.
I'm in front of the IDE but no method like getCursor() or similar appears in the code hints. Do you know how to do it? Using the 1.15.1 spigot jar
If you're in InventoryCloseEvent, you can do event.getPlayer().getItemOnCursor(); for InventoryClickEvent it is event.getCursor(); Where are you having problems? BTW, you should check if the item is null or AIR, and escape the code if that's the case, otherwise, you'll probably get errors.