diff --git a/eco-core/core-plugin/src/main/java/com/willfp/ecoarmor/display/ArmorDisplay.java b/eco-core/core-plugin/src/main/java/com/willfp/ecoarmor/display/ArmorDisplay.java index ef2157f..6009912 100644 --- a/eco-core/core-plugin/src/main/java/com/willfp/ecoarmor/display/ArmorDisplay.java +++ b/eco-core/core-plugin/src/main/java/com/willfp/ecoarmor/display/ArmorDisplay.java @@ -35,17 +35,17 @@ public class ArmorDisplay extends DisplayModule { return; } - ArmorSet set = ArmorUtils.getSetOnItem(itemStack); + ArmorSet set = ArmorUtils.getSetOnItem(meta); if (set == null) { - Tier crystalTier = ArmorUtils.getCrystalTier(itemStack); + Tier crystalTier = ArmorUtils.getCrystalTier(meta); if (crystalTier != null) { meta.setLore(crystalTier.getCrystal().getItemMeta().getLore()); itemStack.setItemMeta(meta); } - ArmorSet shardSet = ArmorUtils.getShardSet(itemStack); + ArmorSet shardSet = ArmorUtils.getShardSet(meta); if (shardSet != null) { itemStack.setItemMeta(shardSet.getAdvancementShardItem().getItemMeta()); @@ -61,7 +61,7 @@ public class ArmorDisplay extends DisplayModule { ItemStack slotStack; - if (ArmorUtils.isAdvanced(itemStack)) { + if (ArmorUtils.isAdvanced(meta)) { slotStack = set.getAdvancedItemStack(slot); } else { slotStack = set.getItemStack(slot); @@ -69,7 +69,7 @@ public class ArmorDisplay extends DisplayModule { ItemMeta slotMeta = slotStack.getItemMeta(); assert slotMeta != null; - Tier tier = ArmorUtils.getTier(itemStack); + Tier tier = ArmorUtils.getTier(meta); List lore = new ArrayList<>(); diff --git a/eco-core/core-plugin/src/main/java/com/willfp/ecoarmor/sets/util/ArmorUtils.java b/eco-core/core-plugin/src/main/java/com/willfp/ecoarmor/sets/util/ArmorUtils.java index 06029f2..c5070ae 100644 --- a/eco-core/core-plugin/src/main/java/com/willfp/ecoarmor/sets/util/ArmorUtils.java +++ b/eco-core/core-plugin/src/main/java/com/willfp/ecoarmor/sets/util/ArmorUtils.java @@ -19,6 +19,7 @@ import org.bukkit.persistence.PersistentDataType; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; +import javax.xml.bind.annotation.XmlType; import java.util.ArrayList; import java.util.List; import java.util.Map; @@ -45,6 +46,17 @@ public class ArmorUtils { return null; } + return getSetOnItem(meta); + } + + /** + * Get armor set on an item. + * + * @param meta The itemStack to check. + * @return The set, or null if no set is found. + */ + @Nullable + public ArmorSet getSetOnItem(@NotNull final ItemMeta meta) { PersistentDataContainer container = meta.getPersistentDataContainer(); String setName = container.get(PLUGIN.getNamespacedKeyFactory().create("set"), PersistentDataType.STRING); @@ -133,6 +145,17 @@ public class ArmorUtils { return null; } + return getCrystalTier(meta); + } + + /** + * Get tier on upgrade crystal. + * + * @param meta The item to check. + * @return The found tier, or null. + */ + @Nullable + public static Tier getCrystalTier(@NotNull final ItemMeta meta) { if (meta.getPersistentDataContainer().has(PLUGIN.getNamespacedKeyFactory().create("upgrade_crystal"), PersistentDataType.STRING)) { return Tiers.getByName(meta.getPersistentDataContainer().get(PLUGIN.getNamespacedKeyFactory().create("upgrade_crystal"), PersistentDataType.STRING)); } @@ -154,7 +177,25 @@ public class ArmorUtils { return null; } - if (getSetOnItem(itemStack) == null) { + Tier tier = getTier(meta); + + if (getSetOnItem(meta) != null && tier == null) { + setTier(itemStack, Tiers.DEFAULT); + return Tiers.DEFAULT; + } else { + return tier; + } + } + + /** + * Get tier on item. + * + * @param meta The item to check. + * @return The found tier, or null if not found. + */ + @Nullable + public static Tier getTier(@NotNull final ItemMeta meta) { + if (getSetOnItem(meta) == null) { return null; } @@ -162,8 +203,7 @@ public class ArmorUtils { return Tiers.getByName(meta.getPersistentDataContainer().get(PLUGIN.getNamespacedKeyFactory().create("tier"), PersistentDataType.STRING)); } - setTier(itemStack, Tiers.DEFAULT); - return getTier(itemStack); + return null; } /** @@ -290,6 +330,16 @@ public class ArmorUtils { return false; } + return isAdvanced(meta); + } + + /** + * Get if item is advanced. + * + * @param meta The item to check. + * @return If advanced. + */ + public static boolean isAdvanced(@NotNull final ItemMeta meta) { if (meta.getPersistentDataContainer().has(PLUGIN.getNamespacedKeyFactory().create("advanced"), PersistentDataType.INTEGER)) { return meta.getPersistentDataContainer().get(PLUGIN.getNamespacedKeyFactory().create("advanced"), PersistentDataType.INTEGER) == 1; } @@ -334,6 +384,17 @@ public class ArmorUtils { return null; } + return getShardSet(meta); + } + + /** + * Get the set from a shard. + * + * @param meta The item to check. + * @return The set, or null if not a shard. + */ + @Nullable + public static ArmorSet getShardSet(@NotNull final ItemMeta meta) { String shardSet = meta.getPersistentDataContainer().get(PLUGIN.getNamespacedKeyFactory().create("advancement-shard"), PersistentDataType.STRING); if (shardSet == null) {