[PLUG-248] Events can't be cancelled when launching an item to an entity Created: 30/Jun/17  Updated: 30/Jun/17  Resolved: 30/Jun/17

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

Type: Bug Priority: Major
Reporter: Vontus Assignee: Unassigned
Resolution: Invalid Votes: 0
Labels: 1.10, 1.11, 1.12, bug, entity, event

Plugin: MagicBottle

 Description   

I can't prevent items like snowballs and xp bottles to be thrown to entities by cancelling PlayerInteractEntityEvent. Also, cancelling ProjectileLaunchEvent does not make the trick for me as I need players to keep the items in their inventories.

Aside from PlayerInteractEvent has the same problem, but is looks like you have to right click a block with your hand before and then to an entity with a throwable item (I haven't looked too much into this).

I'm having this issue with MagicBottle, specially using PlayerInteractEvent, but the issue can be easily reproduced by just cancelling the event and throwing a snowball to an entity.



 Comments   
Comment by Vontus [ 30/Jun/17 ]

Okay thank you for trying

Comment by md_5 [ 30/Jun/17 ]

Cannot reproduce using wither skeleton and red sand in creative.

Comment by Vontus [ 30/Jun/17 ]

I'm sorry to be annoying but it took me weeks to realize this bug wasn't caused by my plugin. There's no workaround I can find and it happens in every server I've tried.

I made another video, can you at least identify the bug in it? Please see I'm clicking the entity twice with an item, but only the second time shows the message. Only happens when right clicking on any block first with your bare hand.

https://puu.sh/wxYpo/3aaf4c34c0.mp4

Comment by md_5 [ 30/Jun/17 ]

Cannot reproduce

Comment by Vontus [ 30/Jun/17 ]

 

public void onInteract(PlayerInteractEvent e) {
    Bukkit.broadcastMessage("you clicked something");
    e.setCancelled(true);
}

 

Please use the previous code and follow these steps:

  1. Right click the floor with your hand: The message will be displayed twice (once for each hand, that's okay)
  2. Right click an entity with an item right away: The message WONT be displayed <- Here is the bug
  3. Right click the entity again: The message will be displayed as normal
Comment by md_5 [ 30/Jun/17 ]

1) The event is fired for each hand.
2) That event is not for throwing stuff, the normal interact event works fine.

    @EventHandler
    public void event(PlayerInteractEvent event)
    {
        event.setCancelled( true );
    }

This prevents throwing.

Comment by Vontus [ 30/Jun/17 ]

Sorry, I don't completely understand what's going on and I'm not fluent in english, but I'll try to explain it in a different way.

It looks like there are two problems with two different events:

  1. PlayerInteractEvent. Which is fired twice when right clicking a block with your hand and isn't fired when you right click an entity for the first time after clicking the block. Also, if you cancel the event of right clicking the block, when you right click the entity the next time it seems to "re-use" the cancelled status.
  2. PlayerInteractEntityEvent. Cancelling this event doesn't prevent snowballs, eggs, potions and xp bottles to be thrown to entities.

You can see the video in the comment to see the first problem. This is the code I used to test it:

public void onInteract(PlayerInteractEvent e) {
  Bukkit.broadcastMessage(e.getAction().toString());
  if (e.getAction() == Action.RIGHT_CLICK_AIR || e.getAction() == Action.RIGHT_CLICK_BLOCK) {
    e.setCancelled(true);
    Bukkit.broadcastMessage("cancelled");
  } else {
    Bukkit.broadcastMessage("not cancelled");
  }
}
Comment by md_5 [ 30/Jun/17 ]

Not sure what you're trying to say.
Are you saying that cancelling PlayerInteractEvent will not stop vanilla items from being thrown (no other plugins?)

Comment by Vontus [ 30/Jun/17 ]

So, looks like if you click a block with your bare hand the event is called twice (maybe one time for every hand) but when you right click an entity after that, no PlayerInteractEvent is fired, and the cancelled status is saved from when you clicked the block.

 Here is a video to explain it: https://puu.sh/wxVUq/4ab88940cd.mp4

Generated at Sat Dec 13 02:30:13 UTC 2025 using Jira 10.3.13#10030013-sha1:56dd970ae30ebfeda3a697d25be1f6388b68a422.