Emulate unbreaking properly

This commit is contained in:
NuclearW 2012-05-21 08:31:29 -04:00
parent 93ea558ec3
commit a7f69545f2

View File

@ -1,5 +1,7 @@
package com.gmail.nossr50.util; package com.gmail.nossr50.util;
import java.util.Random;
import org.bukkit.ChatColor; import org.bukkit.ChatColor;
import org.bukkit.block.Block; import org.bukkit.block.Block;
import org.bukkit.enchantments.Enchantment; import org.bukkit.enchantments.Enchantment;
@ -25,6 +27,8 @@ public class Skills {
private final static int TIME_CONVERSION_FACTOR = 1000; private final static int TIME_CONVERSION_FACTOR = 1000;
private final static double MAX_DISTANCE_AWAY = 10.0; private final static double MAX_DISTANCE_AWAY = 10.0;
private final static Random random = new Random();
/** /**
* Checks to see if the cooldown for an item or ability is expired. * Checks to see if the cooldown for an item or ability is expired.
* *
@ -346,9 +350,13 @@ public class Skills {
*/ */
public static void abilityDurabilityLoss(ItemStack inHand, int durabilityLoss) { public static void abilityDurabilityLoss(ItemStack inHand, int durabilityLoss) {
if (Config.getInstance().getAbilitiesDamageTools()) { if (Config.getInstance().getAbilitiesDamageTools()) {
if (!inHand.containsEnchantment(Enchantment.DURABILITY)) { if (inHand.containsEnchantment(Enchantment.DURABILITY)) {
inHand.setDurability((short) (inHand.getDurability() + durabilityLoss)); int level = inHand.getEnchantmentLevel(Enchantment.DURABILITY);
if (random.nextInt(level + 1) > 0) {
return;
}
} }
inHand.setDurability((short) (inHand.getDurability() + durabilityLoss));
} }
} }