[SPIGOT-6786] PlayerInteractEvent Should Not Run As Cancelled When Interacting With Air Created: 04/Nov/21 Updated: 23/Nov/21 |
|
| Status: | Open |
| Project: | Spigot |
| Component/s: | None |
| Affects Version/s: | None |
| Fix Version/s: | None |
| Type: | Bug | Priority: | Minor |
| Reporter: | Austin Dart | Assignee: | Unassigned |
| Resolution: | Unresolved | Votes: | 0 |
| Labels: | PlayerInteractEvent, improvement | ||
| Attachments: |
|
| Version: | 3274-Spigot-3892929-eb19161 |
| Guidelines Read: | Yes |
| Description |
|
According to Spigot's JavaDocs, the PlayerInteractEvent runs as cancelled if a player interacts with air. Quote: "This event will fire as cancelled if the vanilla behavior is to do nothing (e.g interacting with air)."
This should not be the case, because right-clicking the air with an armor piece can equip the armor piece in your hand. A cancelled event suggests this is not happening.
To demonstrate the issue, I have included a plugin which broadcasts two messages - one from listening to the PlayerInteractEvent with ignoreCancelled = true, and one with ignoreCancelled = false. |
| Comments |
| Comment by Ssomar [ 23/Nov/21 ] |
|
In fact this event is quite special, because it count the block interaction and the air interaction. (and as its mentionned in the javadoc the isCancelled() is deprecated so avoid to use it) "This event will fire as cancelled if the vanilla behavior is to do nothing (e.g interacting with air)." So yes the event is fired as cancelled because you interact with air when you equip an armor, but it is not completly cancelled, because if it is complety cancelled the vanilla things like launch projectiles, or like your example equip armor will be cancelled, that is bad. To cancel the air interaction of the event you can add
e.setCancelled(true);
or
e.setUseItemInHand(Event.Result.DENY);
|
| Comment by Austin Dart [ 04/Nov/21 ] |
|
I thought I clicked "Improvement," but now "Improvement" has disappeared. |