Class CommandTree<C>
- java.lang.Object
-
- cloud.commandframework.CommandTree<C>
-
- Type Parameters:
C- Command sender type
public final class CommandTree<C> extends java.lang.ObjectTree containing all commands and command paths.All
commandsconsists of unique paths made out ofarguments. These arguments may beliteralsor variables. Command may either be required or optional, with the requirement that no optional argument precedes a required argument.The
commandsare stored in this tree and the nodes of tree consists of the commandarguments. Each leaf node of the tree should containing a fully parsedCommand. It is thus possible to walk the tree and determine whether or not 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
InvalidSyntaxExceptionbeing thrown, whereas scenario three would result in aNoSuchCommandExceptionif occurring at the root node or aInvalidSyntaxExceptionotherwise. Only the fourth scenario would result in a complete command being parsed.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classCommandTree.Node<T>Very simple tree structure
-
Method Summary
Modifier and Type Method Description @NonNull CommandManager<C>getCommandManager()Get the command manager@Nullable CommandTree.Node<@Nullable CommandArgument<C,?>>getNamedNode(@Nullable java.lang.String name)Get a named root node, if it exists@NonNull java.util.Collection<@NonNull CommandTree.Node<@Nullable CommandArgument<C,?>>>getRootNodes()Get an immutable collection containing all of the root nodes in the tree@NonNull java.util.List<@NonNull java.lang.String>getSuggestions(@NonNull CommandContext<C> context, @NonNull java.util.Queue<@NonNull java.lang.String> commandQueue)Get suggestions from the input queuevoidinsertCommand(@NonNull Command<C> command)Insert a new command into the command treestatic <C> @NonNull CommandTree<C>newTree(@NonNull CommandManager<C> commandManager)Create a new command tree instance@NonNull Pair<@Nullable Command<C>,@Nullable java.lang.Exception>parse(@NonNull CommandContext<C> commandContext, @NonNull java.util.Queue<@NonNull java.lang.String> args)Attempt to parse string input into a commandvoidverifyAndRegister()Go through all commands and register them, and verify the command tree contracts
-
-
-
Method Detail
-
newTree
public static <C> @NonNull CommandTree<C> newTree(@NonNull CommandManager<C> commandManager)
Create a new command tree instance- Type Parameters:
C- Command sender type- Parameters:
commandManager- Command manager- Returns:
- New command tree
-
parse
public @NonNull Pair<@Nullable Command<C>,@Nullable java.lang.Exception> parse(@NonNull CommandContext<C> commandContext, @NonNull java.util.Queue<@NonNull java.lang.String> args)
Attempt to parse string input into a command- Parameters:
commandContext- Command context instanceargs- Input- Returns:
- Parsed command, if one could be found
-
getSuggestions
public @NonNull java.util.List<@NonNull java.lang.String> getSuggestions(@NonNull CommandContext<C> context, @NonNull java.util.Queue<@NonNull java.lang.String> commandQueue)
Get suggestions from the input queue- Parameters:
context- Context instancecommandQueue- Input queue- Returns:
- String suggestions. These should be filtered based on
String.startsWith(String)
-
insertCommand
public void insertCommand(@NonNull Command<C> command)
Insert a new command into the command tree- Parameters:
command- Command to insert
-
verifyAndRegister
public void verifyAndRegister()
Go through all commands and register them, and verify the command tree contracts
-
getRootNodes
public @NonNull java.util.Collection<@NonNull CommandTree.Node<@Nullable CommandArgument<C,?>>> getRootNodes()
Get an immutable collection containing all of the root nodes in the tree- Returns:
- Root nodes
-
getNamedNode
public @Nullable CommandTree.Node<@Nullable CommandArgument<C,?>> getNamedNode(@Nullable java.lang.String name)
Get a named root node, if it exists- Parameters:
name- Root node name- Returns:
- Root node, or
null
-
getCommandManager
public @NonNull CommandManager<C> getCommandManager()
Get the command manager- Returns:
- Command manager
-
-