mirror of
https://github.com/TotalFreedomMC/TF-EssentialsX.git
synced 2025-01-03 22:08:28 +00:00
Show custom item aliases in /itemdb (#3907)
Shows items from the custom_items.yml resolver in /itemdb. Closes #3686.
This commit is contained in:
parent
eee1c0628b
commit
1301e8fc99
2 changed files with 23 additions and 3 deletions
|
@ -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
|
||||
|
|
|
@ -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();
|
||||
|
|
Loading…
Reference in a new issue