diff --git a/plugin/src/main/java/me/libraryaddict/disguise/disguisetypes/AnimalColor.java b/plugin/src/main/java/me/libraryaddict/disguise/disguisetypes/AnimalColor.java index 270ab969..67a82bed 100644 --- a/plugin/src/main/java/me/libraryaddict/disguise/disguisetypes/AnimalColor.java +++ b/plugin/src/main/java/me/libraryaddict/disguise/disguisetypes/AnimalColor.java @@ -25,6 +25,10 @@ public enum AnimalColor { WHITE(DyeColor.WHITE, NmsVersion.v1_13.isSupported() ? Material.getMaterial("BONE_MEAL") : null), YELLOW(DyeColor.YELLOW, NmsVersion.v1_14.isSupported() ? Material.getMaterial("YELLOW_DYE") : Material.getMaterial("DANDELION_YELLOW")); + public Material getCarpetMaterial() { + return Material.valueOf(name() + "_CARPET"); + } + public static AnimalColor getColorByWool(int woolId) { for (AnimalColor color : values()) { if (woolId != color.getDyeColor().getWoolData()) { diff --git a/plugin/src/main/java/me/libraryaddict/disguise/disguisetypes/watchers/LlamaWatcher.java b/plugin/src/main/java/me/libraryaddict/disguise/disguisetypes/watchers/LlamaWatcher.java index 836872e9..690abda7 100644 --- a/plugin/src/main/java/me/libraryaddict/disguise/disguisetypes/watchers/LlamaWatcher.java +++ b/plugin/src/main/java/me/libraryaddict/disguise/disguisetypes/watchers/LlamaWatcher.java @@ -4,9 +4,10 @@ import me.libraryaddict.disguise.disguisetypes.AnimalColor; import me.libraryaddict.disguise.disguisetypes.Disguise; import me.libraryaddict.disguise.disguisetypes.MetaIndex; import me.libraryaddict.disguise.utilities.reflection.NmsVersion; -import me.libraryaddict.disguise.utilities.reflection.annotations.NmsRemovedIn; import org.bukkit.DyeColor; import org.bukkit.entity.Llama; +import org.bukkit.inventory.EquipmentSlot; +import org.bukkit.inventory.ItemStack; public class LlamaWatcher extends ChestedHorseWatcher { @@ -23,6 +24,22 @@ public class LlamaWatcher extends ChestedHorseWatcher { } public DyeColor getCarpet() { + if (NmsVersion.v1_20_R4.isSupported()) { + ItemStack item = getEquipment().getItem(EquipmentSlot.BODY); + + if (item == null) { + return null; + } + + AnimalColor color = AnimalColor.getColorByWool(item.getType()); + + if (color == null) { + return null; + } + + return color.getDyeColor(); + } + if (!hasValue(MetaIndex.LLAMA_CARPET) || getData(MetaIndex.LLAMA_CARPET) == -1) { return null; } @@ -30,8 +47,19 @@ public class LlamaWatcher extends ChestedHorseWatcher { return AnimalColor.getColorByWool(getData(MetaIndex.LLAMA_CARPET)).getDyeColor(); } - @NmsRemovedIn(NmsVersion.v1_20_R4) public void setCarpet(DyeColor dyeColor) { + if (NmsVersion.v1_20_R4.isSupported()) { + AnimalColor color = AnimalColor.getColor(dyeColor); + + if (color == null) { + return; + } + + ItemStack item = new ItemStack(color.getCarpetMaterial()); + getEquipment().setItem(EquipmentSlot.BODY, item); + return; + } + sendData(MetaIndex.LLAMA_CARPET, dyeColor == null ? -1 : (int) dyeColor.getWoolData()); }