From decd8062acdcadadd9ef97aac4f8927877ded022 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Feli=E2=84=A2=EF=B8=8F?= <67964269+Feli499@users.noreply.github.com> Date: Sat, 3 Feb 2024 06:35:58 +0100 Subject: [PATCH] Re-Implemented localized Naming on Items that doesn't have a Name specified by a plugin (#6) --- .../com/Acrobot/ChestShop/Commands/ItemInfo.java | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/src/main/java/com/Acrobot/ChestShop/Commands/ItemInfo.java b/src/main/java/com/Acrobot/ChestShop/Commands/ItemInfo.java index 9b0e82440..3f6fbdd74 100644 --- a/src/main/java/com/Acrobot/ChestShop/Commands/ItemInfo.java +++ b/src/main/java/com/Acrobot/ChestShop/Commands/ItemInfo.java @@ -9,7 +9,9 @@ import com.Acrobot.ChestShop.Configuration.Messages; import com.Acrobot.ChestShop.Events.ItemInfoEvent; import com.Acrobot.ChestShop.Utils.ItemNamingUtils; +import net.md_5.bungee.api.chat.BaseComponent; import net.md_5.bungee.api.chat.TextComponent; +import net.md_5.bungee.api.chat.TranslatableComponent; import org.bukkit.ChatColor; import org.bukkit.command.Command; import org.bukkit.command.CommandExecutor; @@ -50,11 +52,18 @@ public static void showItemInfo(CommandSender sender, ItemStack item) { return; } - String fullName = ChatColor.stripColor(ItemNamingUtils.getDisplayName(item)); + String displayName = ItemNamingUtils.getDisplayName(item); + String fullName = ChatColor.stripColor(displayName); - TextComponent tc = new TextComponent(" "); + BaseComponent tc; + if (StringUtil.capitalizeFirstLetter(item.getType().name(), '_').equals(fullName)) { + // If Itemname is identical to Material name, no plugin "claimed" that item and changed the name + // so we can do the player a favor and translate the item name to their Language. + tc = new TranslatableComponent(item.getTranslationKey()); + } else { + tc = new TextComponent(fullName); + } tc.setColor(net.md_5.bungee.api.ChatColor.WHITE); - tc.addExtra(fullName); sender.spigot().sendMessage(tc); ItemInfoEvent event = new ItemInfoEvent(sender, item);