Fixed enchantments being ignored + removed uneccesary code

Fixed Unbreaking enchantments being ignored when using Treefelling and
when hit by Armor Impact
This commit is contained in:
TfT_02 2012-12-29 22:38:57 +01:00
parent 0a028afe7f
commit 43de871392
4 changed files with 19 additions and 43 deletions

View File

@ -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

View File

@ -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
}

View File

@ -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,10 +501,11 @@ 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))) {
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();
}

View File

@ -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;
}
}