Skip to content

Command

endstone.command

Classes relating to handling specialized non-chat player input.

Classes:

Name Description
BlockCommandSender

Represents a block command sender.

Command

Represents a Command, which executes various tasks upon user input.

CommandExecutor

Represents a class which contains a single method for executing commands.

CommandMap

Represents a command map that manages all commands of the Server.

CommandSender

Represents a command sender.

CommandSenderWrapper

Represents a wrapper that forwards commands to the wrapped CommandSender and captures its output.

ConsoleCommandSender

Represents a console command sender.

ProxiedCommandSender

Represents a command sender that is running a command on behalf of another one, as /execute does.

BlockCommandSender

Bases: CommandSender

Represents a block command sender.

Attributes:

Name Type Description
block Block

The block this command sender belongs to.

block property

block: Block

The block this command sender belongs to.

Command

Command(
    name: str,
    description: str | None = None,
    usages: list[str] | None = None,
    aliases: list[str] | None = None,
    permissions: list[str] | None = None,
    *args: Any,
    **kwargs: Any
)

Represents a Command, which executes various tasks upon user input.

Methods:

Name Description
execute

Executes the command, returning its success.

test_permission

Tests the given CommandSender to see if they can perform this command.

test_permission_silently

Tests the given CommandSender to see if they can perform this command.

Attributes:

Name Type Description
aliases list[str]

A list of aliases of this command.

description str

A brief description of this command.

is_registered bool

The current registered state of this command.

name str

The name of this command.

permissions list[str]

The permissions required by users to be able to perform this command.

usages list[str]

A list of usages of this command.

aliases property writable

aliases: list[str]

A list of aliases of this command.

description property writable

description: str

A brief description of this command.

is_registered property

is_registered: bool

The current registered state of this command.

name property writable

name: str

The name of this command.

permissions property writable

permissions: list[str]

The permissions required by users to be able to perform this command.

usages property writable

usages: list[str]

A list of usages of this command.

execute

execute(sender: CommandSender, args: list[str]) -> bool

Executes the command, returning its success.

Parameters:

Name Type Description Default
sender CommandSender

Source of the command.

required
args list[str]

Arguments passed to the command.

required

Returns:

Type Description
bool

True if the execution was successful, False otherwise.

test_permission

test_permission(target: CommandSender) -> bool

Tests the given CommandSender to see if they can perform this command.

If they do not have permission, they will be informed that they cannot do this.

Parameters:

Name Type Description Default
target CommandSender

User to test.

required

Returns:

Type Description
bool

True if they can use it, False otherwise.

test_permission_silently

test_permission_silently(target: CommandSender) -> bool

Tests the given CommandSender to see if they can perform this command.

No error is sent to the sender.

Parameters:

Name Type Description Default
target CommandSender

User to test.

required

Returns:

Type Description
bool

True if they can use it, False otherwise.

CommandExecutor

CommandExecutor()

Represents a class which contains a single method for executing commands.

Methods:

Name Description
on_command

Executes the given command, returning its success.

on_command

on_command(
    sender: CommandSender, command: Command, args: list[str]
) -> bool

Executes the given command, returning its success.

Parameters:

Name Type Description Default
sender CommandSender

Source of the command.

required
command Command

Command which was executed.

required
args list[str]

Passed command arguments.

required

Returns:

Type Description
bool

True if the execution is successful, False otherwise.

CommandMap

Represents a command map that manages all commands of the Server.

Methods:

Name Description
clear_commands

Clears all registered commands.

dispatch

Looks for the requested command and executes it if found.

get_command

Gets the command registered to the specified name.

register_command

Registers a command.

clear_commands

clear_commands() -> None

Clears all registered commands.

dispatch

dispatch(sender: CommandSender, command_line: str) -> bool

Looks for the requested command and executes it if found.

Parameters:

Name Type Description Default
sender CommandSender

The command's sender.

required
command_line str

The command and its arguments, e.g. "/test abc 123".

required

Returns:

Type Description
bool

True if the execution was successful, False otherwise.

get_command

get_command(name: str) -> Command | None

Gets the command registered to the specified name.

Parameters:

Name Type Description Default
name str

The name of the command to retrieve.

required

Returns:

Type Description
Command | None

The command with the specified name, None if a command with that label doesn't exist.

register_command

register_command(command: Command) -> bool

Registers a command.

Parameters:

Name Type Description Default
command Command

The command to register.

required

Returns:

Type Description
bool

True on success, False if a command with the same name is already registered.

CommandSender

Bases: Permissible

Represents a command sender.

Methods:

Name Description
send_error_message

Sends this sender a error message.

send_message

Sends this sender a message.

Attributes:

Name Type Description
name str

The name of this command sender.

server Server

The server instance that this command is running on.

name property

name: str

The name of this command sender.

server property

server: Server

The server instance that this command is running on.

send_error_message

send_error_message(message: str | Translatable) -> None

Sends this sender a error message.

Parameters:

Name Type Description Default
message str | Translatable

Error message to be displayed.

required

send_message

send_message(message: str | Translatable) -> None

Sends this sender a message.

Parameters:

Name Type Description Default
message str | Translatable

Message to be displayed.

required

CommandSenderWrapper

CommandSenderWrapper(
    sender: CommandSender,
    on_message: (
        Callable[[str | Translatable], None] | None
    ) = None,
    on_error: (
        Callable[[str | Translatable], None] | None
    ) = None,
)

Bases: CommandSender

Represents a wrapper that forwards commands to the wrapped CommandSender and captures its output.

ConsoleCommandSender

Bases: CommandSender

Represents a console command sender.

ProxiedCommandSender

Bases: CommandSender

Represents a command sender that is running a command on behalf of another one, as /execute does.

Output and permissions belong to the caller, while the name and the execution context belong to the callee.

Attributes:

Name Type Description
callee CommandSender

The CommandSender which is being used to call the command.

caller CommandSender

The CommandSender which triggered this proxied command.

callee property

callee: CommandSender

The CommandSender which is being used to call the command.

caller property

caller: CommandSender

The CommandSender which triggered this proxied command.