From 23dfa93eced2bb2e22ce1179a8ad1daea5eab9ff Mon Sep 17 00:00:00 2001 From: libraryaddict Date: Sat, 28 Sep 2024 15:20:20 +1200 Subject: [PATCH] Add setWolfArmor and setWolfArmorColor --- .../disguisetypes/watchers/WolfWatcher.java | 46 +++++++++++++++++++ 1 file changed, 46 insertions(+) diff --git a/plugin/src/main/java/me/libraryaddict/disguise/disguisetypes/watchers/WolfWatcher.java b/plugin/src/main/java/me/libraryaddict/disguise/disguisetypes/watchers/WolfWatcher.java index 0c2ab1c7..2a592f0b 100644 --- a/plugin/src/main/java/me/libraryaddict/disguise/disguisetypes/watchers/WolfWatcher.java +++ b/plugin/src/main/java/me/libraryaddict/disguise/disguisetypes/watchers/WolfWatcher.java @@ -8,8 +8,13 @@ import me.libraryaddict.disguise.utilities.reflection.NmsVersion; import me.libraryaddict.disguise.utilities.reflection.ReflectionManager; import me.libraryaddict.disguise.utilities.reflection.annotations.NmsAddedIn; import me.libraryaddict.disguise.utilities.reflection.annotations.NmsRemovedIn; +import org.bukkit.Color; import org.bukkit.DyeColor; +import org.bukkit.Material; import org.bukkit.entity.Wolf; +import org.bukkit.inventory.EquipmentSlot; +import org.bukkit.inventory.ItemStack; +import org.bukkit.inventory.meta.LeatherArmorMeta; public class WolfWatcher extends TameableWatcher { @@ -108,4 +113,45 @@ public class WolfWatcher extends TameableWatcher { public Wolf.Variant getVariant() { return getData(MetaIndex.WOLF_VARIANT); } + + @NmsAddedIn(NmsVersion.v1_20_R4) + public ItemStack getWolfArmor() { + return getEquipment().getItem(EquipmentSlot.BODY); + } + + @NmsAddedIn(NmsVersion.v1_20_R4) + public void setWolfArmor(ItemStack item) { + getEquipment().setItem(EquipmentSlot.BODY, item); + } + + @NmsAddedIn(NmsVersion.v1_20_R4) + public Color getWolfArmorColor() { + ItemStack item = getWolfArmor(); + + if (item == null || item.getType() != Material.WOLF_ARMOR) { + return null; + } + + return ((LeatherArmorMeta) item.getItemMeta()).getColor(); + } + + @NmsAddedIn(NmsVersion.v1_20_R4) + public void setWolfArmorColor(Color color) { + if (color == null) { + setWolfArmor(null); + return; + } + + ItemStack item = getWolfArmor(); + + if (item == null || item.getType() != Material.WOLF_ARMOR) { + item = new ItemStack(Material.WOLF_ARMOR); + } + + LeatherArmorMeta meta = (LeatherArmorMeta) item.getItemMeta(); + meta.setColor(color); + item.setItemMeta(meta); + + setWolfArmor(item); + } }