endstone/command

Classes

NameDescription
BlockCommandSenderRepresents a block command sender.
CommandRepresents a Command, which executes various tasks upon user input.
CommandExecutorRepresents a class which contains a single method for executing commands.
CommandMapRepresents a command map that manages all commands of the Server.
CommandSenderRepresents a command sender.
CommandSenderWrapperRepresents a wrapper that forwards commands to the wrapped CommandSender and captures its output.
ConsoleCommandSenderRepresents a console command sender.
PluginCommandRepresents a Command belonging to a Plugin.

classBlockCommandSender

Defined in <endstone/command/block_command_sender.h>

Bases: CommandSender

Represents a block command sender.

Methods

NameDescription
getBlockReturns the block this command sender belongs to.

methgetBlockabstractconst

std::unique_ptr<Block> getBlock() const =0

Returns the block this command sender belongs to.

Returns

TypeDescription
std::unique_ptr<Block>Block for the command sender

classCommand

Defined in <endstone/command/command.h>

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

Methods

methCommandexplicit

Command(std::string name, std::string description = "", std::vector<std::string> usages = {}, std::vector<std::string> aliases = {}, std::vector<std::string> permissions = {})

meth~Commandvirtual

~Command() =default

methexecutevirtualconst

bool execute(CommandSender& sender, const std::vector<std::string>& args) const

Executes the command, returning its success

Parameters

NameTypeDescription
senderCommandSender&Source of the command
argsconst std::vector<std::string>&Arguments passed to the command

Returns

TypeDescription
booltrue if the execution was successful, otherwise false

methgetNameconst

std::string getName() const

Returns the name of this command

Returns

TypeDescription
std::stringName of this command

methsetName

void setName(std::string name)

Sets the name of this command.

May only be used before registering the command.

Parameters

NameTypeDescription
namestd::stringNew command name

methgetDescriptionconst

std::string getDescription() const

Gets a brief description of this command

Returns

TypeDescription
std::stringDescription of this command

methsetDescription

void setDescription(std::string description)

Sets a brief description of this command.

Parameters

NameTypeDescription
descriptionstd::stringnew command description

methgetAliasesconst

std::vector<std::string> getAliases() const

Returns a list of aliases of this command

Returns

TypeDescription
std::vector<std::string>List of aliases

methsetAliases

void setAliases(Alias... aliases)

Sets the list of aliases to request on registration for this command.

Parameters

NameTypeDescription
aliasesAlias...aliases to register to this command

methgetUsagesconst

std::vector<std::string> getUsages() const

Returns a list of usages of this command

Returns

TypeDescription
std::vector<std::string>List of usages

methsetUsages

void setUsages(Usage... usages)

Sets the usages of this command

Parameters

NameTypeDescription
usagesUsage...List of usages

methgetPermissionsconst

std::vector<std::string> getPermissions() const

Gets the permissions required by users to be able to perform this command

Returns

TypeDescription
std::vector<std::string>List of permission names, or empty if none

methsetPermissions

void setPermissions(Permission... permissions)

Sets the permissions required by users to be able to perform this command

Parameters

NameTypeDescription
permissionsPermission...List of permission names

methtestPermissionconst

bool testPermission(const CommandSender& target) const

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

NameTypeDescription
targetconst CommandSender&User to test

Returns

TypeDescription
booltrue if they can use it, otherwise false

methtestPermissionSilentlyconst

bool testPermissionSilently(const CommandSender& target) const

Tests the given CommandSender to see if they can perform this command. No error is sent to the sender.

Parameters

NameTypeDescription
targetconst CommandSender&User to test

Returns

TypeDescription
booltrue if they can use it, otherwise false

methregisterTo

bool registerTo(const CommandMap& command_map)

Registers this command to a CommandMap.

Parameters

NameTypeDescription
command_mapconst CommandMap&the CommandMap to register to

Returns

TypeDescription
booltrue if the registration was successful, false otherwise

methunregisterFrom

bool unregisterFrom(const CommandMap& command_map)

Unregisters this command from a CommandMap

Parameters

NameTypeDescription
command_mapconst CommandMap&the CommandMap to unregister from

