Improved /enchantinfo tabcompletion and fixed errors with colorized names, allowing support for case insensitivity

This commit is contained in:
Auxilor 2021-01-29 09:43:50 +00:00
parent 73446cdb54
commit 129b5ce7aa
2 changed files with 9 additions and 2 deletions

View File

@ -9,6 +9,7 @@ import com.willfp.ecoenchants.display.EnchantmentCache;
import com.willfp.ecoenchants.enchantments.EcoEnchant;
import com.willfp.ecoenchants.enchantments.EcoEnchants;
import org.apache.commons.lang.WordUtils;
import org.bukkit.ChatColor;
import org.bukkit.Material;
import org.bukkit.command.CommandSender;
import org.bukkit.enchantments.Enchantment;
@ -49,6 +50,11 @@ public class CommandEnchantinfo extends AbstractCommand {
EcoEnchant enchantment = EcoEnchants.getByName(searchName);
if (enchantment == null) {
String finalSearchName = searchName;
enchantment = EcoEnchants.values().stream().filter(ecoEnchant -> ChatColor.stripColor(ecoEnchant.getName()).equalsIgnoreCase(finalSearchName)).findFirst().orElse(null);
}
if (enchantment == null || !enchantment.isEnabled()) {
String message = this.getPlugin().getLangYml().getMessage("not-found").replace("%name%", searchName);
sender.sendMessage(message);

View File

@ -7,6 +7,7 @@ import com.willfp.eco.util.config.updating.annotations.ConfigUpdater;
import com.willfp.ecoenchants.enchantments.EcoEnchant;
import com.willfp.ecoenchants.enchantments.EcoEnchants;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.command.CommandSender;
import org.bukkit.util.StringUtil;
import org.jetbrains.annotations.NotNull;
@ -21,7 +22,7 @@ public class TabCompleterEnchantinfo extends AbstractTabCompleter {
/**
* The cached enchantment names.
*/
private static final List<String> ENCHANT_NAMES = EcoEnchants.values().stream().filter(EcoEnchant::isEnabled).map(EcoEnchant::getName).collect(Collectors.toList());
private static final List<String> ENCHANT_NAMES = EcoEnchants.values().stream().filter(EcoEnchant::isEnabled).map(EcoEnchant::getName).map(ChatColor::stripColor).collect(Collectors.toList());
/**
* Instantiate a new tab-completer for /enchantinfo.
@ -36,7 +37,7 @@ public class TabCompleterEnchantinfo extends AbstractTabCompleter {
@ConfigUpdater
public static void reload() {
ENCHANT_NAMES.clear();
ENCHANT_NAMES.addAll(EcoEnchants.values().stream().filter(EcoEnchant::isEnabled).map(EcoEnchant::getName).collect(Collectors.toList()));
ENCHANT_NAMES.addAll(EcoEnchants.values().stream().filter(EcoEnchant::isEnabled).map(EcoEnchant::getName).map(ChatColor::stripColor).collect(Collectors.toList()));
}
/**