mirror of
https://github.com/Auxilor/EcoEnchants.git
synced 2024-11-22 15:05:18 +01:00
Improved /enchantinfo tabcompletion and fixed errors with colorized names, allowing support for case insensitivity
This commit is contained in:
parent
73446cdb54
commit
129b5ce7aa
@ -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);
|
||||
|
@ -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()));
|
||||
}
|
||||
|
||||
/**
|
||||
|
Loading…
Reference in New Issue
Block a user