From 8d1e427409159c39d4f9a79093de5d333b2666bb Mon Sep 17 00:00:00 2001 From: TheBusyBiscuit Date: Mon, 3 Aug 2020 00:30:58 +0200 Subject: [PATCH] A few more changes --- CHANGELOG.md | 1 + .../items/tools/ExplosiveShovel.java | 14 +-- .../items/tools/ExplosiveTool.java | 89 ++++++++++++------- 3 files changed, 59 insertions(+), 45 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index ead2aed07..fab1264da 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -39,6 +39,7 @@ * Fixed #2147 * Fixed #2179 * Fixed Reinforced Spawners not working sometimes +* Fixed Explosive Pickaxe not handling normal Shulker boxes correctly ## Release Candidate 15 (01 Aug 2020) diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/tools/ExplosiveShovel.java b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/tools/ExplosiveShovel.java index 8b83819a5..c7ee1477f 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/tools/ExplosiveShovel.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/tools/ExplosiveShovel.java @@ -1,8 +1,5 @@ package io.github.thebusybiscuit.slimefun4.implementation.items.tools; -import java.util.List; - -import org.bukkit.Effect; import org.bukkit.block.Block; import org.bukkit.entity.Player; import org.bukkit.inventory.ItemStack; @@ -31,15 +28,8 @@ public class ExplosiveShovel extends ExplosiveTool { } @Override - protected void breakBlock(Player p, ItemStack item, Block b, int fortune, List drops) { - if (MaterialTools.getBreakableByShovel().contains(b.getType()) && SlimefunPlugin.getProtectionManager().hasPermission(p, b.getLocation(), ProtectableAction.BREAK_BLOCK)) { - SlimefunPlugin.getProtectionManager().logAction(p, b, ProtectableAction.BREAK_BLOCK); - - b.getWorld().playEffect(b.getLocation(), Effect.STEP_SOUND, b.getType()); - b.breakNaturally(item); - - damageItem(p, item); - } + protected boolean canBreak(Player p, Block b) { + return MaterialTools.getBreakableByShovel().contains(b.getType()) && SlimefunPlugin.getProtectionManager().hasPermission(p, b.getLocation(), ProtectableAction.BREAK_BLOCK); } } 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 23c78e051..15d6db5b6 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 @@ -29,6 +29,15 @@ import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.UnregisterReason; import me.mrCookieSlime.Slimefun.api.BlockStorage; import me.mrCookieSlime.Slimefun.api.SlimefunItemStack; +/** + * This {@link SlimefunItem} is a super class for items like the {@link ExplosivePickaxe} or {@link ExplosiveShovel}. + * + * @author TheBusyBiscuit + * + * @see ExplosivePickaxe + * @see ExplosiveShovel + * + */ class ExplosiveTool extends SimpleSlimefunItem implements NotPlaceable, DamageableItem { private final ItemSetting damageOnUse = new ItemSetting<>("damage-on-use", true); @@ -61,13 +70,17 @@ class ExplosiveTool extends SimpleSlimefunItem implements NotPla if (!blockExplodeEvent.isCancelled()) { for (Block block : blockExplodeEvent.blockList()) { - breakBlock(p, item, block, fortune, drops); + if (canBreak(p, block)) { + breakBlock(p, item, block, fortune, drops); + } } } } else { for (Block block : blocks) { - breakBlock(p, item, block, fortune, drops); + if (canBreak(p, block)) { + breakBlock(p, item, block, fortune, drops); + } } } } @@ -96,38 +109,48 @@ class ExplosiveTool extends SimpleSlimefunItem implements NotPla return damageOnUse.getValue(); } - protected void breakBlock(Player p, ItemStack item, Block b, int fortune, List drops) { - if (!b.isEmpty() && !b.isLiquid() && !MaterialCollections.getAllUnbreakableBlocks().contains(b.getType()) && SlimefunPlugin.getProtectionManager().hasPermission(p, b.getLocation(), ProtectableAction.BREAK_BLOCK)) { - SlimefunPlugin.getProtectionManager().logAction(p, b, ProtectableAction.BREAK_BLOCK); - - b.getWorld().playEffect(b.getLocation(), Effect.STEP_SOUND, b.getType()); - SlimefunItem sfItem = BlockStorage.check(b); - - if (sfItem != null && !sfItem.useVanillaBlockBreaking()) { - SlimefunBlockHandler handler = SlimefunPlugin.getRegistry().getBlockHandlers().get(sfItem.getID()); - - if (handler != null && !handler.onBreak(p, b, sfItem, UnregisterReason.PLAYER_BREAK)) { - drops.add(BlockStorage.retrieve(b)); - } - } - else if (b.getType() == Material.PLAYER_HEAD || b.getType().name().endsWith("_SHULKER_BOX")) { - b.breakNaturally(); - } - else { - boolean applyFortune = b.getType().name().endsWith("_ORE") && b.getType() != Material.IRON_ORE && b.getType() != Material.GOLD_ORE; - - for (ItemStack drop : b.getDrops(getItem())) { - // For some reason this check is necessary with Paper - if (drop != null && drop.getType() != Material.AIR) { - b.getWorld().dropItemNaturally(b.getLocation(), applyFortune ? new CustomItem(drop, fortune) : drop); - } - } - - b.setType(Material.AIR); - } - - damageItem(p, item); + protected boolean canBreak(Player p, Block b) { + if (b.isEmpty() || b.isLiquid()) { + return false; + } + else if (MaterialCollections.getAllUnbreakableBlocks().contains(b.getType())) { + return false; + } + else { + return SlimefunPlugin.getProtectionManager().hasPermission(p, b.getLocation(), ProtectableAction.BREAK_BLOCK); } } + private void breakBlock(Player p, ItemStack item, Block b, int fortune, List drops) { + SlimefunPlugin.getProtectionManager().logAction(p, b, ProtectableAction.BREAK_BLOCK); + + b.getWorld().playEffect(b.getLocation(), Effect.STEP_SOUND, b.getType()); + SlimefunItem sfItem = BlockStorage.check(b); + + if (sfItem != null && !sfItem.useVanillaBlockBreaking()) { + SlimefunBlockHandler handler = SlimefunPlugin.getRegistry().getBlockHandlers().get(sfItem.getID()); + + if (handler != null && !handler.onBreak(p, b, sfItem, UnregisterReason.PLAYER_BREAK)) { + drops.add(BlockStorage.retrieve(b)); + } + } + else if (b.getType() == Material.PLAYER_HEAD || b.getType() == Material.SHULKER_BOX || b.getType().name().endsWith("_SHULKER_BOX")) { + b.breakNaturally(item); + } + else { + boolean applyFortune = b.getType().name().endsWith("_ORE") && b.getType() != Material.IRON_ORE && b.getType() != Material.GOLD_ORE; + + for (ItemStack drop : b.getDrops(getItem())) { + // For some reason this check is necessary with Paper + if (drop != null && drop.getType() != Material.AIR) { + b.getWorld().dropItemNaturally(b.getLocation(), applyFortune ? new CustomItem(drop, fortune) : drop); + } + } + + b.setType(Material.AIR); + } + + damageItem(p, item); + } + }