Class CommandTree<C>
- Type Parameters:
C- command sender type
All commands consists of unique paths made out of components.
These arguments may be literals or variables. Command may either be required
or optional, with the requirement that no optional argument precedes a required argument.
The commands are stored in this tree and the nodes of tree consists of the command
components. Each leaf node of the tree should contain a fully parsed
Command. It is thus possible to walk the tree and determine whether the supplied
input from a command sender constitutes a proper command.
When parsing input, the tree will be walked until one of four scenarios occur:
- The input queue is empty at a non-leaf node
- The input queue is not empty following a leaf node
- No child node is able to accept the input
- The input queue is empty following a leaf node
Scenarios one and two would result in a InvalidSyntaxException being thrown, whereas
scenario three would result in a NoSuchCommandException if occurring at the root node
or a InvalidSyntaxException otherwise. Only the fourth scenario would result in a complete
command being parsed.
-
Method Summary
Modifier and TypeMethodDescriptionReturns the command manager that was used to create this command treegetLeaves(@NonNull CommandNode<C> node) Returns all leaf nodes attached to the givennodeor its children.getLeavesRaw(@NonNull CommandNode<C> node) Returns all leaf nodes attached to the givennodeor its children.getNamedNode(@Nullable String name) Returns a named root node, if it exists<S extends Suggestion>
@NonNull CompletableFuture<@NonNull Suggestions<C, S>> getSuggestions(@NonNull CommandContext<C> context, @NonNull CommandInput commandInput, @NonNull SuggestionMapper<S> mapper, @NonNull Executor executor) Returns suggestions from the input queuevoidinsertCommand(@NonNull Command<C> command) Inserts a new command into the command tree and then verifies the integrity of the treestatic <C> @NonNull CommandTree<C> newTree(@NonNull CommandManager<C> commandManager) Creates a new command tree instanceparse(@NonNull CommandContext<C> commandContext, @NonNull CommandInput commandInput, @NonNull Executor parsingExecutor) Attempts to parse a command from the provided input.rootNode()Returns the node that allrootNodes()share as a parent.Returns an immutable view containing of the root nodes of the command tree
-
Method Details
-
newTree
Creates a new command tree instance- Type Parameters:
C- Command sender type- Parameters:
commandManager- Command manager- Returns:
- the created command tree
-
commandManager
Returns the command manager that was used to create this command tree- Returns:
- Command manager
-
rootNodes
Returns an immutable view containing of the root nodes of the command tree- Returns:
- immutable view of the root nodes
-
getNamedNode
Returns a named root node, if it exists- Parameters:
name- root node name- Returns:
- the found root node, or
null
-
parse
@API(status=STABLE) public @NonNull CompletableFuture<@Nullable Command<C>> parse(@NonNull CommandContext<C> commandContext, @NonNull CommandInput commandInput, @NonNull Executor parsingExecutor) Attempts to parse a command from the provided input.- Parameters:
commandContext- command context instancecommandInput- command inputparsingExecutor- executor to schedule parsing logic on- Returns:
- parsed command, if one could be found
-
getSuggestions
@API(status=STABLE) public <S extends Suggestion> @NonNull CompletableFuture<@NonNull Suggestions<C,S>> getSuggestions(@NonNull CommandContext<C> context, @NonNull CommandInput commandInput, @NonNull SuggestionMapper<S> mapper, @NonNull Executor executor) Returns suggestions from the input queue- Type Parameters:
S- suggestion type- Parameters:
context- Context instancecommandInput- Inputmapper- suggestion mapperexecutor- executor to schedule suggestion logic on- Returns:
- String suggestions. These should be filtered based on
String.startsWith(String)
-
insertCommand
Inserts a new command into the command tree and then verifies the integrity of the tree- Parameters:
command- the command to insert
-
rootNode
Returns the node that allrootNodes()share as a parent.- Returns:
- the root node
-
getLeavesRaw
@API(status=INTERNAL) public @NonNull List<@NonNull CommandNode<C>> getLeavesRaw(@NonNull CommandNode<C> node) Returns all leaf nodes attached to the givennodeor its children.- Parameters:
node- the node- Returns:
- the leaf nodes attached to the node
-
getLeaves
@API(status=INTERNAL) public @NonNull List<@NonNull CommandNode<C>> getLeaves(@NonNull CommandNode<C> node) Returns all leaf nodes attached to the givennodeor its children.- Parameters:
node- the node- Returns:
- the leaf nodes attached to the node
-