Added TabCompleter to base ApplianceCommand

This commit is contained in:
Elias Müller 2023-10-25 00:55:51 +02:00
parent 160a17ea62
commit 463874a024
2 changed files with 9 additions and 1 deletions

View File

@ -75,6 +75,7 @@ public abstract class Appliance {
PluginCommand command = plugin.getCommand(name);
if(command != null) {
command.setExecutor(executor);
command.setTabCompleter(executor);
} else {
Bukkit.getLogger().warning("Command " + name + " is not specified in plugin.yml!");
}

View File

@ -7,16 +7,18 @@ import org.bukkit.Bukkit;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
import org.bukkit.command.TabCompleter;
import org.bukkit.entity.Player;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import java.util.List;
import java.util.Optional;
/**
* Utility class which enables command name definition over a constructor.
*/
public abstract class ApplianceCommand<T extends Appliance> implements ApplianceSupplier<T>, CommandExecutor {
public abstract class ApplianceCommand<T extends Appliance> implements ApplianceSupplier<T>, TabCompleter, CommandExecutor {
public String commandName;
private final T appliance;
protected Component errorMessage = Component.text("Error whilst executing command").color(NamedTextColor.RED);
@ -43,6 +45,11 @@ public abstract class ApplianceCommand<T extends Appliance> implements Appliance
return true;
}
@Override
public @Nullable List<String> onTabComplete(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label, @NotNull String[] args) {
return null;
}
protected abstract void execute(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label, @NotNull String[] args);
@Override