Skip to content

Commit

Permalink
Re-Implemented localized Naming on Items that doesn't have a Name spe…
Browse files Browse the repository at this point in the history
…cified by a plugin (#6)
  • Loading branch information
Feli499 committed Feb 3, 2024
1 parent 205744e commit decd806
Showing 1 changed file with 12 additions and 3 deletions.
15 changes: 12 additions & 3 deletions src/main/java/com/Acrobot/ChestShop/Commands/ItemInfo.java
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit decd806

Please sign in to comment.