Module ultimategdbot.api
Class CommandProvider
- java.lang.Object
-
- com.github.alex1304.ultimategdbot.api.command.CommandProvider
-
public final class CommandProvider extends Object
Provides a set of commands. Each command handler provides their own way to handle errors via aCommandErrorHandler.
-
-
Constructor Summary
Constructors Constructor Description CommandProvider(String name)Deprecated.CommandProvider(String name, PermissionChecker permissionChecker)
-
Method Summary
All Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description voidadd(Command command)Adds a command to this provider.reactor.core.publisher.Flux<Object>addAllFromModule(Module module)Scans the module path and adds all commands that are found in the given module.reactor.core.publisher.Flux<Object>addAllFromModule(Module module, Predicate<String> classNameFilter)Scans the module path and adds all commands that are found in the given module.voidaddAnnotated(Object annotated)Adds an annotated object as a command into this provider.voidaddParamConverter(ParamConverter<?> converter)Adds a new param converter to this annotated command provider.<T> reactor.core.publisher.Mono<T>convertParam(Context ctx, String input, Class<T> targetType)Optional<Command>getCommandByAlias(String alias)Gets a command instance corresponding to the given alias.CommandErrorHandlergetErrorHandler()Gets the error handler assigned to this provider.StringgetName()Gets the name of this command provider.PermissionCheckergetPermissionChecker()Deprecated.Set<Command>getProvidedCommands()Gets all provided commands.voidsetErrorHandler(CommandErrorHandler errorHandler)Sets a custom command handler.voidsetPermissionChecker(PermissionChecker permissionChecker)Deprecated.StringtoString()
-
-
-
Constructor Detail
-
CommandProvider
@Deprecated public CommandProvider(String name)
Deprecated.
-
CommandProvider
public CommandProvider(String name, PermissionChecker permissionChecker)
-
-
Method Detail
-
getName
public String getName()
Gets the name of this command provider.- Returns:
- the name of this command provider
-
add
public void add(Command command)
Adds a command to this provider.- Parameters:
command- the command to add
-
addAnnotated
public void addAnnotated(Object annotated)
Adds an annotated object as a command into this provider. This is equivalent to doing:provider.add(AnnotatedCommand.from(object, provider));
- Parameters:
annotated- the annotated object to add
-
addAllFromModule
public reactor.core.publisher.Flux<Object> addAllFromModule(Module module)
Scans the module path and adds all commands that are found in the given module. The command's class needs to be annotated withCommandDescriptorand have a no-arg constructor.Since module path scanning requires I/O operations, this method returns a Flux that subscribes on
Schedulers.boundedElastic().This method is equivalent to
addAllFromModule(module, null)- Parameters:
module- the Java module where to find the commands- Returns:
- a Flux emitting the instances of the annotated command classes, created by the module path scanning process. If an error happened during the scan, the Flux will error.
-
addAllFromModule
public reactor.core.publisher.Flux<Object> addAllFromModule(Module module, @Nullable Predicate<String> classNameFilter)
Scans the module path and adds all commands that are found in the given module. The command's class needs to be annotated withCommandDescriptorand have a no-arg constructor.Since module path scanning requires I/O operations, this method returns a Flux that subscribes on
Schedulers.boundedElastic().- Parameters:
module- the Java module where to find the commandsclassNameFilter- a filter to include only certain classes,nullto accept all classes- Returns:
- a Flux emitting the instances of the annotated command classes, created by the module path scanning process. If an error happened during the scan, the Flux will error.
-
getCommandByAlias
public Optional<Command> getCommandByAlias(String alias)
Gets a command instance corresponding to the given alias.- Parameters:
alias- the alias of the command- Returns:
- the corresponding command instance, if present
-
getErrorHandler
public CommandErrorHandler getErrorHandler()
Gets the error handler assigned to this provider.- Returns:
- the error handler
-
setErrorHandler
public void setErrorHandler(CommandErrorHandler errorHandler)
Sets a custom command handler. If this method is not called, a default handler will be used.- Parameters:
errorHandler- the error handler to set
-
getPermissionChecker
@Deprecated public PermissionChecker getPermissionChecker()
Deprecated.Gets the permission checker assigned to this provider.- Returns:
- the permission checker
-
setPermissionChecker
@Deprecated public void setPermissionChecker(PermissionChecker permissionChecker)
Deprecated.Sets a custom permission checker. If this method is not called, an empty permission checker will be used.- Parameters:
permissionChecker- the permission checker to set
-
getProvidedCommands
public Set<Command> getProvidedCommands()
Gets all provided commands.- Returns:
- an unmodifiable Set containing all commands provided by this provider
-
addParamConverter
public void addParamConverter(ParamConverter<?> converter)
Adds a new param converter to this annotated command provider.- Parameters:
converter- the converter to add
-
convertParam
public <T> reactor.core.publisher.Mono<T> convertParam(Context ctx, String input, Class<T> targetType)
-
-