mirror of
https://github.com/Auxilor/EcoEnchants.git
synced 2024-11-22 15:05:18 +01:00
Documented AbstractTabCompleter
This commit is contained in:
parent
eb032f2483
commit
1fb3d56ebf
@ -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<String> 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<String> onTab(CommandSender sender, List<String> args) {
|
||||
public List<String> onTab(@NotNull CommandSender sender, @NotNull List<String> args) {
|
||||
List<String> completions = new ArrayList<>();
|
||||
|
||||
if (args.size() == 0) {
|
||||
|
@ -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);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user