[SPIGOT-5632] Dropping an item while targetting air causes a PlayerInteractEvent Created: 24/Mar/20  Updated: 20/Aug/23  Resolved: 24/Mar/20

Status: Resolved
Project: Spigot
Component/s: None
Affects Version/s: None
Fix Version/s: None

Type: Bug Priority: Major
Reporter: Bjarne Koll Assignee: Unassigned
Resolution: Duplicate Votes: 0
Labels: 1.15.2, bug
Environment:

Ubuntu 18.04
Java 13


Issue Links:
Duplicate
duplicates SPIGOT-5435 Hand calls twice PlayerInteractEvent ... Resolved
is duplicated by SPIGOT-5974 PlayerInteractEvent fired for certain... Open
is duplicated by SPIGOT-5634 PlayerInteractEvent fires when item i... Resolved
is duplicated by SPIGOT-5661 Dropping Item fires wrong event Resolved
is duplicated by SPIGOT-5904 PlayerDropItemEvent fires PlayerInter... Resolved
Version: version git-Spigot-a03b1fd-fc318cc (MC: 1.15.2)
Guidelines Read: Yes

 Description   

Dropping an item while not targeting a block causes spigot to publish a PlayerInteractEvent to the event handlers.

This bug, at least in my opinion, is rather game breaking for most plugins which now execute logic when the player drops as well as at the intended point when the player actually left clicks the air.

Steps to reproduce:

  • Get the latest version of spigot
  • Register a listener for the PlayerInteractEvent in a plugin
  • InGame; Drop an itemstack from your inventory hotbar using the hotkey 'q' (if configured so) while NOT looking at a block.
  • Your plugin's listener now received a PlayerInteractEvent with the Action LEFT_CLICK_AIR.

Notes:
As I currently do not have the time to actually fix this myself I did some digging anyway.
My current guess on the culprit (I repeat, guess) would be:

1.15.2 plays a player arm swing animation whenever the player drops an item.
This causes PlayerConnection#a(PacketPlayInArmAnimation) to be executed, which is used to even catch any LEFT_CLICK_AIR interactions.
This method currently does not know if the animation was played because the player left clicked or dropped an item and therefore calls both.



 Comments   
Comment by Shane Martin [ 20/Aug/23 ]

So if anyone runs across this later looking for a solution, in one of the affected versions there is a workaround.

 

The PlayerDropItemEvent fires BEFORE PlayerInteractEvent.

 

If you store a "cooldown" for the player when they drop an item..  You can then check to see if that cooldown has expired in the interact event.

 

EG:

HashMap of <Player,Long> namedWhatever somewhere you can access it later.
 
onPlayerDropItem(PlayerDropItemEvent e) {
  namedWhatever.put(e.getPlayer(), System.currentTimeMillis() + 15);
 }

onPlayerInteract(PlayerInteractEvent e) {
  if(namedWhatever.containsKey(e.getPlayer() && System.currentTimeMillis() < namedWhatever.get(e.getPlayer())
  //return/setcancelled/whatever but now you know they recently pressed q
}
  

You may need to play with the values, but it should happen pretty fast, 15ms is probably plenty long to detect a drop item before the interact fires.

 

Comment by md_5 [ 24/Mar/20 ]

Yes your analysis is correct, but the only way it could be fixed is just completely removing the left click air event.

https://hub.spigotmc.org/jira/browse/SPIGOT-5435?focusedCommentId=35082&page=com.atlassian.jira.plugin.system.issuetabpanels%3Acomment-tabpanel#comment-35082

Generated at Sat Dec 13 13:38:46 UTC 2025 using Jira 10.3.13#10030013-sha1:56dd970ae30ebfeda3a697d25be1f6388b68a422.