[SPIGOT-1353] PlayerInteractEvent is cancelled when right-clicking air Created: 18/Dec/15  Updated: 23/Dec/15  Resolved: 18/Dec/15

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

Type: Bug Priority: Minor
Reporter: Oliver Brammer Assignee: Unassigned
Resolution: Won't Fix Votes: 0
Labels: Craftbukkit, bug
Environment:
CraftBukkit version git-Spigot-db6de12-18fbb24 (MC: 1.8.8) (Implementing API version 1.8.8-R0.1-SNAPSHOT)

Plugins (1): Tower_Control

JRE 1.8


 Description   

EventHandler call is cancelled for PlayerInteractEvent when the player interacts with Material.AIR

Sample code (working):

    @EventHandler(priority = EventPriority.HIGHEST)
    public void onPlayerInteract(PlayerInteractEvent event) {
        final Action action = event.getAction();
        final Player bukkitPlayer = event.getPlayer();

        final BattlePlayer player = gameController.getBattlePlayer(bukkitPlayer);
        if (player == null) return;

        if (!bukkitPlayer.getItemInHand().getType().equals(player.getWeapon().getBukkitMaterial())) return;
        if (!(action.equals(Action.RIGHT_CLICK_BLOCK) || action.equals(Action.RIGHT_CLICK_AIR))) return;

        final Projectile projectile = event.getPlayer().launchProjectile(player.getWeapon().getAmmunitionProjectileClass());
        projectile.setShooter(bukkitPlayer);

        double multiplier = ThreadLocalRandom.current().nextDouble(0, 1);
        projectile.setVelocity(projectile.getVelocity().multiply(multiplier));
    }

However, setting ignoreCancelled to true on the annotation means this does not get called - indicating that the event is being cancelled. Whether or not this is normal behaviour for this event, I'm not so sure. If it is normal, then it would be helpful if it could be documented.



 Comments   
Comment by Ryan Hamshire [ 23/Dec/15 ]

If I remember right, the workaround is to set your event handler at lower priority so that you see the click air event before it's cancelled. I've done this in a couple of my plugins.

Comment by Oliver Brammer [ 18/Dec/15 ]

Yes, but it's still not documented...

Comment by Hex [ 18/Dec/15 ]

This is intended.

Generated at Tue Apr 08 01:20:41 UTC 2025 using Jira 10.3.3#10030003-sha1:d220e3fefc8dfc6d47f522d3b9a20c1455e12b7b.