Skip to content

Class CommandContext

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

Contains the parsed nodes, arguments, source, and execution metadata for a command stage.

public record CommandContext : IEquatable<CommandContext>

Inheritance

objectCommandContext

Implements

IEquatable<CommandContext>

Inherited Members

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

Constructors

CommandContext(ICommandSource, string, Dictionary<string, IParsedArgument>, CommandExecutor?, CommandNode, List<ParsedCommandNode>, StringRange, CommandContext?, RedirectModifier?, bool)

Contains the parsed nodes, arguments, source, and execution metadata for a command stage.

public CommandContext(ICommandSource Source, string Input, Dictionary<string, IParsedArgument> Arguments, CommandExecutor? Executor, CommandNode RootNode, List<ParsedCommandNode> Nodes, StringRange Range, CommandContext? Child, RedirectModifier? RedirectModifier, bool Forks)

Parameters

Source ICommandSource

The command source for this context.

Input string

The complete command input.

Arguments Dictionary<string, IParsedArgument>

Parsed arguments keyed by node name.

Executor CommandExecutor?

The executor associated with the final parsed node, if any.

RootNode CommandNode

The tree root used for parsing.

Nodes List<ParsedCommandNode>

The parsed command-node sequence.

Range StringRange

The input range covered by this context.

Child CommandContext?

The redirected child context, if any.

RedirectModifier RedirectModifier?

The source modifier applied before entering the child.

Forks bool

Whether this redirect forks execution across sources.

Properties

Arguments

Parsed arguments keyed by node name.

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

Property Value

Dictionary<string, IParsedArgument>

Child

The redirected child context, if any.

public CommandContext? Child { get; init; }

Property Value

CommandContext?

Executor

The executor associated with the final parsed node, if any.

public CommandExecutor? Executor { get; init; }

Property Value

CommandExecutor?

Forks

Whether this redirect forks execution across sources.

public bool Forks { get; init; }

Property Value

bool

HasNodes

Gets whether at least one command node was parsed.

public bool HasNodes { get; }

Property Value

bool

Input

The complete command input.

public string Input { get; init; }

Property Value

string

Nodes

The parsed command-node sequence.

public List<ParsedCommandNode> Nodes { get; init; }

Property Value

List<ParsedCommandNode>

Range

The input range covered by this context.

public StringRange Range { get; init; }

Property Value

StringRange

RedirectModifier

The source modifier applied before entering the child.

public RedirectModifier? RedirectModifier { get; init; }

Property Value

RedirectModifier?

RootNode

The tree root used for parsing.

public CommandNode RootNode { get; init; }

Property Value

CommandNode

Source

The command source for this context.

public ICommandSource Source { get; init; }

Property Value

ICommandSource

Methods

CopyFor(ICommandSource)

Returns this context for an equal source, or a shallow copy using another source.

public CommandContext CopyFor(ICommandSource source)

Parameters

source ICommandSource

The source to associate.

Returns

CommandContext

This instance or the source-adjusted copy.

GetArgument<TType>(string)

Gets and converts a parsed argument value by name.

public TType GetArgument<TType>(string name)

Parameters

name string

The argument name.

Returns

TType

The converted argument value.

Type Parameters

TType

The requested result type.

Exceptions

ArgumentException

The argument is absent or has an incompatible result type.

GetLastChild()

Traverses redirected children to the final context.

public CommandContext GetLastChild()

Returns

CommandContext

The last context in the child chain.

TryGetArgument<TType>(string, out TType)

Attempts to get and convert a parsed argument value by name.

public bool TryGetArgument<TType>(string name, out TType type)

Parameters

name string

The argument name.

type TType

The converted value when found.

Returns

bool

false only when the name is absent; otherwise true.

Type Parameters

TType

The requested result type.

Exceptions

ArgumentException

The argument exists but its result has an incompatible type.