Returns

TypeDescription
booltrue if the unregistration was successful, false otherwise

methisRegisteredconst

bool isRegistered() const

Returns the current registered state of this command

Returns

TypeDescription
booltrue if this command is currently registered false otherwise

methasPluginCommandvirtualconst

PluginCommand* asPluginCommand() const

classCommandExecutor

Defined in <endstone/command/command_executor.h>

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

Methods

meth~CommandExecutorvirtual

~CommandExecutor() =default

methonCommandvirtual

bool onCommand(CommandSender& sender, const Command& command, const std::vector<std::string>& args)

Executes the given command, returning its success.

Parameters

NameTypeDescription
senderCommandSender&Source of the command
commandconst Command&Command which was executed
argsconst std::vector<std::string>&Passed command arguments

Returns

TypeDescription
booltrue if the execution is successful, otherwise false

classCommandMap

Defined in <endstone/command/command_map.h>

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

Methods

NameDescription
CommandMap
CommandMap
operator=
CommandMap
operator=
~CommandMap
registerCommand
dispatchLooks for the requested command and executes it if found.
clearCommands
getCommand

methCommandMap

CommandMap() =default

methCommandMap

CommandMap(const CommandMap&) =delete

methoperator=

CommandMap& operator=(const CommandMap&) =delete

methCommandMap

CommandMap(CommandMap&&) =default

methoperator=

CommandMap& operator=(CommandMap&&) =default

meth~CommandMapvirtual

~CommandMap() =default

methregisterCommandabstract

bool registerCommand(std::shared_ptr<Command> command) =0

Registers a command.

Parameters

NameTypeDescription
commandstd::shared_ptr<Command>the command to register

Returns

TypeDescription
booltrue on success, false if a command with the same name is already registered

methdispatchabstractconst

bool dispatch(CommandSender& sender, std::string command_line) const =0

Looks for the requested command and executes it if found.

Parameters

NameTypeDescription
senderCommandSender&The command's sender
command_linestd::stringcommand + arguments. Example: "/test abc 123"

Returns

TypeDescription
booltrue if execution is successful, false otherwise

methclearCommandsabstract

void clearCommands() =0

Clears all registered commands.

methgetCommandabstractconst

std::shared_ptr<Command> getCommand(std::string name) const =0

Gets the command registered to the specified name

Parameters

NameTypeDescription
namestd::stringName of the command to retrieve

Returns

TypeDescription
std::shared_ptr<Command>Command with the specified name or nullptr if a command with that label doesn't exist

classCommandSender

Defined in <endstone/command/command_sender.h>

Bases: Permissible

Represents a command sender.

Methods

NameDescription
asCommandSenderCasts a Permissible as CommandSender.
asConsoleGets a CommandSender as ConsoleCommandSender.
asBlockGets a CommandSender as BlockCommandSender.
asActorGets a CommandSender as Actor.
asPlayerGets a CommandSender as Player.
sendMessageSends this sender a message.
sendMessage
sendErrorMessageSends this sender a error message.
sendErrorMessage
getServerReturns the server instance that this command is running on.
getNameGets the name of this command sender.

methasCommandSendervirtualconstoverride

CommandSender* asCommandSender() const override

Casts a Permissible as CommandSender.

Returns

TypeDescription
CommandSender*CommandSender, nullptr if not a CommandSender

methasConsoleabstractconst

ConsoleCommandSender* asConsole() const =0

Gets a CommandSender as ConsoleCommandSender.

Returns

methasBlockabstractconst

BlockCommandSender* asBlock() const =0

Gets a CommandSender as BlockCommandSender.

Returns

TypeDescription
BlockCommandSender*CommandSender, nullptr if not a BlockCommandSender

methasActorabstractconst

Actor* asActor() const =0

Gets a CommandSender as Actor.

Returns

TypeDescription
Actor*Actor, nullptr if not an Actor

methasPlayerabstractconst

Player* asPlayer() const =0

Gets a CommandSender as Player.

Returns

TypeDescription
Player*Player, nullptr if not a Player

methsendMessageabstractconst

void sendMessage(const Message& message) const =0

