[SPIGOT-7429] PlayerInteractEvent LEFT_CLICK_AIR not working with spectator/passable entities Created: 15/Jul/23  Updated: 25/Dec/24  Resolved: 18/Jul/23

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

Type: Bug Priority: Minor
Reporter: Collin Barber Assignee: Unassigned
Resolution: Fixed Votes: 0
Labels: None
Environment:

Just built a clean server an hour ago with Spigot 1.20.1, 1 plugin for testing the bug


Attachments: File LeftClickAirBug-1.0.0.jar     Text File latest.log    
Version: This server is running CraftBukkit version 3830-Spigot-0ca4eb6-36b1076 (MC: 1.20.1) (Implementing API version 1.20.1-R0.1-SNAPSHOT)
Guidelines Read: Yes

 Description   

Here is a video explaining the issue in detail: https://youtu.be/F4PjLW__G0w

Source code (+built plugin) below.

Basically, the issue is that spectators (and some entities) are interfering with ray tracing, which causes the PlayerInteractEvent to be skipped when it should be called for LEFT_CLICK_AIR.

This predicate should be good to solve it (untested):

in ServerGamePacketListenerImpl#handleAnimate

!((CraftEntity)entity).getHandle().isSpectator() && ((CraftEntity)entity).getHandle().isPickable()
import org.bukkit.Bukkit;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.player.PlayerInteractEvent;
import org.bukkit.plugin.java.JavaPlugin;

public class Main extends JavaPlugin implements Listener {

    @Override
    public void onEnable() {
        getServer().getPluginManager().registerEvents(this, this);
    }

    @EventHandler
    public void onInteract(PlayerInteractEvent event) {
        Bukkit.broadcastMessage("Interaction: " + event.getAction());
    }
}


 Comments   
Comment by Collin Barber [ 17/Jul/23 ]

If you left click air through your mount, it will not cause a `PlayerInteractEvent`.  Since punching mounts/passengers does not cause damage, the `PlayerInteractEvent` for `LEFT_CLICK_AIR` should definitely be called.

Comment by md_5 [ 17/Jul/23 ]

How come? Players shouldn't be overlapping their vehicle? Especially if the vehicle is at the bottom of a stack?

Comment by Collin Barber [ 15/Jul/23 ]

I forgot to mention that this should also affect players riding and players with other entities mounted. This may affect other cases but these are the ones I thought of. 

Generated at Fri Apr 11 16:22:17 UTC 2025 using Jira 10.3.3#10030003-sha1:d220e3fefc8dfc6d47f522d3b9a20c1455e12b7b.