diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/api/events/ExplosiveToolBreakBlockEvent.java b/src/main/java/io/github/thebusybiscuit/slimefun4/api/events/ExplosiveToolBreakBlockEvent.java index e0fe83b76..aeca781dd 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/api/events/ExplosiveToolBreakBlockEvent.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/api/events/ExplosiveToolBreakBlockEvent.java @@ -11,6 +11,7 @@ import org.bukkit.inventory.ItemStack; import javax.annotation.Nonnull; import javax.annotation.ParametersAreNonnullByDefault; +import java.util.ArrayList; /** * This {@link Event} is called when a {@link Block} is destroyed by an {@link ExplosiveTool}. @@ -23,13 +24,13 @@ public class ExplosiveToolBreakBlockEvent extends PlayerEvent implements Cancell private static final HandlerList handlers = new HandlerList(); private final ItemStack tool; - private final Block block; + private final ArrayList blocks; private boolean cancelled; @ParametersAreNonnullByDefault - public ExplosiveToolBreakBlockEvent(Player player, Block block, ItemStack item) { + public ExplosiveToolBreakBlockEvent(Player player, ArrayList blocks, ItemStack item) { super(player); - this.block = block; + this.blocks = blocks; this.tool = item; } @@ -43,12 +44,12 @@ public class ExplosiveToolBreakBlockEvent extends PlayerEvent implements Cancell } /** - * Gets the {@link Block} destroyed in the event + * Gets the {@link Block} ArrayList of blocks destroyed in the event * */ @Nonnull - public Block getBlock() { - return this.block; + public ArrayList getBlocks() { + return this.blocks; } @Override diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/tools/ExplosiveTool.java b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/tools/ExplosiveTool.java index 9c5df29d6..25709f859 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/tools/ExplosiveTool.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/tools/ExplosiveTool.java @@ -70,6 +70,8 @@ public class ExplosiveTool extends SimpleSlimefunItem implements @ParametersAreNonnullByDefault private void breakBlocks(Player p, ItemStack item, Block b, List blocks, List drops) { + ArrayList blocksToDestroy = new ArrayList<>(); + if (callExplosionEvent.getValue().booleanValue()) { BlockExplodeEvent blockExplodeEvent = new BlockExplodeEvent(b, blocks, 0); Bukkit.getServer().getPluginManager().callEvent(blockExplodeEvent); @@ -77,27 +79,26 @@ public class ExplosiveTool extends SimpleSlimefunItem implements if (!blockExplodeEvent.isCancelled()) { for (Block block : blockExplodeEvent.blockList()) { if (canBreak(p, block)) { - ExplosiveToolBreakBlockEvent event = new ExplosiveToolBreakBlockEvent(p, block, item); - Bukkit.getServer().getPluginManager().callEvent(event); - - if (!event.isCancelled()) { - breakBlock(p, item, block, drops); - } + blocksToDestroy.add(block); } } } } else { for (Block block : blocks) { if (canBreak(p, block)) { - ExplosiveToolBreakBlockEvent event = new ExplosiveToolBreakBlockEvent(p, block, item); - Bukkit.getServer().getPluginManager().callEvent(event); - - if (!event.isCancelled()) { - breakBlock(p, item, block, drops); - } + blocksToDestroy.add(block); } } } + + ExplosiveToolBreakBlockEvent event = new ExplosiveToolBreakBlockEvent(p, blocksToDestroy, item); + Bukkit.getServer().getPluginManager().callEvent(event); + + if (!event.isCancelled()){ + for (Block block : blocksToDestroy) { + breakBlock(p, item, block, drops); + } + } } private List findBlocks(Block b) {