Package kboyle.oktane.core
Class CommandHandler<CONTEXT extends CommandContext>
java.lang.Object
kboyle.oktane.core.CommandHandler<CONTEXT>
- Type Parameters:
CONTEXT
- The type of context that's used in commands.
The entry point for executing commands.
CommandHandler.<YourContextType>builder()
.withModule(YourCommandModule.class)
.build();
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic class
CommandHandler.Builder<CONTEXT extends CommandContext>
A builder for theCommandHandler
. -
Method Summary
Modifier and TypeMethodDescriptionstatic <CONTEXT extends CommandContext>
CommandHandler.Builder<CONTEXT>builder()
Creates a new builder for theCommandHandler
.commands()
reactor.core.publisher.Mono<Result>
Tries to execute a command for the given input, checking whether or not the input starts with a prefix.reactor.core.publisher.Mono<Result>
Tries to execute a command for the given input at the given index (does not check for prefixes).com.google.common.collect.ImmutableList<CommandModule>
modules()
Gets thePrefixHandler
that thisCommandHandler
is using.
-
Method Details
-
builder
Creates a new builder for theCommandHandler
.- Returns:
- A new
CommandHandler.Builder
.
-
execute
Tries to execute a command for the given input, checking whether or not the input starts with a prefix.- Parameters:
input
- The user input to parse.context
- TheCommandContext
to pass into execution.- Returns:
- The result of execution.
- Throws:
NullPointerException
- wheninput
is null.NullPointerException
- whencontext
is null.
-
execute
Tries to execute a command for the given input at the given index (does not check for prefixes).- Parameters:
input
- The user input to parse.context
- TheCommandContext
to pass into execution.startIndex
- The index to start parsing theinput
from.- Returns:
- The result of execution.
- Throws:
NullPointerException
- wheninput
is null.NullPointerException
- whencontext
is null.IllegalStateException
- whenstartIndex
< 0.IllegalStateException
- whenstartIndex
>input.length()
.
-
modules
- Returns:
- All of the top level
CommandModule
s that belong to theCommandHandler
.
-
flattenModules
- Returns:
- Recursively gets all top level
CommandModule
s and their children that belong to theCommandHandler
.
-
commands
- Returns:
- All of the
Command
s that belong to theCommandHandler
.
-
prefixHandler
Gets thePrefixHandler
that thisCommandHandler
is using.- Returns:
- The
PrefixHandler
.
-