diff --git a/src/main/java/nl/pim16aap2/armoredElytra/handlers/ArmoredElytraHandler.java b/src/main/java/nl/pim16aap2/armoredElytra/handlers/ArmoredElytraHandler.java index 17eef77..2a03db8 100644 --- a/src/main/java/nl/pim16aap2/armoredElytra/handlers/ArmoredElytraHandler.java +++ b/src/main/java/nl/pim16aap2/armoredElytra/handlers/ArmoredElytraHandler.java @@ -76,10 +76,13 @@ abstract class ArmoredElytraHandler private Color getItemColor(final ItemStack itemStack) { - if (itemStack == null || !itemStack.hasItemMeta()) + if (itemStack == null) return null; - if (!(itemStack.getItemMeta() instanceof LeatherArmorMeta)) + if (itemStack.getType() == Material.ELYTRA) + return ArmoredElytra.getInstance().getNbtEditor().getColorOfArmoredElytra(itemStack); + + if (!itemStack.hasItemMeta() || !(itemStack.getItemMeta() instanceof LeatherArmorMeta)) return null; return ((LeatherArmorMeta) itemStack.getItemMeta()).getColor(); diff --git a/src/main/java/nl/pim16aap2/armoredElytra/nbtEditor/INBTEditor.java b/src/main/java/nl/pim16aap2/armoredElytra/nbtEditor/INBTEditor.java index 9bf62b6..c6d3305 100644 --- a/src/main/java/nl/pim16aap2/armoredElytra/nbtEditor/INBTEditor.java +++ b/src/main/java/nl/pim16aap2/armoredElytra/nbtEditor/INBTEditor.java @@ -75,4 +75,14 @@ public interface INBTEditor * @return The {@link ArmorTier} that is on the item. If none is found, {@link ArmorTier#NONE} is returned. */ ArmorTier getArmorTier(ItemStack item); + + /** + * Gets the Color of an armored elytra. + *
+ * If the provided {@link ItemStack} is not an AE, null is returned. + * + * @param item The armored elytra to check. + * @return The color of the armored elytra, if the input is a color armored elytra, otherwise null. + */ + Color getColorOfArmoredElytra(ItemStack item); } diff --git a/src/main/java/nl/pim16aap2/armoredElytra/nbtEditor/NBTEditor.java b/src/main/java/nl/pim16aap2/armoredElytra/nbtEditor/NBTEditor.java index 49fce7f..cacd22d 100644 --- a/src/main/java/nl/pim16aap2/armoredElytra/nbtEditor/NBTEditor.java +++ b/src/main/java/nl/pim16aap2/armoredElytra/nbtEditor/NBTEditor.java @@ -4,12 +4,14 @@ import nl.pim16aap2.armoredElytra.ArmoredElytra; import nl.pim16aap2.armoredElytra.util.ArmorTier; import org.bukkit.Bukkit; import org.bukkit.Color; +import org.bukkit.Material; import org.bukkit.NamespacedKey; import org.bukkit.attribute.Attribute; import org.bukkit.attribute.AttributeModifier; import org.bukkit.inventory.EquipmentSlot; import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.meta.ItemMeta; +import org.bukkit.persistence.PersistentDataContainer; import org.bukkit.persistence.PersistentDataType; import java.util.Collection; @@ -34,7 +36,8 @@ public class NBTEditor implements INBTEditor if (meta == null) throw new IllegalArgumentException("Tried to add armor to invalid item: " + item); meta.getPersistentDataContainer().set(armorTierKey, PersistentDataType.INTEGER, ArmorTier.getTierID(armorTier)); - if (color != null) + + if (color != null && armorTier == ArmorTier.LEATHER) meta.getPersistentDataContainer().set(armorColorKey, PersistentDataType.INTEGER, color.asRGB()); overwriteNBTValue(meta, Attribute.GENERIC_ARMOR, ArmorTier.getArmor(armorTier), "generic.armor"); @@ -91,4 +94,22 @@ public class NBTEditor implements INBTEditor return ArmorTier.NONE; } + + @Override + public Color getColorOfArmoredElytra(final ItemStack item) + { + if (item == null || item.getType() != Material.ELYTRA || !item.hasItemMeta()) + return null; + + final ItemMeta meta = item.getItemMeta(); + if (meta == null) + return null; + + final PersistentDataContainer container = meta.getPersistentDataContainer(); + if (!container.has(armorColorKey, PersistentDataType.INTEGER)) + return null; + + final Integer rgb = container.get(armorColorKey, PersistentDataType.INTEGER); + return rgb == null ? null : Color.fromRGB(rgb); + } }