CommandContext
Namespace Mc.Scripting.Commands · Kind class (sealed)
public sealed class CommandContextThe parsed invocation of a command: the source and the argument values. Valid only while the executor / provider runs.
Properties
Section titled “Properties”| 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).
Player
Section titled “Player”public Player? Player { get; }The sending player, null for the console.
RawArgs
Section titled “RawArgs”public string RawArgs { get; }The text after the command name.
Result
Section titled “Result”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.
Sender
Section titled “Sender”public Entity Sender { get; }The executing entity (shortcut for Source.Entity; Entity.Null for the console).
Source
Section titled “Source”public CommandSource Source { get; }Who runs the command.
Methods
Section titled “Methods”| 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. |
Detach
Section titled “Detach”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.
GetBlockPos
Section titled “GetBlockPos”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
GetBlockState
Section titled “GetBlockState”public BlockState GetBlockState(string name)The block state of a Arg.BlockState argument.
Parameters
| Name | Type | Description |
|---|---|---|
name |
string |
The argument name. |
Returns BlockState
GetBool
Section titled “GetBool”public bool GetBool(string name)The value of a boolean argument.
Parameters
| Name | Type | Description |
|---|---|---|
name |
string |
The argument name. |
Returns bool
GetDouble
Section titled “GetDouble”public double GetDouble(string name)The value of a double argument.
Parameters
| Name | Type | Description |
|---|---|---|
name |
string |
The argument name. |
Returns double
GetEntities
Section titled “GetEntities”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>
GetFloat
Section titled “GetFloat”public float GetFloat(string name)The value of a float argument.
Parameters
| Name | Type | Description |
|---|---|---|
name |
string |
The argument name. |
Returns float
GetInt
Section titled “GetInt”public int GetInt(string name)The value of an integer argument.
Parameters
| Name | Type | Description |
|---|---|---|
name |
string |
The argument name. |
Returns int
GetLong
Section titled “GetLong”public long GetLong(string name)The value of a long argument.
Parameters
| Name | Type | Description |
|---|---|---|
name |
string |
The argument name. |
Returns long
GetPlayer
Section titled “GetPlayer”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
GetPlayers
Section titled “GetPlayers”public IReadOnlyList<Player> GetPlayers(string name)The players a selector argument matches.
Parameters
| Name | Type | Description |
|---|---|---|
name |
string |
The argument name. |
Returns IReadOnlyList<Player>
GetString
Section titled “GetString”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
GetText
Section titled “GetText”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
GetVec3
Section titled “GetVec3”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. |
RequirePlayer
Section titled “RequirePlayer”public Player RequirePlayer()The sending player, or throws CommandFailure (“Only players can use this command”) for the console.
Returns Player: The player.
See also
Section titled “See also”BlockPos · BlockState · CommandSource · Component · DetachedCommand · Entity · Player · Vec3d