Documented AbstractTabCompleter
This commit is contained in:
@@ -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[])}.
|
||||
* <p>
|
||||
* 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<String> onTabComplete(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label, @NotNull String[] args) {
|
||||
if (!command.getName().equalsIgnoreCase(this.command.getName()))
|
||||
public @Nullable List<String> 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<String> onTab(CommandSender sender, List<String> args);
|
||||
/**
|
||||
* The code for the tab-completion of the command (The actual functionality).
|
||||
* <p>
|
||||
*
|
||||
* @param sender The sender of the command.
|
||||
* @param args The arguments of the command.
|
||||
* @return The list of tab-completions.
|
||||
*/
|
||||
public abstract List<String> onTab(@NotNull CommandSender sender,
|
||||
@NotNull List<String> args);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user