Sends this sender a message.

Parameters

NameTypeDescription
messageconst Message&Message to be displayed

methsendMessageconst

void sendMessage(const std::format_string<Args...> format, Args&&... args) const

methsendErrorMessageabstractconst

void sendErrorMessage(const Message& message) const =0

Sends this sender a error message.

Parameters

NameTypeDescription
messageconst Message&Error message to be displayed

methsendErrorMessageconst

void sendErrorMessage(const std::format_string<Args...> format, Args&&... args) const

methgetServerabstractconst

Server& getServer() const =0

Returns the server instance that this command is running on.

Returns

TypeDescription
Server&Server instance

methgetNameabstractconst

std::string getName() const =0

Gets the name of this command sender.

Returns

TypeDescription
std::stringName of the sender

classCommandSenderWrapper

Defined in <endstone/command/command_sender_wrapper.h>

Bases: CommandSender

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

Type Aliases

NameDescription
Callback

Methods

NameDescription
CommandSenderWrapper
sendMessageSends this sender a message.
sendErrorMessageSends this sender a error message.
getPermissionLevelGets the permission level of this object.
isPermissionSetChecks if this object contains an override for the specified permission, by fully qualified name.
isPermissionSetChecks if this object contains an override for the specified Permission.
hasPermissionGets the value of the specified permission, if set. If a permission override is not set on this object, the default value of the permission will be returned.
hasPermissionGets the value of the specified permission, if set. If a permission override is not set on this object, the default value of the permission will be returned.
addAttachmentAdds a new PermissionAttachment with a single permission by name and value.
addAttachmentAdds a new empty PermissionAttachment to this object.
removeAttachmentRemoves the given PermissionAttachment from this object.
recalculatePermissionsRecalculates the permissions for this object, if the attachments have changed values. This should very rarely need to be called from a plugin.
getEffectivePermissionsGets a set containing all the permissions currently in effect by this object.
asConsoleGets a CommandSender as ConsoleCommandSender.
asBlockGets a CommandSender as BlockCommandSender.
asActorGets a CommandSender as Actor.
asPlayerGets a CommandSender as Player.
getServerReturns the server instance that this command is running on.
getNameGets the name of this command sender.

typeCallback

std::function<void(const Message&)> Callback

methCommandSenderWrapperexplicit

CommandSenderWrapper(CommandSender& sender, Callback on_message = {}, Callback on_error = {})

methsendMessagevirtualconstoverride

void sendMessage(const Message& message) const override

Sends this sender a message.

Parameters

NameTypeDescription
messageconst Message&Message to be displayed

methsendErrorMessagevirtualconstoverride

void sendErrorMessage(const Message& message) const override

Sends this sender a error message.

Parameters

NameTypeDescription
messageconst Message&Error message to be displayed

methgetPermissionLevelvirtualconstoverride

PermissionLevel getPermissionLevel() const override

Gets the permission level of this object.

Returns

TypeDescription
PermissionLevelThe permission level

methisPermissionSetvirtualconstoverride

bool isPermissionSet(std::string name) const override

Checks if this object contains an override for the specified permission, by fully qualified name.

Parameters

NameTypeDescription
namestd::stringName of the permission

Returns

TypeDescription
booltrue if the permission is set, otherwise false

methisPermissionSetvirtualconstoverride

bool isPermissionSet(const Permission& perm) const override

Checks if this object contains an override for the specified Permission.

Parameters

NameTypeDescription
permconst Permission&Permission to check

Returns

TypeDescription
booltrue if the permission is set, otherwise false

methhasPermissionvirtualconstoverride

bool hasPermission(std::string name) const override

Gets the value of the specified permission, if set. If a permission override is not set on this object, the default value of the permission will be returned.

Parameters

NameTypeDescription
namestd::stringName of the permission

Returns

TypeDescription
boolValue of the permission

methhasPermissionvirtualconstoverride

bool hasPermission(const Permission& perm) const override

Gets the value of the specified permission, if set. If a permission override is not set on this object, the default value of the permission will be returned.

Parameters

NameTypeDescription
permconst Permission&Permission to get

Returns

