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

public abstract class CommandNode<T extends CommandNode<T>> extends Object
Base class for command tree nodes.

A command is structured as a tree of nodes, where each node can be:

Example Tree Structure


 gamemode (literal)
 ├── survival (literal) -> executes
 ├── creative (literal) -> executes
 └── <mode> (argument: string)
     └── <player> (argument: player) -> executes
 
  • Field Details

    • name

      protected final String name
      The name of this command node.
    • children

      protected final List<CommandNode<?>> children
      The child nodes of this command node.
    • executor

      protected CommandExecutor executor
      The executor that handles command execution for this node.
    • requirement

      protected Predicate<CommandSender> requirement
      The requirement predicate that must be satisfied for this command to be available.
  • Constructor Details

    • CommandNode

      protected CommandNode(String name)
      Creates a new command node with the given name.
      Parameters:
      name - the name of this command node
  • Method Details

    • getName

      public String getName()
      Returns the name of this node.
      Returns:
      the node name
    • getChildren

      public List<CommandNode<?>> getChildren()
      Returns the child nodes.
      Returns:
      an unmodifiable list of children
    • getExecutor

      public CommandExecutor getExecutor()
      Returns the executor for this node, if any.
      Returns:
      the executor, or null
    • getRequirement

      public Predicate<CommandSender> getRequirement()
      Returns the requirement predicate for this node.
      Returns:
      the requirement
    • canUse

      public boolean canUse(CommandSender sender)
      Checks if the sender can use this node.
      Parameters:
      sender - the command sender
      Returns:
      true if the requirement is met
    • then

      public T then(CommandNode<?> child)
      Adds a child node to this node.
      Parameters:
      child - the child to add
      Returns:
      this node for chaining
    • executes

      public T executes(CommandExecutor executor)
      Sets the executor for this node.
      Parameters:
      executor - the executor
      Returns:
      this node for chaining
    • requires

      public T requires(String permission)
      Sets a requirement for this node based on a permission.
      Parameters:
      permission - the required permission
      Returns:
      this node for chaining
    • requires

      public T requires(Predicate<CommandSender> requirement)
      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:
      true if this node has an executor
    • getUsageText

      public abstract String 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 context
      builder - the suggestions builder
      Returns:
      a future with suggestions
    • literal

      public static CommandNode.LiteralNode literal(String name)
      Creates a literal command node.
      Parameters:
      name - the literal text
      Returns:
      a new literal node
    • argument

      public static <T> CommandNode.ArgumentNode<T> argument(String name, ArgumentType<T> type)
      Creates an argument command node.
      Type Parameters:
      T - the argument's result type
      Parameters:
      name - the argument name
      type - the argument type
      Returns:
      a new argument node