Fixed tabcompletion

This commit is contained in:
Auxilor 2022-04-29 17:39:45 +01:00
parent ce1e8a20f9
commit 2a4ff69678

View File

@ -25,12 +25,6 @@ import java.util.Set;
import java.util.stream.Collectors;
public class CommandEnchantinfo extends PluginCommand {
/**
* The cached enchantment names.
*/
private static final List<String> ENCHANT_NAMES = EcoEnchants.values().stream().filter(EcoEnchant::isEnabled)
.map(EcoEnchant::getDisplayName).map(ChatColor::stripColor).collect(Collectors.toList());
/**
* Instantiate a new /enchantinfo command handler.
*
@ -40,15 +34,6 @@ public class CommandEnchantinfo extends PluginCommand {
super(plugin, "enchantinfo", "ecoenchants.command.enchantinfo", false);
}
/**
* Called on reload.
*/
@ConfigUpdater
public static void reload() {
ENCHANT_NAMES.clear();
ENCHANT_NAMES.addAll(EcoEnchants.values().stream().filter(EcoEnchant::isEnabled).map(EcoEnchant::getDisplayName).map(ChatColor::stripColor).toList());
}
@Override
public void onExecute(@NotNull final CommandSender sender,
@NotNull final List<String> args) {
@ -159,12 +144,14 @@ public class CommandEnchantinfo extends PluginCommand {
@NotNull final List<String> args) {
List<String> completions = new ArrayList<>();
List<String> names = EcoEnchants.values().stream().filter(EcoEnchant::isEnabled).map(EcoEnchant::getDisplayName).map(ChatColor::stripColor).toList();
if (args.isEmpty()) {
// Currently, this case is not ever reached
return ENCHANT_NAMES;
return names;
}
StringUtil.copyPartialMatches(String.join(" ", args), ENCHANT_NAMES, completions);
StringUtil.copyPartialMatches(String.join(" ", args), names, completions);
if (args.size() > 1) { // Remove all previous words from the candidate of completions
ArrayList<String> finishedArgs = new ArrayList<>(args);