[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. |
| 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:
|
| Comment by md_5 [ 30/Jun/17 ] |
|
1) The event is fired for each hand. @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:
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. |
| 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 |