Interface CommandProvider
execute(CommandSource, String).
Commands are registered on a per-class basis therefore every class should only contain one root command. With this one "root command" is meant that all commands in one class must start with a prefix that all have in common. The reason for this is that there is no other way to properly parse and register the commands than this one.
Note: Commands that have a requiredSender in their Command annotation set are
only executable using the console or the api.
- Since:
- 4.0
- See Also:
-
Method Summary
Modifier and TypeMethodDescription@Nullable eu.cloudnetservice.driver.command.CommandInfoLooks for a registered command with the given root name or alias.@UnmodifiableView @NonNull Collection<eu.cloudnetservice.driver.command.CommandInfo> commands()Collects all previously registered commands that are registered in a node and returns them in an unmodifiable collection.execute(@NonNull CommandSource source, @NonNull String input) Executes a command with the given command source and sends all responses to the given source.voidRegisters a command on a per-class basis.voidRegisters a command on a per-class basis.suggest(@NonNull CommandSource source, @NonNull String input) Resolves the next correct command suggestions that would result in a successful command execution, while only suggesting commands that the source is allowed to execute.voidunregister(@NonNull ClassLoader classLoader) Unregisters every command that was registered by the given classloader.voidunregister(@NonNull String name) Unregisters the command with the given name or alias.
-
Method Details
-
suggest
@NonNull @NonNull List<String> suggest(@NonNull @NonNull CommandSource source, @NonNull @NonNull String input) Resolves the next correct command suggestions that would result in a successful command execution, while only suggesting commands that the source is allowed to execute.- Parameters:
source- the commandSource for the suggestions. Mostly for permission checks.input- the command chain that suggestions are needed for.- Returns:
- the suggestions for the current command chain.
- Throws:
NullPointerException- if separator or input is null.
-
execute
@NonNull @NonNull CompletableFuture<?> execute(@NonNull @NonNull CommandSource source, @NonNull @NonNull String input) Executes a command with the given command source and sends all responses to the given source.Note: The command is executed asynchronously in a cached thread pool. If synchronous execution is necessary, then you should consider blocking for the command execution.
- Parameters:
source- the command source that is used to execute the command.input- the commandline that is executed.- Returns:
- a task wrapping the command execution.
- Throws:
NullPointerException- if source or input is null.
-
register
Registers a command on a per-class basis. All methods annotated withCommandare parsed into a command and only one commonCommandInfo.This method takes a class instead of an instance and creates the instance using our dependency injection framework. Make sure that the given class supports the instantiation using dependency injection.
- Parameters:
commandClass- the class to instantiate and register the commands for afterwards.- Throws:
NullPointerException- if object is null.
-
register
Registers a command on a per-class basis. All methods annotated withCommandare parsed into a command and only one commonCommandInfo.- Parameters:
command- the instance of the class to register all commands for.- Throws:
NullPointerException- if object is null.
-
unregister
Unregisters the command with the given name or alias.- Parameters:
name- the name or alias of the command to unregister.- Throws:
NullPointerException- if the given name is null.
-
unregister
Unregisters every command that was registered by the given classloader.- Parameters:
classLoader- the classloader that was used to register the command.- Throws:
NullPointerException- if classLoader is null.
-
command
@Nullable @Nullable eu.cloudnetservice.driver.command.CommandInfo command(@NonNull @NonNull String name) Looks for a registered command with the given root name or alias.- Parameters:
name- the command root name or an alias of the root- Returns:
- the command with the given name - null if no command was found with the given name / alias
- Throws:
NullPointerException- if name is null.
-
commands
@NonNull @UnmodifiableView @NonNull Collection<eu.cloudnetservice.driver.command.CommandInfo> commands()Collects all previously registered commands that are registered in a node and returns them in an unmodifiable collection.- Returns:
- all registered commands.
-