Respect unbreakable tag on items when attempting durability changes

Fixes mcMMO-Dev/mcMMO#3327
Fixes mcMMO-Dev/mcMMO#3391
This commit is contained in:
ezeiger92 2018-02-15 13:38:10 -08:00
parent d4f2f0e11b
commit 40b609ccd8

View File

@ -188,6 +188,10 @@ public class SkillUtils {
* @param maxDamageModifier the amount to adjust the max damage by * @param maxDamageModifier the amount to adjust the max damage by
*/ */
public static void handleDurabilityChange(ItemStack itemStack, int durabilityModifier, double maxDamageModifier) { public static void handleDurabilityChange(ItemStack itemStack, int durabilityModifier, double maxDamageModifier) {
if(itemStack.hasItemMeta() && itemStack.getItemMeta().isUnbreakable()) {
return;
}
Material type = itemStack.getType(); Material type = itemStack.getType();
short maxDurability = mcMMO.getRepairableManager().isRepairable(type) ? mcMMO.getRepairableManager().getRepairable(type).getMaximumDurability() : type.getMaxDurability(); short maxDurability = mcMMO.getRepairableManager().isRepairable(type) ? mcMMO.getRepairableManager().getRepairable(type).getMaximumDurability() : type.getMaxDurability();
durabilityModifier = (int) Math.min(durabilityModifier / (itemStack.getEnchantmentLevel(Enchantment.DURABILITY) + 1), maxDurability * maxDamageModifier); durabilityModifier = (int) Math.min(durabilityModifier / (itemStack.getEnchantmentLevel(Enchantment.DURABILITY) + 1), maxDurability * maxDamageModifier);