Skip to content

Class CommandDispatcher

Namespace: Void.Minecraft.Commands.Brigadier
Assembly: Void.Minecraft.dll

Owns a Brigadier command tree and provides registration, parsing, execution, usage, and completion operations.

public record CommandDispatcher : ICommandDispatcher, IEquatable<CommandDispatcher>

Inheritance

objectCommandDispatcher

Implements

ICommandDispatcher, IEquatable<CommandDispatcher>

Inherited Members

object.Equals(object?), object.Equals(object?, object?), object.GetHashCode(), object.GetType(), object.MemberwiseClone(), object.ReferenceEquals(object?, object?), object.ToString()

Constructors

CommandDispatcher(RootCommandNode)

Owns a Brigadier command tree and provides registration, parsing, execution, usage, and completion operations.

public CommandDispatcher(RootCommandNode Root)

Parameters

Root RootCommandNode

The root command node.

CommandDispatcher()

Creates a dispatcher with a new empty root.

public CommandDispatcher()

Fields

ArgumentSeparator

Specifies the single space used to separate command arguments.

public const char ArgumentSeparator = ' '

Field Value

char

Properties

Consumer

Gets or sets the callback notified after execution attempts.

public ResultConsumer Consumer { get; set; }

Property Value

ResultConsumer

Root

The root command node.

public RootCommandNode Root { get; init; }

Property Value

RootCommandNode

Methods

Add(ICommandNode)

Adds a proxy API command node to the root.

public void Add(ICommandNode node)

Parameters

node ICommandNode

The node to add.

Exceptions

ArgumentException

node is not this Brigadier implementation’s .

All(CommandNode?)

Enumerates descendants depth-first, excluding the supplied root itself.

public IEnumerable<CommandNode> All(CommandNode? root = null)

Parameters

root CommandNode?

The traversal root, or null for .

Returns

IEnumerable<CommandNode>

The lazy descendant sequence.

ExecuteAsync(string, ICommandSource, CancellationToken)

Parses and executes command text.

public ValueTask<int> ExecuteAsync(string input, ICommandSource source, CancellationToken cancellationToken)

Parameters

input string

The command input.

source ICommandSource

The command source.

cancellationToken CancellationToken

A cancellation token.

Returns

ValueTask<int>

The command result or accumulated fork result.

ExecuteAsync(StringReader, ICommandSource, CancellationToken)

Parses and executes input from a reader.

public ValueTask<int> ExecuteAsync(StringReader input, ICommandSource source, CancellationToken cancellationToken)

Parameters

input StringReader

The command reader.

source ICommandSource

The command source.

cancellationToken CancellationToken

A cancellation token.

Returns

ValueTask<int>

The command result or accumulated fork result.

ExecuteAsync(ParseResults, CancellationToken)

Validates and executes precomputed parse results.

public ValueTask<int> ExecuteAsync(ParseResults parse, CancellationToken cancellationToken)

Parameters

parse ParseResults

The parse result.

cancellationToken CancellationToken

A cancellation token passed to execution.

Returns

ValueTask<int>

The command result or accumulated fork result.

Exceptions

CommandSyntaxException

Input remains unparsed, no executable context exists, or execution reports a syntax failure.

FindNode(List<string>)

Traverses exact child names from the root.

public CommandNode? FindNode(List<string> path)

Parameters

path List<string>

The root-relative name path.

Returns

CommandNode?

The reached node; an empty path returns .

Exceptions

KeyNotFoundException

A path segment is not a child of the current node.

GetAllUsageAsync(CommandNode, ICommandSource, bool, CancellationToken)

Enumerates every executable and redirect usage below a node.

public ValueTask<string[]> GetAllUsageAsync(CommandNode node, ICommandSource source, bool restricted, CancellationToken cancellationToken)

Parameters

node CommandNode

The traversal root.

source ICommandSource

The source used for access checks.

restricted bool

Whether to omit inaccessible branches.

cancellationToken CancellationToken

A cancellation token.

Returns

ValueTask<string[]>

