From 1301e8fc99a120d0f326869313bc90100f710688 Mon Sep 17 00:00:00 2001 From: Josh Roy <10731363+JRoy@users.noreply.github.com> Date: Fri, 5 Feb 2021 15:27:33 -0500 Subject: [PATCH] Show custom item aliases in /itemdb (#3907) Shows items from the custom_items.yml resolver in /itemdb. Closes #3686. --- .../earth2me/essentials/commands/Commanditemdb.java | 13 ++++++++++--- .../essentials/items/CustomItemResolver.java | 13 +++++++++++++ 2 files changed, 23 insertions(+), 3 deletions(-) diff --git a/Essentials/src/main/java/com/earth2me/essentials/commands/Commanditemdb.java b/Essentials/src/main/java/com/earth2me/essentials/commands/Commanditemdb.java index 45a2f55bc..7f75b0beb 100644 --- a/Essentials/src/main/java/com/earth2me/essentials/commands/Commanditemdb.java +++ b/Essentials/src/main/java/com/earth2me/essentials/commands/Commanditemdb.java @@ -1,6 +1,7 @@ package com.earth2me.essentials.commands; import com.earth2me.essentials.CommandSource; +import com.earth2me.essentials.utils.StringUtil; import com.earth2me.essentials.utils.VersionUtil; import org.bukkit.Material; import org.bukkit.Server; @@ -52,10 +53,16 @@ public class Commanditemdb extends EssentialsCommand { sender.sendMessage(tl("durability", Integer.toString(durability))); } } - final String itemNameList = ess.getItemDb().names(itemStack); - if (itemNameList != null) { - sender.sendMessage(tl("itemNames", ess.getItemDb().names(itemStack))); + + List nameList = ess.getItemDb().nameList(itemStack); + nameList.addAll(ess.getCustomItemResolver().getAliasesFor(ess.getItemDb().name(itemStack))); + Collections.sort(nameList); + + if (nameList.size() > 15) { + nameList = nameList.subList(0, 14); } + final String itemNameList = StringUtil.joinList(", ", nameList); + sender.sendMessage(tl("itemNames", itemNameList)); } @Override diff --git a/Essentials/src/main/java/com/earth2me/essentials/items/CustomItemResolver.java b/Essentials/src/main/java/com/earth2me/essentials/items/CustomItemResolver.java index b0c043b0a..18fbdfb05 100644 --- a/Essentials/src/main/java/com/earth2me/essentials/items/CustomItemResolver.java +++ b/Essentials/src/main/java/com/earth2me/essentials/items/CustomItemResolver.java @@ -8,8 +8,11 @@ import org.bukkit.configuration.ConfigurationSection; import org.bukkit.inventory.ItemStack; import java.io.File; +import java.util.ArrayList; import java.util.Collection; import java.util.HashMap; +import java.util.List; +import java.util.Map; public class CustomItemResolver implements IItemDb.ItemResolver, IConf { private final EssentialsConf config; @@ -39,6 +42,16 @@ public class CustomItemResolver implements IItemDb.ItemResolver, IConf { return map.keySet(); } + public List getAliasesFor(String item) throws Exception { + final List results = new ArrayList<>(); + for (Map.Entry entry : map.entrySet()) { + if (item.equalsIgnoreCase(ess.getItemDb().name(ess.getItemDb().get(entry.getValue())))) { + results.add(entry.getKey()); + } + } + return results; + } + @Override public void reloadConfig() { map.clear();