From 349026329c0f2bbb7ea3749da15c0516b78194d3 Mon Sep 17 00:00:00 2001 From: Auxilor Date: Sun, 27 Dec 2020 18:15:42 +0000 Subject: [PATCH] Misc changes --- .../TabCompleterEnchantinfo.java | 29 +++++++++++++++---- .../config/EnchantmentYamlConfig.java | 4 --- 2 files changed, 23 insertions(+), 10 deletions(-) diff --git a/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/command/tabcompleters/TabCompleterEnchantinfo.java b/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/command/tabcompleters/TabCompleterEnchantinfo.java index 5d8301da..08d4b8f0 100644 --- a/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/command/tabcompleters/TabCompleterEnchantinfo.java +++ b/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/command/tabcompleters/TabCompleterEnchantinfo.java @@ -19,28 +19,45 @@ import java.util.Objects; import java.util.stream.Collectors; public class TabCompleterEnchantinfo extends AbstractTabCompleter implements Updatable { - private static final List enchantsNames = EcoEnchants.values().stream().filter(EcoEnchant::isEnabled).map(EcoEnchant::getName).collect(Collectors.toList()); + /** + * The cached enchantment names. + */ + private static final List ENCHANT_NAMES = EcoEnchants.values().stream().filter(EcoEnchant::isEnabled).map(EcoEnchant::getName).collect(Collectors.toList()); + /** + * Instantiate a new tab-completer for /enchantinfo. + */ public TabCompleterEnchantinfo() { super((AbstractCommand) Objects.requireNonNull(Bukkit.getPluginCommand("enchantinfo")).getExecutor()); } + /** + * Called on /ecoreload. + */ @ConfigUpdater public static void reload() { - enchantsNames.clear(); - enchantsNames.addAll(EcoEnchants.values().stream().filter(EcoEnchant::isEnabled).map(EcoEnchant::getName).collect(Collectors.toList())); + ENCHANT_NAMES.clear(); + ENCHANT_NAMES.addAll(EcoEnchants.values().stream().filter(EcoEnchant::isEnabled).map(EcoEnchant::getName).collect(Collectors.toList())); } + /** + * The execution of the tabcompleter. + * + * @param sender The sender of the command. + * @param args The arguments of the command. + * @return A list of tab-completions. + */ @Override - public List onTab(@NotNull CommandSender sender, @NotNull List args) { + public List onTab(@NotNull final CommandSender sender, + @NotNull final List args) { List completions = new ArrayList<>(); if (args.isEmpty()) { // Currently, this case is not ever reached - return enchantsNames; + return ENCHANT_NAMES; } - StringUtil.copyPartialMatches(String.join(" ", args), enchantsNames, completions); + StringUtil.copyPartialMatches(String.join(" ", args), ENCHANT_NAMES, completions); if (args.size() > 1) { // Remove all previous words from the candidate of completions ArrayList finishedArgs = new ArrayList<>(args); diff --git a/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/config/EnchantmentYamlConfig.java b/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/config/EnchantmentYamlConfig.java index d2cc74a1..68645b45 100644 --- a/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/config/EnchantmentYamlConfig.java +++ b/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/config/EnchantmentYamlConfig.java @@ -59,10 +59,6 @@ public abstract class EnchantmentYamlConfig extends PluginDependent { } this.directory = dir; - init(); - } - - private void init() { if (!new File(directory, name + ".yml").exists()) { createFile(); }