From c31ec1ad0593cacd73b3d9dbc05c4d2997c1b624 Mon Sep 17 00:00:00 2001 From: Lightling Date: Fri, 13 Sep 2019 16:17:14 -0400 Subject: [PATCH] fixed issue where all pickaxes and shovels were being considered a hammer/excavator --- .../gibsoniacraft/util/BlockListener.java | 6 ++--- .../gibsoniacraft/util/ToolUtil.java | 24 ++++++++++++++----- 2 files changed, 21 insertions(+), 9 deletions(-) diff --git a/plugin/src/lightling/gibsoniacraft/util/BlockListener.java b/plugin/src/lightling/gibsoniacraft/util/BlockListener.java index a62b77e..15ce2c3 100644 --- a/plugin/src/lightling/gibsoniacraft/util/BlockListener.java +++ b/plugin/src/lightling/gibsoniacraft/util/BlockListener.java @@ -48,7 +48,7 @@ public class BlockListener implements Listener { return; } - if (!ToolUtil.IsExcavator(itemType) && !ToolUtil.IsHammer(itemType)) + if (!ToolUtil.IsExcavator(item) && !ToolUtil.IsHammer(item)) { return; } @@ -77,8 +77,8 @@ public class BlockListener implements Listener Location blockLoc = b.getLocation(); // Determine whether an appropriate tool is being used - boolean isExc = ToolUtil.IsExcavatable(itemType, blockMat); - boolean isHam = ToolUtil.IsHammerable(itemType, blockMat); + boolean isExc = ToolUtil.IsExcavatable(item, blockMat); + boolean isHam = ToolUtil.IsHammerable(item, blockMat); // If using the correct tools, break surrounding blocks if (isExc || isHam) diff --git a/plugin/src/lightling/gibsoniacraft/util/ToolUtil.java b/plugin/src/lightling/gibsoniacraft/util/ToolUtil.java index d8fe4be..332e9a2 100644 --- a/plugin/src/lightling/gibsoniacraft/util/ToolUtil.java +++ b/plugin/src/lightling/gibsoniacraft/util/ToolUtil.java @@ -2,10 +2,12 @@ package lightling.gibsoniacraft.util; import java.util.ArrayList; import java.util.Collections; +import java.util.List; import org.bukkit.Material; import org.bukkit.block.Block; import org.bukkit.block.BlockFace; +import org.bukkit.inventory.ItemStack; import org.bukkit.World; /** @@ -39,9 +41,14 @@ public class ToolUtil * @param mat The material being checked * @return Whether the item is a valid hammer */ - public static boolean IsHammer(Material mat) + public static boolean IsHammer(ItemStack item) { - return BlockRef.ValidHammers.contains(mat); + List lore = item.getLore(); + Material mat = item.getType(); + if (lore != null && mat != null) + return BlockRef.ValidHammers.contains(mat) && lore.contains("Based off of item from PowerMining/Tinkers' Construct"); + else + return false; } /** @@ -49,9 +56,14 @@ public class ToolUtil * @param mat The material being checked * @return Whether the item is a valid excavator */ - public static boolean IsExcavator(Material mat) + public static boolean IsExcavator(ItemStack item) { - return BlockRef.ValidExcavators.contains(mat); + List lore = item.getLore(); + Material mat = item.getType(); + if (lore != null && mat != null) + return BlockRef.ValidExcavators.contains(mat) && lore.contains("Based off of item from PowerMining/Tinkers' Construct"); + else + return false; } /** @@ -60,7 +72,7 @@ public class ToolUtil * @param block The block that should be mineable * @return Valid or invalid action */ - public static boolean IsHammerable(Material ham, Material block) + public static boolean IsHammerable(ItemStack ham, Material block) { return IsMineable(block) && IsHammer(ham); } @@ -71,7 +83,7 @@ public class ToolUtil * @param block The block that should be diggable * @return Valid or invalid action */ - public static boolean IsExcavatable(Material exc, Material block) + public static boolean IsExcavatable(ItemStack exc, Material block) { return IsDiggable(block) && IsExcavator(exc); }