[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: File NewSpigotReportPlugin.jar     File SpigotReportPlugin.jar    
Issue Links:
Duplicate
is duplicated by SPIGOT-5632 Dropping an item while targetting air... Resolved
is duplicated by PLUG-370 dropping items fires interact event Resolved
is duplicated by SPIGOT-5452 Right clicking entity calls PlayerInt... Resolved
is duplicated by SPIGOT-6044 PlayerInteractEvent Trigger left clic... Resolved
is duplicated by SPIGOT-6421 PlayerInteractEvent gets called for R... Resolved
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)

  • POTION (any kind)
  • SPLASH_POTION (any kind)
  • LINGERING_POTION (any kind)
  • EXP_BOTTLE
  • HONEY_BOTTLE
  • ENDER_PEARL
     

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?
I discovered something new. The event is being called twice with the same hand (not offhand). The only difference is that first the action is RIGHT_CLICK_AIR, and the second time the action is LEFT_CLICK_AIR (and I just right clicked the air with the potion)

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:

  • If I consume the potion: first it fires the PlayerInteractEvent twice, and then it fires the PlayerItemConsumeEvent (This one behaves exactly the same whether I am in creative or survival)
  • If I use a splash potion: it fires one PlayerInteractEvent,, then it fires ProjectileLaunchEvent, then it fires PlayerInteractEvent again! (I am using only one splash potion) ; If I am in survival mode, it just calls PlayerInteractEvent once, if I am in creative, twice.

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.
Have a look at other events, like PlayerItemConsumeEvent or ProjectileLaunchEvent.

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.

Generated at Sat Dec 13 15:25:57 UTC 2025 using Jira 10.3.13#10030013-sha1:56dd970ae30ebfeda3a697d25be1f6388b68a422.