Skip to content

Class ContextChain

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

Represents redirect modifiers followed by one executable command context.

public record ContextChain : IEquatable<ContextChain>

Inheritance

objectContextChain

Implements

IEquatable<ContextChain>

Inherited Members

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

Constructors

ContextChain(List<CommandContext>, CommandContext)

Represents redirect modifiers followed by one executable command context.

public ContextChain(List<CommandContext> Modifiers, CommandContext Executable)

Parameters

Modifiers List<CommandContext>

The ordered redirect-modifier contexts.

Executable CommandContext

The final executable context.

Properties

Executable

The final executable context.

public CommandContext Executable { get; init; }

Property Value

CommandContext

Modifiers

The ordered redirect-modifier contexts.

public List<CommandContext> Modifiers { get; init; }

Property Value

List<CommandContext>

NextStage

Gets a cached chain with the first modifier removed, or null at execution.

public ContextChain? NextStage { get; }

Property Value

ContextChain?

Stage

Gets whether this chain begins with modification or execution.

public ContextChain.ContextChainStage Stage { get; }

Property Value

ContextChain.ContextChainStage

TopContext

Gets the first modifier, or the executable context when no modifiers remain.

public CommandContext TopContext { get; }

Property Value

CommandContext

Methods

ExecuteAllAsync(ICommandSource, ResultConsumer, CancellationToken)

Runs all redirect stages and executes the final context for every resulting source.

public ValueTask<int> ExecuteAllAsync(ICommandSource source, ResultConsumer resultConsumer, CancellationToken cancellationToken)

Parameters

source ICommandSource

The initial source.

resultConsumer ResultConsumer

The callback notified for each execution attempt.

cancellationToken CancellationToken

The cancellation token passed to executors.

Returns

ValueTask<int>

The accumulated result, using successful branch counts once the chain forks.

RunExecutableAsync(CommandContext, ICommandSource, ResultConsumer, bool, CancellationToken)

Executes one final context and reports its outcome.

public static ValueTask<int> RunExecutableAsync(CommandContext context, ICommandSource source, ResultConsumer resultConsumer, bool forkedMode, CancellationToken cancellationToken)

Parameters

context CommandContext

The executable context.

source ICommandSource

The execution source.

resultConsumer ResultConsumer

The callback notified of success or syntax failure.

forkedMode bool

Whether to return one per successful branch and suppress syntax failures.

cancellationToken CancellationToken

The cancellation token passed to the executor.

Returns

ValueTask<int>

The executor result, one for a successful fork, or zero for a suppressed failure.

RunModifier(CommandContext, ICommandSource, ResultConsumer, bool)

Runs one redirect modifier or propagates the source for a simple redirect.

public static IEnumerable<ICommandSource> RunModifier(CommandContext modifier, ICommandSource source, ResultConsumer resultConsumer, bool forkedMode)

Parameters

modifier CommandContext

The redirect context.

source ICommandSource

The current source.

resultConsumer ResultConsumer

The callback notified of syntax failures.

forkedMode bool

Whether syntax failures should be converted to an empty source sequence.

Returns

IEnumerable<ICommandSource>

The sources for the next stage.

TryFlatten(CommandContext)

Flattens a redirected child chain into modifiers and one executable context.

public static ContextChain? TryFlatten(CommandContext rootContext)

Parameters

rootContext CommandContext

The root parsed context.

Returns

ContextChain?

The flattened chain, or null when the final context has no executor.