From 6f9fc26ab5e36a2a10787cd40b706d6c303cd50d Mon Sep 17 00:00:00 2001 From: GJ Date: Thu, 23 Feb 2012 02:12:24 -0500 Subject: [PATCH] Changed tool ability damage to use built in Bukkit methods. --- src/main/java/com/gmail/nossr50/m.java | 40 ------------------- .../com/gmail/nossr50/skills/Excavation.java | 6 ++- .../java/com/gmail/nossr50/skills/Mining.java | 6 ++- .../com/gmail/nossr50/skills/WoodCutting.java | 11 ++++- 4 files changed, 20 insertions(+), 43 deletions(-) diff --git a/src/main/java/com/gmail/nossr50/m.java b/src/main/java/com/gmail/nossr50/m.java index 133672f48..266f58f80 100644 --- a/src/main/java/com/gmail/nossr50/m.java +++ b/src/main/java/com/gmail/nossr50/m.java @@ -144,26 +144,6 @@ public class m return false; //Return false if something went wrong } } - - public static void damageTool(Player player, short damage) - { - if(player.getItemInHand().getTypeId() == 0) - return; - player.getItemInHand().setDurability((short) (player.getItemInHand().getDurability() + damage)); - if(player.getItemInHand().getDurability() >= getMaxDurability(getTier(player), player.getItemInHand())) - { - ItemStack[] inventory = player.getInventory().getContents(); - for(ItemStack x : inventory) - { - if(x != null && x.getTypeId() == player.getItemInHand().getTypeId() && x.getDurability() == player.getItemInHand().getDurability()){ - x.setTypeId(0); - x.setAmount(0); - player.getInventory().setContents(inventory); - return; - } - } - } - } public static Integer getTier(Player player) { @@ -182,26 +162,6 @@ public class m return 1; //UNRECOGNIZED } } - - public static Integer getMaxDurability(Integer tier, ItemStack item) - { - int id = item.getTypeId(); - if(tier == 1){ - if((id == 283 || id == 284 || id == 285 || id == 286 || id == 294)){ - return 33; //GOLD - } else { - return 60; //WOOD - } - } else if (tier == 2){ - return 132; - } else if (tier == 3){ - return 251; - } else if (tier == 4){ - return 1562; - } else { - return 0; - } - } public static double getDistance(Location loca, Location locb) { diff --git a/src/main/java/com/gmail/nossr50/skills/Excavation.java b/src/main/java/com/gmail/nossr50/skills/Excavation.java index 1987d3399..7606e9b6e 100644 --- a/src/main/java/com/gmail/nossr50/skills/Excavation.java +++ b/src/main/java/com/gmail/nossr50/skills/Excavation.java @@ -204,7 +204,11 @@ public class Excavation if(LoadProperties.toolsLoseDurabilityFromAbilities) { if(!player.getItemInHand().containsEnchantment(Enchantment.DURABILITY)) - m.damageTool(player, (short) LoadProperties.abilityDurabilityLoss); + { + short durability = player.getItemInHand().getDurability(); + durability -= LoadProperties.abilityDurabilityLoss; + player.getItemInHand().setDurability(durability); + } } if(block.getData() != (byte)5) diff --git a/src/main/java/com/gmail/nossr50/skills/Mining.java b/src/main/java/com/gmail/nossr50/skills/Mining.java index 81bf5af46..5a9a3b151 100644 --- a/src/main/java/com/gmail/nossr50/skills/Mining.java +++ b/src/main/java/com/gmail/nossr50/skills/Mining.java @@ -264,7 +264,11 @@ public class Mining if(LoadProperties.toolsLoseDurabilityFromAbilities) { if(!player.getItemInHand().containsEnchantment(Enchantment.DURABILITY)) - m.damageTool(player, (short) LoadProperties.abilityDurabilityLoss); + { + short durability = player.getItemInHand().getDurability(); + durability -= LoadProperties.abilityDurabilityLoss; + player.getItemInHand().setDurability(durability); + } } //Pre-processing diff --git a/src/main/java/com/gmail/nossr50/skills/WoodCutting.java b/src/main/java/com/gmail/nossr50/skills/WoodCutting.java index ccf2051b6..c480b04be 100644 --- a/src/main/java/com/gmail/nossr50/skills/WoodCutting.java +++ b/src/main/java/com/gmail/nossr50/skills/WoodCutting.java @@ -36,6 +36,7 @@ import com.gmail.nossr50.datatypes.SkillType; import com.gmail.nossr50.locale.mcLocale; import com.gmail.nossr50.spout.SpoutStuff; import com.gmail.nossr50.config.*; + import org.getspout.spoutapi.sound.SoundEffect; @@ -261,7 +262,15 @@ public class WoodCutting if(LoadProperties.toolsLoseDurabilityFromAbilities) { if(!player.getItemInHand().containsEnchantment(Enchantment.DURABILITY)) - m.damageTool(player, (short) LoadProperties.abilityDurabilityLoss); + { + System.out.println("BEFORE"); + System.out.println(player.getItemInHand().getDurability()); + short durability = player.getItemInHand().getDurability(); + durability -= LoadProperties.abilityDurabilityLoss; + player.getItemInHand().setDurability(durability); + System.out.println("AFTER"); + System.out.println(player.getItemInHand().getDurability()); + } } if(LoadProperties.spoutEnabled)