Browse Source

Fixed enchantments being ignored + removed uneccesary code

Fixed Unbreaking enchantments being ignored when using Treefelling and
when hit by Armor Impact
TfT_02 12 years ago
parent
commit
43de871392

+ 1 - 0
Changelog.txt

@@ -17,6 +17,7 @@ Version 1.3.13-dev
  = Fixed Async deprecation issues
  = Fixed some issues with mySQL databases (non-alphanumeric characters preventing MySQL)
  = Fixed skill commands displaying .x% instead of 0.x%
+ = Fixed Unbreaking enchantments being ignored when using Treefelling and when hit by Armor Impact
  ! GJ stopped being a lazy slacker and got stuff done
  - Removed dead code relating to null profiles
  - Removed unused imports

+ 8 - 2
src/main/java/com/gmail/nossr50/skills/combat/Axes.java

@@ -2,6 +2,7 @@ package com.gmail.nossr50.skills.combat;
 
 import java.util.Random;
 
+import org.bukkit.enchantments.Enchantment;
 import org.bukkit.entity.AnimalTamer;
 import org.bukkit.entity.Entity;
 import org.bukkit.entity.LivingEntity;
@@ -16,7 +17,6 @@ import com.gmail.nossr50.datatypes.PlayerProfile;
 import com.gmail.nossr50.datatypes.SkillType;
 import com.gmail.nossr50.locale.LocaleLoader;
 import com.gmail.nossr50.party.PartyManager;
-import com.gmail.nossr50.util.ItemChecks;
 import com.gmail.nossr50.util.Misc;
 import com.gmail.nossr50.util.Permissions;
 import com.gmail.nossr50.util.Users;
@@ -141,7 +141,13 @@ public class Axes {
             else {
                 for (ItemStack armor : targetPlayer.getInventory().getArmorContents()) {
                     if(Math.random() * 100 > 75) {
-                        maxDurability = (short) (ItemChecks.getMaxDurabilityArmor(armor) * impactMaxDamage);
+                    	if (armor.containsEnchantment(Enchantment.DURABILITY)) {
+                    		int level = armor.getEnchantmentLevel(Enchantment.DURABILITY);
+                    		if (random.nextInt(level + 1) > 0) {
+                    			return;
+                    		}
+                    	}
+                        maxDurability = (short) (armor.getType().getMaxDurability() * impactMaxDamage);
                     	if (durabilityDamage > maxDurability) durabilityDamage = (short) maxDurability;
                         armor.setDurability((short) (armor.getDurability() + durabilityDamage)); //Damage armor piece
                     }

+ 10 - 6
src/main/java/com/gmail/nossr50/skills/gathering/WoodCutting.java

@@ -7,6 +7,7 @@ import org.bukkit.Location;
 import org.bukkit.Material;
 import org.bukkit.TreeSpecies;
 import org.bukkit.block.Block;
+import org.bukkit.enchantments.Enchantment;
 import org.bukkit.entity.Player;
 import org.bukkit.event.block.BlockBreakEvent;
 import org.bukkit.inventory.ItemStack;
@@ -65,9 +66,13 @@ public class WoodCutting {
             return;
         }
 
-        int durabilityLoss = durabilityLossCalulate(toBeFelled);
         int xp = 0;
         ItemStack inHand = player.getItemInHand();
+        int level = 0;
+        if (inHand.containsEnchantment(Enchantment.DURABILITY)) {
+            level = inHand.getEnchantmentLevel(Enchantment.DURABILITY);
+        }
+        int durabilityLoss = durabilityLossCalulate(toBeFelled, level);
 
         /* This is to prevent using wood axes everytime you tree fell */
         if (ModChecks.isCustomTool(inHand)) {
@@ -79,7 +84,6 @@ public class WoodCutting {
                 if (health >= 2) {
                     Combat.dealDamage(player, random.nextInt(health - 1));
                 }
-                return;
             }
         }
         else if ((inHand.getDurability() + durabilityLoss >= inHand.getType().getMaxDurability()) || inHand.getType().equals(Material.AIR)) {
@@ -90,7 +94,6 @@ public class WoodCutting {
             if (health >= 2) {
                 Combat.dealDamage(player, random.nextInt(health - 1));
             }
-            return;
         }
 
         /* Damage the tool */
@@ -498,11 +501,12 @@ public class WoodCutting {
         }
     }
 
-    private static int durabilityLossCalulate(ArrayList<Block> toBeFelled) {
+    private static int durabilityLossCalulate(ArrayList<Block> toBeFelled, int level) {
         int durabilityLoss = 0;
         for (Block x : toBeFelled) {
-            if (x.getType().equals(Material.LOG) || (Config.getInstance().getBlockModsEnabled() && ModChecks.isCustomLogBlock(x))) {
-                durabilityLoss++;
+        	if (random.nextInt(level + 1) > 0) {}//Don't add durabilityLoss, because Unbreaking enchantment does it work.
+        	else if (x.getType().equals(Material.LOG) || (Config.getInstance().getBlockModsEnabled() && ModChecks.isCustomLogBlock(x))) {
+        		durabilityLoss++;
                 durabilityLoss = durabilityLoss + Config.getInstance().getAbilityToolDamage();
             }
         }

+ 0 - 35
src/main/java/com/gmail/nossr50/util/ItemChecks.java

@@ -474,39 +474,4 @@ public class ItemChecks {
     public static boolean isEnchantable(ItemStack is) {
         return isArmor(is) || isSword(is) || isAxe(is) || isShovel(is) || isPickaxe(is) || (is.getType() == Material.BOW);
     }
-
-    /**
-     * Get the maximum durability of an armor type.
-     *
-     * @param is Item to check
-     * @return maximum durability value.
-     */
-    public static int getMaxDurabilityArmor(ItemStack is) {
-    	int durability = 0;
-    	if (isDiamondArmor(is)) {
-    		if (isHelmet(is)) durability = 364;
-    		else if (isChestplate(is)) durability = 529;
-    		else if (isPants(is)) durability = 496;
-    		else if (isBoots(is)) durability = 430;
-    	}
-    	else if (isIronArmor(is)) {
-    		if (isHelmet(is)) durability = 166;
-    		else if (isChestplate(is)) durability = 242;
-    		else if (isPants(is)) durability = 226;
-    		else if (isBoots(is)) durability = 196;
-    	}
-    	else if (isGoldArmor(is)) {
-    		if (isHelmet(is)) durability = 78;
-    		else if (isChestplate(is)) durability = 114;
-    		else if (isPants(is)) durability = 106;
-    		else if (isBoots(is)) durability = 92;
-    	}
-    	else if (isLeatherArmor(is)) {
-    		if (isHelmet(is)) durability = 56;
-    		else if (isChestplate(is)) durability = 82;
-    		else if (isPants(is)) durability = 76;
-    		else if (isBoots(is)) durability = 66;
-    	}
-    	return durability;
-    }
 }