The usage strings.

GetCompletionSuggestions(ParseResults, CancellationToken)

Computes completions at the end of parsed input.

public static ValueTask<Suggestions> GetCompletionSuggestions(ParseResults parse, CancellationToken cancellationToken)

Parameters

parse ParseResults

The parse result.

cancellationToken CancellationToken

A cancellation token.

Returns

ValueTask<Suggestions>

Merged suggestions from relevant child nodes.

GetCompletionSuggestions(ParseResults, int, CancellationToken)

Computes completions at an explicit cursor.

public static ValueTask<Suggestions> GetCompletionSuggestions(ParseResults parse, int cursor, CancellationToken cancellationToken)

Parameters

parse ParseResults

The parse result.

cursor int

The completion cursor.

cancellationToken CancellationToken

A cancellation token.

Returns

ValueTask<Suggestions>

Merged suggestions from relevant child nodes.

GetPath(CommandNode)

Finds the first root-relative name path to a node by reference identity.

public List<string> GetPath(CommandNode target)

Parameters

target CommandNode

The target node.

Returns

List<string>

The name path, or an empty list when absent or when targeting the root.

GetSmartUsageAsync(CommandNode, ICommandSource, CancellationToken)

Builds compact usage strings for each accessible direct child.

public ValueTask<Dictionary<CommandNode, string>> GetSmartUsageAsync(CommandNode node, ICommandSource source, CancellationToken cancellationToken)

Parameters

node CommandNode

The parent node.

source ICommandSource

The source used for access checks.

cancellationToken CancellationToken

A cancellation token.

Returns

ValueTask<Dictionary<CommandNode, string>>

A map of child nodes to usage strings.

Parse(string, ICommandSource, CancellationToken)

Parses command text into the best matching command-tree path.

public ValueTask<ParseResults> Parse(string command, ICommandSource source, CancellationToken cancellationToken)

Parameters

command string

The command input.

source ICommandSource

The command source used for access checks.

cancellationToken CancellationToken

A cancellation token.

Returns

ValueTask<ParseResults>

The best parse result, including recoverable branch exceptions.

ParseAsync(StringReader, ICommandSource, CancellationToken)

Parses a command reader into the best matching command-tree path.

public ValueTask<ParseResults> ParseAsync(StringReader command, ICommandSource source, CancellationToken cancellationToken)

Parameters

command StringReader

The command reader.

source ICommandSource

The command source used for access checks.

cancellationToken CancellationToken

A cancellation token.

Returns

ValueTask<ParseResults>

The best parse result.

Register(LiteralArgumentBuilder)

Builds and registers a literal command at the root.

public LiteralCommandNode Register(LiteralArgumentBuilder command)

Parameters

command LiteralArgumentBuilder

The command builder.

Returns

LiteralCommandNode

The built node.

Register(Func<IArgumentContext, LiteralArgumentBuilder>)

Invokes a command-builder factory with the default argument context and registers its result.

public LiteralCommandNode Register(Func<IArgumentContext, LiteralArgumentBuilder> command)

Parameters

command Func<IArgumentContext, LiteralArgumentBuilder>

The builder factory.

Returns

LiteralCommandNode

The built node.

SuggestAsync(string, ICommandSource, CancellationToken)

Parses a string and computes completions at its end.

public ValueTask<Suggestions> SuggestAsync(string input, ICommandSource source, CancellationToken cancellationToken)

Parameters

input string

The command input.

source ICommandSource

The command source.

cancellationToken CancellationToken

A cancellation token.

Returns

ValueTask<Suggestions>

The completions.

SuggestAsync(StringReader, ICommandSource, CancellationToken)

Parses a reader and computes completions at the end of its source.

public ValueTask<Suggestions> SuggestAsync(StringReader input, ICommandSource source, CancellationToken cancellationToken)

Parameters

input StringReader

The command reader.

source ICommandSource

The command source.

cancellationToken CancellationToken

A cancellation token.

Returns

ValueTask<Suggestions>

The completions.