Fix mending for new durability system

This commit is contained in:
Pim van der Loos 2021-12-23 13:32:15 +01:00
parent ebe8899813
commit afdce9c0e2
No known key found for this signature in database
GPG Key ID: C16F020ADAE6D5A8

View File

@ -20,6 +20,7 @@ import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener;
import org.bukkit.event.entity.EntityDamageEvent;
import org.bukkit.event.entity.EntityDamageEvent.DamageCause;
import org.bukkit.event.player.PlayerItemMendEvent;
import org.bukkit.inventory.ItemStack;
import java.util.ArrayList;
@ -99,6 +100,20 @@ public class EventHandlers implements Listener
Util.moveChestplateToInventory(p);
}
@EventHandler(ignoreCancelled = true, priority = EventPriority.HIGHEST)
public void onMending(PlayerItemMendEvent e)
{
final ArmorTier armorTier = nbtEditor.getArmorTier(e.getItem());
if (armorTier == ArmorTier.NONE)
return;
final int newDurability = durabilityManager.removeDurability(e.getItem(), -e.getRepairAmount(), armorTier);
// Apply it again a tick later, so we can override the durability of the armored elytra without
// interfering with the player XP change event that depends on the success of this one.
Bukkit.getScheduler().scheduleSyncDelayedTask(plugin, () ->
durabilityManager.setDurability(e.getItem(), newDurability, armorTier), 1);
}
@EventHandler
public void onEquip(ArmorEquipEvent e)
{