Skip to content

Class CommandContextBuilder

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

Accumulates parse results for one stage of a potentially redirected command.

public class CommandContextBuilder

Inheritance

objectCommandContextBuilder

Inherited Members

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

Constructors

CommandContextBuilder(CommandDispatcher, ICommandSource, CommandNode, int)

Creates an empty context builder at a parse position.

public CommandContextBuilder(CommandDispatcher dispatcher, ICommandSource source, CommandNode rootNode, int start)

Parameters

dispatcher CommandDispatcher

The dispatcher owning the tree.

source ICommandSource

The command source.

rootNode CommandNode

The parsing root.

start int

The initial cursor.

Properties

Arguments

Gets the mutable parsed-argument map.

public Dictionary<string, IParsedArgument> Arguments { get; }

Property Value

Dictionary<string, IParsedArgument>

Child

Gets or sets the redirected child context builder.

public CommandContextBuilder? Child { get; set; }

Property Value

CommandContextBuilder?

Command

Gets or sets the executor selected by parsing.

public CommandExecutor? Command { get; set; }

Property Value

CommandExecutor?

Dispatcher

Gets or sets the dispatcher that owns the parsed tree.

public CommandDispatcher Dispatcher { get; set; }

Property Value

CommandDispatcher

IsFork

Gets or sets whether the redirect forks across sources.

public bool IsFork { get; set; }

Property Value

bool

Nodes

Gets the mutable parsed-node sequence.

public List<ParsedCommandNode> Nodes { get; }

Property Value

List<ParsedCommandNode>

Range

Gets or sets the aggregate input range covered by parsed nodes.

public StringRange Range { get; set; }

Property Value

StringRange

RedirectModifier

Gets or sets the redirect source modifier.

public RedirectModifier? RedirectModifier { get; set; }

Property Value

RedirectModifier?

RootNode

Gets or sets the parsing root node.

public CommandNode RootNode { get; set; }

Property Value

CommandNode

Source

Gets or sets the command source.

public ICommandSource Source { get; set; }

Property Value

ICommandSource

Start

Gets or sets the initial parse cursor.

public int Start { get; set; }

Property Value

int

Methods

Build(string)

Creates an immutable command context and recursively builds its child.

public CommandContext Build(string input)

Parameters

input string

The complete command input.

Returns

CommandContext

The built context.

Exceptions

InvalidOperationException

is null.

BuildSuggestions(int)

Locates the command-tree position at which suggestions should be requested.

public SuggestionContext BuildSuggestions(int cursor)

Parameters

cursor int

The completion cursor.

Returns

SuggestionContext

The parent node and token start.

Exceptions

InvalidOperationException

No node precedes the cursor within this context or its children.

Copy()

Creates a shallow copy with new node and argument collections.

public CommandContextBuilder Copy()

Returns

CommandContextBuilder

The copied builder. Its child, source, nodes, and argument values remain shared objects.

GetLastChild()

Traverses redirected children to the final builder.

public CommandContextBuilder GetLastChild()

Returns

CommandContextBuilder

The last builder in the child chain.

WithArgument(string, ParsedArgument)

Records a parsed argument by name for the command context being built.

public CommandContextBuilder WithArgument(string name, ParsedArgument argument)

Parameters

name string

The argument name from the command tree.

argument ParsedArgument

The parsed argument range and value to associate with name.

Returns

CommandContextBuilder

The current instance.

Remarks

If an argument with the same name was already recorded, it is replaced.

Exceptions

ArgumentNullException

name is null.

WithChild(CommandContextBuilder)

Sets the redirected child stage.

public CommandContextBuilder WithChild(CommandContextBuilder child)

Parameters

child CommandContextBuilder

The child builder.

Returns

CommandContextBuilder

This builder.

WithExecutor(CommandExecutor?)

Associates an executor with this stage.

public CommandContextBuilder WithExecutor(CommandExecutor? command)

Parameters

command CommandExecutor?

The executor, or null to clear it.

Returns

CommandContextBuilder

This builder.

WithNode(CommandNode, StringRange)

Appends a parsed node and adopts its redirect metadata.

public CommandContextBuilder WithNode(CommandNode node, StringRange range)

Parameters

node CommandNode

The parsed node.

range StringRange

The consumed range.

Returns

CommandContextBuilder

This builder.

WithSource(ICommandSource)

Replaces the command source.

public CommandContextBuilder WithSource(ICommandSource source)

Parameters

source ICommandSource

The new source.

Returns

CommandContextBuilder

This builder.