[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 |
||
| Issue Links: |
|
||||||||||||||||||||||||
| 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:
Notes: 1.15.2 plays a player arm swing animation whenever the player drops an item. |
| 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. |