From 0a9ead5ffb4a26c9cc0b147fd8da47992ada263d Mon Sep 17 00:00:00 2001 From: Pim van der Loos Date: Thu, 9 Sep 2021 13:44:28 +0200 Subject: [PATCH] Fix lore being ignored - The lore, as specified by the translation file, was not applied on ArmoredElytras. This has now been resolved by retrieving the value when creating new AEs. --- .../armoredElytra/ArmoredElytra.java | 9 +++-- .../armoredElytra/nbtEditor/INBTEditor.java | 33 ++++++++++++++++--- .../armoredElytra/nbtEditor/NBTEditor.java | 8 +++-- 3 files changed, 41 insertions(+), 9 deletions(-) diff --git a/src/main/java/nl/pim16aap2/armoredElytra/ArmoredElytra.java b/src/main/java/nl/pim16aap2/armoredElytra/ArmoredElytra.java index a718dd3..8d3116c 100644 --- a/src/main/java/nl/pim16aap2/armoredElytra/ArmoredElytra.java +++ b/src/main/java/nl/pim16aap2/armoredElytra/ArmoredElytra.java @@ -27,8 +27,11 @@ import org.bukkit.event.Listener; import org.bukkit.inventory.ItemStack; import org.bukkit.plugin.java.JavaPlugin; +import javax.annotation.Nullable; +import java.util.Collections; import java.util.EnumMap; import java.util.HashSet; +import java.util.List; import java.util.Map; import java.util.Set; import java.util.logging.Level; @@ -239,10 +242,10 @@ public class ArmoredElytra extends JavaPlugin implements Listener messagePlayer(player, ChatColor.RED, message); } - public String getElytraLore(ArmorTier armorTier) + public @Nullable List getElytraLore(ArmorTier armorTier) { - final String message = getMessageWithTierNames(Message.MESSAGES_LORE, armorTier); - return message.equals("NONE") ? null : message; + final String message = ChatColor.stripColor(getMessageWithTierNames(Message.MESSAGES_LORE, armorTier)); + return message.equals("NONE") ? null : Collections.singletonList(message); } // Print a string to the log. diff --git a/src/main/java/nl/pim16aap2/armoredElytra/nbtEditor/INBTEditor.java b/src/main/java/nl/pim16aap2/armoredElytra/nbtEditor/INBTEditor.java index c6d3305..2731678 100644 --- a/src/main/java/nl/pim16aap2/armoredElytra/nbtEditor/INBTEditor.java +++ b/src/main/java/nl/pim16aap2/armoredElytra/nbtEditor/INBTEditor.java @@ -5,6 +5,9 @@ import nl.pim16aap2.armoredElytra.util.ArmorTier; import org.bukkit.Color; import org.bukkit.inventory.ItemStack; +import javax.annotation.Nullable; +import java.util.List; + public interface INBTEditor { /** @@ -34,7 +37,7 @@ public interface INBTEditor */ default ItemStack addArmorNBTTags(ItemStack item, ArmorTier armorTier, boolean unbreakable, final String name) { - return addArmorNBTTags(item, armorTier, unbreakable, name, null); + return addArmorNBTTags(item, armorTier, unbreakable, name, null, null); } /** @@ -51,9 +54,30 @@ public interface INBTEditor default ItemStack addArmorNBTTags(ItemStack item, ArmorTier armorTier, boolean unbreakable, final Color color) { return addArmorNBTTags(item, armorTier, unbreakable, - ArmoredElytra.getInstance().getArmoredElytraName(armorTier), color); + ArmoredElytra.getInstance().getArmoredElytraName(armorTier), + ArmoredElytra.getInstance().getElytraLore(armorTier), color); } + /** + * Adds a given {@link ArmorTier} to an item. The item will be cloned. Note that setting the armor tier to {@link + * ArmorTier#NONE} has no effect (besides making a copy of the item). The default name for the given tier is + * applied. See {@link ArmoredElytra#getArmoredElytraName(ArmorTier)}. + * + * @param item The item. + * @param armorTier The {@link ArmorTier} that will be added to it. + * @param unbreakable Whether the resulting item should be unbreakable. + * @param name The name of the item. + * @param color The color of the armor to store. May be null. + * @return The NEW item. + */ + default ItemStack addArmorNBTTags(ItemStack item, ArmorTier armorTier, boolean unbreakable, String name, + Color color) + { + return addArmorNBTTags(item, armorTier, unbreakable, name, + ArmoredElytra.getInstance().getElytraLore(armorTier), color); + } + + /** * Adds a given {@link ArmorTier} to an item. The item will be cloned. Note that setting the armor tier to {@link * ArmorTier#NONE} has no effect (besides making a copy of the item). @@ -61,12 +85,13 @@ public interface INBTEditor * @param item The item. * @param armorTier The {@link ArmorTier} that will be added to it. * @param unbreakable Whether the resulting item should be unbreakable. - * @param name The name fo the item. + * @param name The name of the item. + * @param lore The lore of the item. * @param color The color of the armor to store. May be null. * @return The NEW item. */ ItemStack addArmorNBTTags(ItemStack item, ArmorTier armorTier, boolean unbreakable, final String name, - final Color color); + @Nullable List lore, @Nullable Color color); /** * Checks which {@link ArmorTier} is on an item. diff --git a/src/main/java/nl/pim16aap2/armoredElytra/nbtEditor/NBTEditor.java b/src/main/java/nl/pim16aap2/armoredElytra/nbtEditor/NBTEditor.java index cacd22d..8368a76 100644 --- a/src/main/java/nl/pim16aap2/armoredElytra/nbtEditor/NBTEditor.java +++ b/src/main/java/nl/pim16aap2/armoredElytra/nbtEditor/NBTEditor.java @@ -14,7 +14,9 @@ import org.bukkit.inventory.meta.ItemMeta; import org.bukkit.persistence.PersistentDataContainer; import org.bukkit.persistence.PersistentDataType; +import javax.annotation.Nullable; import java.util.Collection; +import java.util.List; import java.util.UUID; public class NBTEditor implements INBTEditor @@ -25,8 +27,8 @@ public class NBTEditor implements INBTEditor "ARMORED_ELYTRA_COLOR"); @Override - public ItemStack addArmorNBTTags(ItemStack item, ArmorTier armorTier, boolean unbreakable, final String name, - final Color color) + public ItemStack addArmorNBTTags(ItemStack item, ArmorTier armorTier, boolean unbreakable, String name, + @Nullable List lore, @Nullable Color color) { if (armorTier == null || armorTier == ArmorTier.NONE) return new ItemStack(item); @@ -51,6 +53,8 @@ public class NBTEditor implements INBTEditor meta.setUnbreakable(unbreakable); meta.setDisplayName(name); + if (lore != null) + meta.setLore(lore); ret.setItemMeta(meta); return ret;