Solved Check if a player is moving an object

Discussion in 'Spigot Plugin Development' started by Obsidi4nPvP, Feb 1, 2020.

Thread Status:
Not open for further replies.
  1. 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
  2. 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.
  3. 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.
  4. 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.
    • Agree Agree x 1
  5. 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
  6. If you're in InventoryCloseEvent, you can do

    for InventoryClickEvent it is

    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.
    • Useful Useful x 1
  7. Thanks you, with this i have solved
    • Optimistic Optimistic x 1
Thread Status:
Not open for further replies.