Skip to content

Commit

Permalink
Revised item info display and added new methods
Browse files Browse the repository at this point in the history
Modified the ItemInfo class to enhance the way items names are displayed, including full name and sign item name. Added a 'getDisplayName' method in the ItemChecker class to increase versatility and support further code development.
  • Loading branch information
Feli499 committed Jan 7, 2024
1 parent 9fd2c5b commit 2dcccc0
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 3 deletions.
16 changes: 13 additions & 3 deletions src/main/java/com/Acrobot/ChestShop/Commands/ItemInfo.java
Expand Up @@ -8,8 +8,8 @@
import com.Acrobot.ChestShop.ChestShop;
import com.Acrobot.ChestShop.Configuration.Messages;
import com.Acrobot.ChestShop.Events.ItemInfoEvent;
import com.Acrobot.ChestShop.Listeners.PreShopCreation.ItemChecker;
import com.Acrobot.ChestShop.Utils.ComponentUtils;
import net.md_5.bungee.api.chat.BaseComponent;
import net.md_5.bungee.api.chat.TextComponent;
import org.bukkit.ChatColor;
import org.bukkit.command.Command;
Expand Down Expand Up @@ -52,9 +52,19 @@ public static void showItemInfo(CommandSender sender, ItemStack item) {
}

TextComponent tc = new TextComponent(" ");
BaseComponent tcName = ComponentUtils.getLocalizedItemName(item);
tc.addExtra(tcName);
tc.setColor(net.md_5.bungee.api.ChatColor.WHITE);
tc.addExtra(ComponentUtils.getLocalizedItemName(item));

String fullName = ChatColor.stripColor(ItemChecker.getDisplayName(item));
String signItemName = ChatColor.stripColor(ItemChecker.getSignItemName(item));
TextComponent signNames = new TextComponent(" ");
signNames.setColor(net.md_5.bungee.api.ChatColor.DARK_GRAY);
signNames.addExtra(fullName);
if (!fullName.equals(signItemName))
signNames.addExtra(" (" + signItemName + ")");

sender.spigot().sendMessage(tc);
sender.spigot().sendMessage(signNames);

ItemInfoEvent event = new ItemInfoEvent(sender, item);
ChestShop.callEvent(event);
Expand Down
Expand Up @@ -38,6 +38,10 @@ public static String getSignItemName(ItemStack itemStack) {
return getDisplayName(itemStack, 15);
}

public static String getDisplayName(ItemStack itemStack) {
return getDisplayName(itemStack, Integer.MAX_VALUE);
}

public static String getDisplayName(ItemStack itemStack, int length) {
if (itemStack == null) {
return null;
Expand Down

0 comments on commit 2dcccc0

Please sign in to comment.