TypeDescription
boolValue of the permission

methaddAttachmentvirtualoverride

PermissionAttachment* addAttachment(Plugin& plugin, const std::string& name, bool value) override

Adds a new PermissionAttachment with a single permission by name and value.

Parameters

NameTypeDescription
pluginPlugin&Plugin responsible for this attachment, may not be null or disabled
nameconst std::string&Name of the permission to attach
valueboolValue of the permission

Returns

TypeDescription
PermissionAttachment*The PermissionAttachment that was just created

methaddAttachmentvirtualoverride

PermissionAttachment* addAttachment(Plugin& plugin) override

Adds a new empty PermissionAttachment to this object.

Parameters

NameTypeDescription
pluginPlugin&Plugin responsible for this attachment, may not be null or disabled

Returns

TypeDescription
PermissionAttachment*The PermissionAttachment that was just created

methremoveAttachmentvirtualoverride

bool removeAttachment(PermissionAttachment& attachment) override

Removes the given PermissionAttachment from this object.

Parameters

NameTypeDescription
attachmentPermissionAttachment&Attachment to remove

Returns

TypeDescription
booltrue if the specified attachment was removed successfully, false when it isn't part of this object

methrecalculatePermissionsvirtualoverride

void recalculatePermissions() override

Recalculates the permissions for this object, if the attachments have changed values. This should very rarely need to be called from a plugin.

methgetEffectivePermissionsvirtualconstoverride

std::unordered_set<PermissionAttachmentInfo*> getEffectivePermissions() const override

Gets a set containing all the permissions currently in effect by this object.

Returns

TypeDescription
std::unordered_set<PermissionAttachmentInfo*>Set of currently effective permissions

methasConsolevirtualconstoverride

ConsoleCommandSender* asConsole() const override

Gets a CommandSender as ConsoleCommandSender.

Returns

methasBlockvirtualconstoverride

BlockCommandSender* asBlock() const override

Gets a CommandSender as BlockCommandSender.

Returns

TypeDescription
BlockCommandSender*CommandSender, nullptr if not a BlockCommandSender

methasActorvirtualconstoverride

Actor* asActor() const override

Gets a CommandSender as Actor.

Returns

TypeDescription
Actor*Actor, nullptr if not an Actor

methasPlayervirtualconstoverride

Player* asPlayer() const override

Gets a CommandSender as Player.

Returns

TypeDescription
Player*Player, nullptr if not a Player

methgetServervirtualconstoverride

Server& getServer() const override

Returns the server instance that this command is running on.

Returns

TypeDescription
Server&Server instance

methgetNamevirtualconstoverride

std::string getName() const override

Gets the name of this command sender.

Returns

TypeDescription
std::stringName of the sender

classConsoleCommandSender

Defined in <endstone/command/console_command_sender.h>

Bases: CommandSender

Represents a console command sender.

classPluginCommand

Defined in <endstone/command/plugin_command.h>

Bases: Command

Represents a Command belonging to a Plugin.

Methods

methPluginCommand

PluginCommand(const Command& command, Plugin& owner)

methexecutevirtualconstoverride

bool execute(CommandSender& sender, const std::vector<std::string>& args) const override

Executes the command, returning its success

Parameters

NameTypeDescription
senderCommandSender&Source of the command
argsconst std::vector<std::string>&Arguments passed to the command

Returns

TypeDescription
booltrue if the execution was successful, otherwise false

methsetExecutorvirtual

void setExecutor(std::shared_ptr<CommandExecutor> executor)

Sets the CommandExecutor to run when parsing this command

Parameters

NameTypeDescription
executorstd::shared_ptr<CommandExecutor>New executor to run

methgetExecutorvirtualconst

CommandExecutor& getExecutor() const

Gets the CommandExecutor associated with this command

Returns

TypeDescription
CommandExecutor&CommandExecutor object linked to this command

methgetPluginconst

Plugin& getPlugin() const

Gets the owner of this PluginCommand

Returns

TypeDescription
Plugin&Plugin that owns this command

methasPluginCommandvirtualconstoverride

PluginCommand* asPluginCommand() const override

On this page