Skip to content

CommandContext

Namespace Mc.Scripting.Commands · Kind class (sealed)

public sealed class CommandContext

The parsed invocation of a command: the source and the argument values. Valid only while the executor / provider runs.

Member Description
string[] Args { get; } The words after the command name (flat-command style access: split on spaces).
string Input { get; } The whole command line without the leading slash.
string Name { get; } The name of the executing command node chain’s root literal (the word the player typed).
Player? Player { get; } The sending player, null for the console.
string RawArgs { get; } The text after the command name.
int Result { get; set; } The command result the executor of an Action-style handler returns (default 1).
Entity Sender { get; } The executing entity (shortcut for Source.Entity; Entity.Null for the console).
CommandSource Source { get; } Who runs the command.
public string[] Args { get; }

The words after the command name (flat-command style access: split on spaces).

public string Input { get; }

The whole command line without the leading slash.

public string Name { get; }

The name of the executing command node chain’s root literal (the word the player typed).

public Player? Player { get; }

The sending player, null for the console.

public string RawArgs { get; }

The text after the command name.

public int Result { get; set; }

The command result the executor of an Action-style handler returns (default 1). Set it to change the number /execute store sees.

public Entity Sender { get; }

The executing entity (shortcut for Source.Entity; Entity.Null for the console).

public CommandSource Source { get; }

Who runs the command.

Member Description
DetachedCommand Detach() Copies what a command needs after its executor returned: who ran it, the input, the permission level and the position.
BlockPos GetBlockPos(string name) The block position of a Arg.BlockPos argument (relative coordinates resolved against the source).
BlockState GetBlockState(string name) The block state of a Arg.BlockState argument.
bool GetBool(string name) The value of a boolean argument.
double GetDouble(string name) The value of a double argument.
IReadOnlyList<Entity> GetEntities(string name) The entities a selector argument matches (an empty list when none).
float GetFloat(string name) The value of a float argument.
int GetInt(string name) The value of an integer argument.
long GetLong(string name) The value of a long argument.
Player GetPlayer(string name) The single player a Arg.Player argument names.
IReadOnlyList<Player> GetPlayers(string name) The players a selector argument matches.
string GetString(string name) The value of a word / phrase / greedy string argument.
string GetText(string name) The text of any argument as typed (block states, items, components, nbt, uuids, resource ids, …).
Vec3d GetVec3(string name) The position of a Arg.Vec3 argument (relative coordinates resolved against the source).
bool Has(string name) Whether an optional argument was given.
void Reply(string message) Sends a plain message to whoever ran the command.
void Reply(Component message) Sends a rich message to whoever ran the command.
Player RequirePlayer() The sending player, or throws CommandFailure (“Only players can use this command”) for the console.
public DetachedCommand Detach()

Copies what a command needs after its executor returned: who ran it, the input, the permission level and the position. Use it for deferred work (Scheduler.RunLater, a task, a callback): the context itself must not be used after the executor returned.

Returns DetachedCommand: The detached invocation, valid forever; DetachedCommand.Reply still reaches the sender while he is online.

public BlockPos GetBlockPos(string name)

The block position of a Arg.BlockPos argument (relative coordinates resolved against the source).

Parameters

Name Type Description
name string The argument name.

Returns BlockPos

public BlockState GetBlockState(string name)

The block state of a Arg.BlockState argument.

Parameters

Name Type Description
name string The argument name.

Returns BlockState

public bool GetBool(string name)

The value of a boolean argument.

Parameters

Name Type Description
name string The argument name.

Returns bool

public double GetDouble(string name)

The value of a double argument.

Parameters

Name Type Description
name string The argument name.

Returns double

public IReadOnlyList<Entity> GetEntities(string name)

The entities a selector argument matches (an empty list when none).

Parameters

Name Type Description
name string The argument name.

Returns IReadOnlyList<Entity>

public float GetFloat(string name)

The value of a float argument.

Parameters

Name Type Description
name string The argument name.

Returns float

public int GetInt(string name)

The value of an integer argument.

Parameters

Name Type Description
name string The argument name.

Returns int

public long GetLong(string name)

The value of a long argument.

Parameters

Name Type Description
name string The argument name.

Returns long

public Player GetPlayer(string name)

The single player a Arg.Player argument names. Throws CommandFailure when none matched.

Parameters

Name Type Description
name string The argument name.

Returns Player

public IReadOnlyList<Player> GetPlayers(string name)

The players a selector argument matches.

Parameters

Name Type Description
name string The argument name.

Returns IReadOnlyList<Player>

public string GetString(string name)

The value of a word / phrase / greedy string argument.

Parameters

Name Type Description
name string The argument name.

Returns string

public string GetText(string name)

The text of any argument as typed (block states, items, components, nbt, uuids, resource ids, …).

Parameters

Name Type Description
name string The argument name.

Returns string

public Vec3d GetVec3(string name)

The position of a Arg.Vec3 argument (relative coordinates resolved against the source).

Parameters

Name Type Description
name string The argument name.

Returns Vec3d

public bool Has(string name)

Whether an optional argument was given.

Parameters

Name Type Description
name string The argument name.

Returns bool: True when the command line contained it.

public void Reply(string message)

Sends a plain message to whoever ran the command.

Parameters

Name Type Description
message string The text.
public void Reply(Component message)

Sends a rich message to whoever ran the command.

Parameters

Name Type Description
message Component The component.
public Player RequirePlayer()

The sending player, or throws CommandFailure (“Only players can use this command”) for the console.

Returns Player: The player.

BlockPos · BlockState · CommandSource · Component · DetachedCommand · Entity · Player · Vec3d