Show custom item aliases in /itemdb (#3907)

Shows items from the custom_items.yml resolver in /itemdb.

Closes #3686.
This commit is contained in:
Josh Roy 2021-02-05 15:27:33 -05:00 committed by GitHub
parent eee1c0628b
commit 1301e8fc99
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 23 additions and 3 deletions

View File

@ -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<String> 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

View File

@ -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<String> getAliasesFor(String item) throws Exception {
final List<String> results = new ArrayList<>();
for (Map.Entry<String, String> 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();