Skip to content

Commit

Permalink
improve localized item name in iteminfo command
Browse files Browse the repository at this point in the history
  • Loading branch information
Brokkonaut committed Mar 27, 2023
1 parent cfa415c commit 581df4c
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 5 deletions.
2 changes: 1 addition & 1 deletion src/main/java/com/Acrobot/ChestShop/Commands/ItemInfo.java
Expand Up @@ -55,7 +55,7 @@ public static void showItemInfo(CommandSender sender, ItemStack item) {
String signName = MaterialUtil.getSignName(item);
TextComponent tc = new TextComponent(" ");
tc.setColor(net.md_5.bungee.api.ChatColor.DARK_GRAY);
BaseComponent tcName = ComponentUtils.getLocalizedItemName(item.getType());
BaseComponent tcName = ComponentUtils.getLocalizedItemName(item);
tcName.setColor(net.md_5.bungee.api.ChatColor.WHITE);
tc.addExtra(tcName);
tc.addExtra(" " + signName);
Expand Down
Expand Up @@ -90,7 +90,7 @@ private static BaseComponent[] parseItemInformation(ItemStack item) {
// Joiner joiner = Joiner.on(' ');

message.add(new TextComponent(item.getAmount() + " "));
message.add(ComponentUtils.getLocalizedItemName(item.getType()));
message.add(ComponentUtils.getLocalizedItemName(item));

return message.toArray(new BaseComponent[message.size()]);
}
Expand Down
23 changes: 20 additions & 3 deletions src/main/java/com/Acrobot/ChestShop/Utils/ComponentUtils.java
Expand Up @@ -6,17 +6,34 @@
import net.md_5.bungee.api.chat.TextComponent;
import net.md_5.bungee.api.chat.TranslatableComponent;
import org.bukkit.Material;
import org.bukkit.inventory.ItemStack;

public class ComponentUtils {
private ComponentUtils() {
// prevent instances
}

public static BaseComponent getLocalizedItemName(Material m) {
public static BaseComponent getLocalizedItemName(ItemStack stack) {
if (stack == null) {
stack = new ItemStack(Material.AIR);
}
if (Properties.SHOW_TRANSLATED_ITEM_NAMES) {
return new TranslatableComponent((m.isBlock() ? "block.minecraft." : "item.minecraft.") + m.getKey().getKey());
TranslatableComponent suffix = null;
String materialName = stack.getType().name();
if (stack.getType() == Material.NETHERITE_UPGRADE_SMITHING_TEMPLATE) {
suffix = new TranslatableComponent("upgrade.minecraft.netherite_upgrade");
} else if (materialName.endsWith("_SMITHING_TEMPLATE")) {
suffix = new TranslatableComponent("trim_pattern.minecraft." + materialName.replace("_ARMOR_TRIM_SMITHING_TEMPLATE", "").toLowerCase());
} else if (materialName.startsWith("MUSIC_DISC_")) {
suffix = new TranslatableComponent("item.minecraft." + materialName.toLowerCase() + ".desc");
}
TranslatableComponent main = new TranslatableComponent(stack.getTranslationKey());
if (suffix == null) {
return main;
}
return new TextComponent(main, new TextComponent(" "), suffix);
} else {
return new TextComponent(StringUtil.capitalizeFirstLetter(m.name(), '_'));
return new TextComponent(StringUtil.capitalizeFirstLetter(stack.getType().name(), '_'));
}
}
}

0 comments on commit 581df4c

Please sign in to comment.