diff --git a/README.md b/README.md index 74bfb41..3229e9d 100644 --- a/README.md +++ b/README.md @@ -29,6 +29,7 @@ GibsoniaCraft adds new tools to the server. Excavator/Hammer based off of BradzC - Does not account for enchantments - Hammer/Excavator fails at x=-1 (and likely z=-1) +- Due to the current check for hammer/excavator block adding (originally based off of PowerTool's method), durablity on hammers/excavators will always have extra durability reduction even if only one block was added (will eventually change to only add blocks to list if they are the right type, like with lumber-axe) ## License [MIT](LICENSE) diff --git a/plugin/plugin.yml b/plugin/plugin.yml index 3f8d99e..0eabc32 100644 --- a/plugin/plugin.yml +++ b/plugin/plugin.yml @@ -1,6 +1,6 @@ main: lightling.gibsoniacraft.GibsoniaCraft name: GibsoniaCraft -version: 1.1.0 +version: 1.1.1 author: Lightling description: Adds some small additions/changes to a PaperMC server api-version: 1.14 \ No newline at end of file diff --git a/plugin/src/lightling/gibsoniacraft/util/BlockListener.java b/plugin/src/lightling/gibsoniacraft/util/BlockListener.java index 6a5414b..6026329 100644 --- a/plugin/src/lightling/gibsoniacraft/util/BlockListener.java +++ b/plugin/src/lightling/gibsoniacraft/util/BlockListener.java @@ -5,6 +5,9 @@ import org.bukkit.Material; import org.bukkit.block.Block; import org.bukkit.block.BlockFace; import org.bukkit.entity.Player; + +import java.util.ArrayList; + import org.bukkit.Location; // Needed for handling events @@ -63,6 +66,7 @@ public class BlockListener implements Listener String pName = player.getName(); PlayerInteractListener pListener = gcPlugin.GetPlayerInteractListener(); BlockFace blockFace = pListener.GetFaceByName(pName); + ArrayList blocks = ToolUtil.GetSurroundingBlocks(blockFace, block); // Grab durability information ItemMeta meta = item.getItemMeta(); @@ -72,9 +76,13 @@ public class BlockListener implements Listener // Used in determining if an extra block was broken (for durability) boolean success = false; + if (blocks.size() > 1) + { + success = true; + } // Iterates through to break surrounding blocks - for (Block b : ToolUtil.GetSurroundingBlocks(blockFace, block)) + for (Block b : blocks) { // Determine the block type and position Material blockMat = b.getType(); @@ -94,23 +102,30 @@ public class BlockListener implements Listener final ItemStack snow = new ItemStack(Material.SNOWBALL, 1 + b.getData()); b.getWorld().dropItemNaturally(blockLoc, snow); } - success = true; b.breakNaturally(); } } + + // Used for determining durability loss + int addToDamage = 0; + // Do extra damage to durability if extra blocks were broken if (success && !item.getEnchantments().containsKey(Enchantment.DURABILITY)) { - int addToDamage = 2; - if (itemType == Material.DIAMOND_PICKAXE && itemType == Material.DIAMOND_SHOVEL) + addToDamage = 2; + + // Diamond tools take less damage + if (itemType == Material.DIAMOND_PICKAXE || itemType == Material.DIAMOND_SHOVEL) { addToDamage = 1; } - dMeta.setDamage(currDur + addToDamage); - item.setItemMeta(meta); } + + // Update durability + dMeta.setDamage(currDur + addToDamage); + item.setItemMeta(meta); } /** @@ -140,6 +155,7 @@ public class BlockListener implements Listener // Get block information via the player listener Block block = bbEvent.getBlock(); + ArrayList blocks = ToolUtil.GetUpwardLogs(block); // Grab durability information ItemMeta meta = item.getItemMeta(); @@ -149,6 +165,10 @@ public class BlockListener implements Listener // Used in determining if an extra block was broken (for durability) boolean success = false; + if (blocks.size() > 1) + { + success = true; + } for (Block b : ToolUtil.GetUpwardLogs(block)) { @@ -161,21 +181,27 @@ public class BlockListener implements Listener if (isAxe) { - success = true; b.breakNaturally(); } } + // Used for determining durability loss + int addToDamage = 0; + // Do extra damage to durability if extra blocks were broken if (success && !item.getEnchantments().containsKey(Enchantment.DURABILITY)) { - int addToDamage = 2; - if (itemType == Material.DIAMOND_PICKAXE && itemType == Material.DIAMOND_SHOVEL) + addToDamage = 2; + + // Diamond tools take less damage + if (itemType == Material.DIAMOND_PICKAXE || itemType == Material.DIAMOND_SHOVEL) { addToDamage = 1; } - dMeta.setDamage(currDur + addToDamage); - item.setItemMeta(meta); } + + // Update durability + dMeta.setDamage(currDur + addToDamage); + item.setItemMeta(meta); } }