Fixed issue with item damage application

This commit is contained in:
Jules 2023-06-25 22:39:38 +02:00
parent f98d78959f
commit 7767e51534

View File

@ -62,7 +62,6 @@ public class MMOCoreUtils {
}
/**
*
* @param value an integer you want to convert
* @return the string representing the integer but with roman letters
*/
@ -89,6 +88,7 @@ public class MMOCoreUtils {
}
return res;
}
private static String repeat(String s, int n) {
if (s == null) {
return null;
@ -99,6 +99,7 @@ public class MMOCoreUtils {
}
return sb.toString();
}
/**
* Displays an in game indicator using a hologram. This uses
* LumineUtils hologramFactory to summon holograms
@ -260,8 +261,9 @@ public class MMOCoreUtils {
* @param damage Damage that needs to be applied
*/
public static void decreaseDurability(Player player, EquipmentSlot slot, int damage) {
ItemStack item = player.getInventory().getItem(slot);
if (item == null || item.getType().getMaxDurability() == 0 || !item.hasItemMeta() || !(item.getItemMeta() instanceof Damageable) || item.getItemMeta().isUnbreakable())
if (item == null || item.getType().getMaxDurability() == 0 || item.getItemMeta().isUnbreakable())
return;
PlayerItemDamageEvent event = new PlayerItemDamageEvent(player, item, damage);
@ -270,11 +272,12 @@ public class MMOCoreUtils {
return;
ItemMeta meta = item.getItemMeta();
if (event.getDamage() + ((Damageable) meta).getDamage() >= item.getType().getMaxDurability()) {
final int newDamage = event.getDamage() + ((Damageable) meta).getDamage();
if (newDamage >= item.getType().getMaxDurability()) {
player.playSound(player.getLocation(), Sound.ENTITY_ITEM_BREAK, 1F, 1F);
player.getInventory().setItem(slot, null);
} else {
((Damageable) meta).setDamage(((Damageable) meta).getDamage() + event.getDamage());
((Damageable) meta).setDamage(newDamage);
item.setItemMeta(meta);
}
}