Package dev.polv.taleapi.command
Class CommandNode<T extends CommandNode<T>>
java.lang.Object
dev.polv.taleapi.command.CommandNode<T>
- Type Parameters:
T- the self type for builder chaining
- Direct Known Subclasses:
CommandNode.ArgumentNode,CommandNode.LiteralNode
Base class for command tree nodes.
A command is structured as a tree of nodes, where each node can be:
CommandNode.LiteralNode- A fixed text literal (like "gamemode", "give")CommandNode.ArgumentNode- A typed argument that parses input
Example Tree Structure
gamemode (literal)
├── survival (literal) -> executes
├── creative (literal) -> executes
└── <mode> (argument: string)
└── <player> (argument: player) -> executes
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classAn argument command node that parses typed input.static classA literal command node representing fixed text. -
Field Summary
FieldsModifier and TypeFieldDescriptionprotected final List<CommandNode<?>>The child nodes of this command node.protected CommandExecutorThe executor that handles command execution for this node.protected final StringThe name of this command node.protected Predicate<CommandSender>The requirement predicate that must be satisfied for this command to be available. -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedCommandNode(String name) Creates a new command node with the given name. -
Method Summary
Modifier and TypeMethodDescriptionstatic <T> CommandNode.ArgumentNode<T>argument(String name, ArgumentType<T> type) Creates an argument command node.booleancanUse(CommandSender sender) Checks if the sender can use this node.executes(CommandExecutor executor) Sets the executor for this node.List<CommandNode<?>>Returns the child nodes.Returns the executor for this node, if any.getName()Returns the name of this node.Returns the requirement predicate for this node.abstract StringReturns the usage string for this node.booleanChecks if this node can execute a command (has an executor).abstract CompletableFuture<Suggestions>listSuggestions(CommandContext context, SuggestionsBuilder builder) Provides suggestions for autocompletion.static CommandNode.LiteralNodeCreates a literal command node.Sets a requirement for this node based on a permission.requires(Predicate<CommandSender> requirement) Sets a custom requirement predicate for this node.then(CommandNode<?> child) Adds a child node to this node.
-
Field Details
-
name
The name of this command node. -
children
The child nodes of this command node. -
executor
The executor that handles command execution for this node. -
requirement
The requirement predicate that must be satisfied for this command to be available.
-
-
Constructor Details
-
CommandNode
Creates a new command node with the given name.- Parameters:
name- the name of this command node
-
-
Method Details
-
getName
Returns the name of this node.- Returns:
- the node name
-
getChildren
Returns the child nodes.- Returns:
- an unmodifiable list of children
-
getExecutor
Returns the executor for this node, if any.- Returns:
- the executor, or null
-
getRequirement
Returns the requirement predicate for this node.- Returns:
- the requirement
-
canUse
Checks if the sender can use this node.- Parameters:
sender- the command sender- Returns:
trueif the requirement is met
-
then
Adds a child node to this node.- Parameters:
child- the child to add- Returns:
- this node for chaining
-
executes
Sets the executor for this node.- Parameters:
executor- the executor- Returns:
- this node for chaining
-
requires
Sets a requirement for this node based on a permission.- Parameters:
permission- the required permission- Returns:
- this node for chaining
-
requires
Sets a custom requirement predicate for this node.- Parameters:
requirement- the requirement predicate- Returns:
- this node for chaining
-
isExecutable
public boolean isExecutable()Checks if this node can execute a command (has an executor).- Returns:
trueif this node has an executor
-
getUsageText
Returns the usage string for this node.- Returns:
- the usage representation
-
listSuggestions
public abstract CompletableFuture<Suggestions> listSuggestions(CommandContext context, SuggestionsBuilder builder) Provides suggestions for autocompletion.- Parameters:
context- the command contextbuilder- the suggestions builder- Returns:
- a future with suggestions
-
literal
Creates a literal command node.- Parameters:
name- the literal text- Returns:
- a new literal node
-
argument
Creates an argument command node.- Type Parameters:
T- the argument's result type- Parameters:
name- the argument nametype- the argument type- Returns:
- a new argument node
-