[SPIGOT-1198] BlockBreakEvent triggered in creative mode while holding sword. Created: 21/Sep/15 Updated: 30/Jun/16 Resolved: 30/Jun/16 |
|
Status: | Resolved |
Project: | Spigot |
Component/s: | None |
Affects Version/s: | None |
Fix Version/s: | None |
Type: | Bug | Priority: | Minor |
Reporter: | jjm_223 | Assignee: | Unassigned |
Resolution: | Invalid | Votes: | 1 |
Labels: | 1.8.8, blocks, bug, event, spigot | ||
Environment: |
java version "1.8.0_60" |
Attachments: |
![]() ![]() ![]() |
Description |
When a player is in creative mode and punches a block with the sword in hand, the block does not break. However, the BlockBreakEvent is triggered. The attached files were used to demonstrate the issue. The screenshot is not much help, but I felt I should include what I could. |
Comments |
Comment by md_5 [ 30/Jun/16 ] |
event.isCancelled is true by default in this case. Check cancelled state. |
Comment by jjm_223 [ 25/Sep/15 ] |
That's just it though, if a player hits a block with a sword in creative mode, the block would not break. So the event has no reason to trigger. If a player is in survival and breaks* a block with a sword, of course it should still trigger, as said block would actually be broken. I can't imagine a situation where someone would need to run code on a BlockBreakEvent when no block was actually broken. * EDIT: hits -> breaks |
Comment by Elite [ 25/Sep/15 ] |
I get what you're saying: If it doesn't break it, there's no reason for the event to trigger. However, if someone coding a plugin, wanted to do something special with say a sword and block breaking - They could do so, but if it's removed from the event triggering process, then it would be harder to work around. |
Comment by jjm_223 [ 23/Sep/15 ] |
BlockBreakEvent's described purpose states that it is "called when a block is broken by a player." The way it currently acts goes against its purpose. In the situation I reported the block IS NOT broken, so there is no reason to trigger this event. It could even cause problems with backwards compatibility, too, for plugins made prior to the disabling of swords for block breaking in creative mode. I can't imagine a use for having it the way it is, as a PlayerInteractEvent would be vastly more suitable for any action needed to be performed when a player hits a block with a sword in hand in creative mode. EDIT: EDIT of an edit: I misunderstood what the ignoreCancelled flag does, I apologize. You are correct. I do still feel that it isn't necessary to call the event when a block just isn't broken. |
Comment by nathan818 [ 23/Sep/15 ] |
The server receives a block destruction packet, so it's normal to call BlockBreakEvent i think. And in this case it is canceled so no problem. This behavior is that desired i think, here is the call to BlockBreakEvent by Bukkit in the PlayerInteractManager: ... boolean isSwordNoBreak = (this.gamemode.d()) && (this.player.bA() != null) && ((this.player.bA().getItem() instanceof ItemSword)); if ((this.world.getTileEntity(blockposition) == null) && (!isSwordNoBreak)) { ... } event = new BlockBreakEvent(block, this.player.getBukkitEntity()); event.setCancelled(isSwordNoBreak); ... this.world.getServer().getPluginManager().callEvent(event); |
Comment by jjm_223 [ 23/Sep/15 ] |
My issue is that the event DOES activate when a block is NOT broken, which happens when the player is in creative and punches a block with a sword. When this is done, the client does not attempt to break a block, and it doesn't break on the server. The event is triggered anyway, though. |
Comment by nathan818 [ 23/Sep/15 ] |
It's normal. To ignore it when cancelled juste do: @EventHandler(ignoreCancelled = true) public void onBlockBreak(BlockBreakEvent event) { ... } |