diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/listeners/BlockListener.java b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/listeners/BlockListener.java index 205f307d5..30593427e 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/listeners/BlockListener.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/listeners/BlockListener.java @@ -25,6 +25,7 @@ import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.meta.ItemMeta; import io.github.bakedlibs.dough.protection.Interaction; +import io.github.thebusybiscuit.slimefun4.api.events.ExplosiveToolBreakBlocksEvent; import io.github.thebusybiscuit.slimefun4.api.events.SlimefunBlockBreakEvent; import io.github.thebusybiscuit.slimefun4.api.events.SlimefunBlockPlaceEvent; import io.github.thebusybiscuit.slimefun4.api.items.SlimefunItem; @@ -83,7 +84,7 @@ public class BlockListener implements Listener { public void onBlockPlace(BlockPlaceEvent e) { ItemStack item = e.getItemInHand(); SlimefunItem sfItem = SlimefunItem.getByItem(item); - + // TODO: Protection manager is null in testing environment. if (!Slimefun.instance().isUnitTest()) { Slimefun.getProtectionManager().logAction(e.getPlayer(), e.getBlock(), Interaction.PLACE_BLOCK); @@ -141,7 +142,7 @@ public class BlockListener implements Listener { } if (!e.isCancelled()) { - checkForSensitiveBlockAbove(e, item); + checkForSensitiveBlockAbove(e.getPlayer(), e.getBlock(), item); int fortune = getBonusDropsWithFortune(item, e.getBlock()); List drops = new ArrayList<>(); @@ -155,6 +156,13 @@ public class BlockListener implements Listener { } } + @EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true) + public void onExplosiveToolBlockBreak(ExplosiveToolBreakBlocksEvent e) { + for (Block block : e.getAdditionalBlocks()) { + checkForSensitiveBlockAbove(e.getPlayer(), block, e.getItemInHand()); + } + } + @ParametersAreNonnullByDefault private void callToolHandler(BlockBreakEvent e, ItemStack item, int fortune, List drops) { SlimefunItem tool = SlimefunItem.getByItem(item); @@ -219,14 +227,16 @@ public class BlockListener implements Listener { * Sensitive {@link Block Blocks} are pressure plates or saplings, which should be broken * when the block beneath is broken as well. * - * @param p + * @param player * The {@link Player} who broke this {@link Block} - * @param b + * @param block * The {@link Block} that was broken + * @param item + * The {@link ItemStack} that was used to break the {@link Block} */ @ParametersAreNonnullByDefault - private void checkForSensitiveBlockAbove(BlockBreakEvent e, ItemStack item) { - Block blockAbove = e.getBlock().getRelative(BlockFace.UP); + private void checkForSensitiveBlockAbove(Player player, Block block, ItemStack item) { + Block blockAbove = block.getRelative(BlockFace.UP); if (SlimefunTag.SENSITIVE_MATERIALS.isTagged(blockAbove.getType())) { SlimefunItem sfItem = BlockStorage.check(blockAbove); @@ -236,9 +246,8 @@ public class BlockListener implements Listener { * We create a dummy here to pass onto the BlockBreakHandler. * This will set the correct block context. */ - BlockBreakEvent dummyEvent = new BlockBreakEvent(blockAbove, e.getPlayer()); - List drops = new ArrayList<>(); - drops.addAll(sfItem.getDrops(e.getPlayer())); + BlockBreakEvent dummyEvent = new BlockBreakEvent(blockAbove, player); + List drops = new ArrayList<>(sfItem.getDrops(player)); sfItem.callItemHandler(BlockBreakHandler.class, handler -> handler.onPlayerBreak(dummyEvent, item, drops)); blockAbove.setType(Material.AIR);