Tweak unequipping wolf armor

This commit is contained in:
fullwall 2024-08-12 20:31:57 +08:00
parent f78c87b576
commit f43f919df9

View File

@ -1,5 +1,6 @@
package net.citizensnpcs.editor; package net.citizensnpcs.editor;
import org.bukkit.Material;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.ItemStack;
@ -11,6 +12,12 @@ public class WolfEquipper implements Equipper {
@Override @Override
public void equip(Player equipper, NPC toEquip) { public void equip(Player equipper, NPC toEquip) {
ItemStack hand = equipper.getInventory().getItemInHand(); ItemStack hand = equipper.getInventory().getItemInHand();
ItemStack equipped = toEquip.getOrAddTrait(Equipment.class).get(EquipmentSlot.BODY);
if ((hand == null || hand.getType() == Material.AIR) && equipped != null) {
toEquip.getOrAddTrait(Equipment.class).set(EquipmentSlot.BODY, null);
equipper.getWorld().dropItem(equipper.getLocation(), equipped);
return;
}
if (hand.getType().name().equals("WOLF_ARMOR")) { if (hand.getType().name().equals("WOLF_ARMOR")) {
ItemStack armor = hand.clone(); ItemStack armor = hand.clone();
hand.setAmount(hand.getAmount() - 1); hand.setAmount(hand.getAmount() - 1);