[SPIGOT-5435] Hand calls twice PlayerInteractEvent when using potions Created: 11/Dec/19 Updated: 13/Apr/21 Resolved: 13/Dec/19 |
|
| Status: | Resolved |
| Project: | Spigot |
| Component/s: | None |
| Affects Version/s: | None |
| Fix Version/s: | None |
| Type: | Bug | Priority: | Minor |
| Reporter: | xtomyserrax | Assignee: | md_5 |
| Resolution: | Invalid | Votes: | 1 |
| Labels: | 1.15, PlayerInteractEvent | ||
| Attachments: |
|
||||||||||||||||||||||||
| Issue Links: |
|
||||||||||||||||||||||||
| Version: | git-Spigot-f39a89e-f777640 (MC: 1.15) (Implementing API version 1.15-R0.1-SNAPSHOT) | ||||||||||||||||||||||||
| Guidelines Read: | Yes | ||||||||||||||||||||||||
| Description |
|
This is a behaviour that doesnt happen in spigot 1.14.4 but yes in the 1.15 version.
When right clicking potions and pointing the air, the PlayerInteractEvent is being called twice with Hand (I am cancelling the call if Off hand is calling). This doesnt happen if you are right clicking a block or a mob, just the air. And this doesnt happen if you are using left click.
I have made a test plugin so you can see it, basicly, just interact with items and you will notice the difference. The plugin tells you that the event is being called, with which item and if HAND called it. Also, I recorded a video, which I couldnt upload because of size but here is the link: https://streamable.com/ed1do
As far as I tested this bug happens with this items: (it doesnt happen with GLASS_BOTTLE)
Source code of test plugin: https://pastebin.com/VPLpmMme |
| Comments |
| Comment by xtomyserrax [ 13/Dec/19 ] |
|
Okay md_5, thanks a lot for researching. We can code some workarounds when using the event in our own plugins if we need to use potions so it wont be a big problem. Thank you for your work! |
| Comment by md_5 [ 13/Dec/19 ] |
|
Yeah what I said on IRC — we have to trigger the LEFT_CLICK_AIR event based on the arm swing animation because the client has no other packet for it. So this can't be fixed without removing LEFT_CLICK_AIR entirely which would cause greater strife than the two events. |
| Comment by Xinrui Ding [ 13/Dec/19 ] |
|
Can confirm, The player's hand moves twice when you click/break
|
| Comment by xtomyserrax [ 12/Dec/19 ] |
|
So is this behaviour a vanilla issue? |
| Comment by xtomyserrax [ 12/Dec/19 ] |
|
It behaves the same if you are in creative or in survival (except when I throw a splash potion in survival mode). I checked with both events and:
Also another thing, the PlayerInteractEvent only happens twice when I am aiming right clicking the air, not if I am right clicking a block or a mob. |
| Comment by Black Hole [ 11/Dec/19 ] |
|
If the client is sending two packets for the same hand, it's not possible to distinguish the two events. Please also test if the client behaves differently in creative and survival mode. |
| Comment by xtomyserrax [ 11/Dec/19 ] |
|
My code already returns the event if it is the OffHand. I thought you meant another thing with "each hand", here is the code of the test plugin I attached and the one using in the video Iink I put in the description: @EventHandler
public void PlayerInteractEvent(PlayerInteractEvent e) {
if (e.getHand() == EquipmentSlot.OFF_HAND)
return;
e.getPlayer().sendMessage("You are interacting with: " + e.getItem().getType().toString());
if (e.getHand() == EquipmentSlot.HAND)
e.getPlayer().sendMessage("Your HAND called the event");
}
|
| Comment by Black Hole [ 11/Dec/19 ] |
|
I'm confused, you're already using PlayerInteractEvent.getHand(). |
| Comment by xtomyserrax [ 11/Dec/19 ] |
|
Is there a way we can check which hand was? When I use e.getHand I can compare with HAND or OFF_HAND |
| Comment by Black Hole [ 11/Dec/19 ] |
|
Spigot calls those events for each packet received by the client. So it seems the client is sending one packet for each hand here now, too. |