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 6348f3d2..d633d39c 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 @@ -3,23 +3,24 @@ package com.willfp.ecoenchants.command.tabcompleters; import com.willfp.eco.util.StringUtils; import com.willfp.eco.util.command.AbstractCommand; import com.willfp.eco.util.command.AbstractTabCompleter; -import com.willfp.eco.util.plugin.AbstractEcoPlugin; import com.willfp.ecoenchants.enchantments.EcoEnchant; import com.willfp.ecoenchants.enchantments.EcoEnchants; import org.bukkit.Bukkit; import org.bukkit.command.CommandSender; import org.bukkit.util.StringUtil; +import org.jetbrains.annotations.NotNull; import java.util.ArrayList; import java.util.Collections; import java.util.List; +import java.util.Objects; import java.util.stream.Collectors; public class TabCompleterEnchantinfo extends AbstractTabCompleter { private static final List enchantsNames = EcoEnchants.values().stream().filter(EcoEnchant::isEnabled).map(EcoEnchant::getName).collect(Collectors.toList()); - public TabCompleterEnchantinfo(AbstractEcoPlugin plugin) { - super(plugin, (AbstractCommand) Bukkit.getPluginCommand("enchantinfo").getExecutor()); + public TabCompleterEnchantinfo() { + super((AbstractCommand) Objects.requireNonNull(Bukkit.getPluginCommand("enchantinfo")).getExecutor()); } public static void reload() { @@ -28,7 +29,7 @@ public class TabCompleterEnchantinfo extends AbstractTabCompleter { } @Override - public List onTab(CommandSender sender, List args) { + public List onTab(@NotNull CommandSender sender, @NotNull List args) { List completions = new ArrayList<>(); if (args.size() == 0) { diff --git a/eco-util/src/main/java/com/willfp/eco/util/command/AbstractTabCompleter.java b/eco-util/src/main/java/com/willfp/eco/util/command/AbstractTabCompleter.java index afc93ff6..ac14456b 100644 --- a/eco-util/src/main/java/com/willfp/eco/util/command/AbstractTabCompleter.java +++ b/eco-util/src/main/java/com/willfp/eco/util/command/AbstractTabCompleter.java @@ -1,7 +1,5 @@ package com.willfp.eco.util.command; -import com.willfp.eco.util.injection.PluginDependent; -import com.willfp.eco.util.plugin.AbstractEcoPlugin; import org.bukkit.command.Command; import org.bukkit.command.CommandSender; import org.bukkit.command.TabCompleter; @@ -11,24 +9,57 @@ import org.jetbrains.annotations.Nullable; import java.util.Arrays; import java.util.List; -public abstract class AbstractTabCompleter extends PluginDependent implements TabCompleter { +public abstract class AbstractTabCompleter implements TabCompleter { + /** + * The {@link AbstractCommand} that is tab-completed. + */ private final AbstractCommand command; - protected AbstractTabCompleter(AbstractEcoPlugin plugin, AbstractCommand command) { - super(plugin); + /** + * Create a tab-completer for a specified {@link AbstractCommand}. + * + * @param command The command to tab-complete. + */ + protected AbstractTabCompleter(@NotNull final AbstractCommand command) { this.command = command; } + /** + * Internal implementation used to clean up boilerplate. + * Used for parity with {@link TabCompleter#onTabComplete(CommandSender, Command, String, String[])}. + *

+ * Calls {@link this#onTab(CommandSender, List)}. + * + * @param sender The executor of the command. + * @param command The bukkit command. + * @param label The name of the executed command. + * @param args The arguments of the command (anything after the physical command name). + * @return The list of tab-completions. + */ @Override - public @Nullable List onTabComplete(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label, @NotNull String[] args) { - if (!command.getName().equalsIgnoreCase(this.command.getName())) + public @Nullable List onTabComplete(@NotNull final CommandSender sender, + @NotNull final Command command, + @NotNull final String label, + @NotNull final String[] args) { + if (!command.getName().equalsIgnoreCase(this.command.getName())) { return null; + } - if (!sender.hasPermission(this.command.getPermission())) + if (!sender.hasPermission(this.command.getPermission())) { return null; + } return onTab(sender, Arrays.asList(args)); } - public abstract List onTab(CommandSender sender, List args); + /** + * The code for the tab-completion of the command (The actual functionality). + *

+ * + * @param sender The sender of the command. + * @param args The arguments of the command. + * @return The list of tab-completions. + */ + public abstract List onTab(@NotNull CommandSender sender, + @NotNull List args); }