endstone/command
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. |
PluginCommand | Represents a Command belonging to a Plugin. |
classBlockCommandSender
Defined in <endstone/command/block_command_sender.h>
Bases: CommandSender
Represents a block command sender.
Methods
| Name | Description |
|---|---|
getBlock | Returns the block this command sender belongs to. |
methgetBlockabstractconst
std::unique_ptr<Block> getBlock() const =0Returns the block this command sender belongs to.
Returns
| Type | Description |
|---|---|
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() =defaultmethexecutevirtualconst
bool execute(CommandSender& sender, const std::vector<std::string>& args) constExecutes the command, returning its success
Parameters
| Name | Type | Description |
|---|---|---|
sender | CommandSender& | Source of the command |
args | const std::vector<std::string>& | Arguments passed to the command |
Returns
| Type | Description |
|---|---|
bool | true if the execution was successful, otherwise false |
methgetNameconst
std::string getName() constReturns the name of this command
Returns
| Type | Description |
|---|---|
std::string | Name of this command |
methsetName
void setName(std::string name)Sets the name of this command.
May only be used before registering the command.
Parameters
| Name | Type | Description |
|---|---|---|
name | std::string | New command name |
methgetDescriptionconst
std::string getDescription() constGets a brief description of this command
Returns
| Type | Description |
|---|---|
std::string | Description of this command |
methsetDescription
void setDescription(std::string description)Sets a brief description of this command.
Parameters
| Name | Type | Description |
|---|---|---|
description | std::string | new command description |
methgetAliasesconst
std::vector<std::string> getAliases() constReturns a list of aliases of this command
Returns
| Type | Description |
|---|---|
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
| Name | Type | Description |
|---|---|---|
aliases | Alias... | aliases to register to this command |
methgetUsagesconst
std::vector<std::string> getUsages() constReturns a list of usages of this command
Returns
| Type | Description |
|---|---|
std::vector<std::string> | List of usages |
methsetUsages
void setUsages(Usage... usages)Sets the usages of this command
Parameters
| Name | Type | Description |
|---|---|---|
usages | Usage... | List of usages |
methgetPermissionsconst
std::vector<std::string> getPermissions() constGets the permissions required by users to be able to perform this command
Returns
| Type | Description |
|---|---|
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
| Name | Type | Description |
|---|---|---|
permissions | Permission... | List of permission names |
methtestPermissionconst
bool testPermission(const CommandSender& target) constTests 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 |
|---|---|---|
target | const CommandSender& | User to test |
Returns
| Type | Description |
|---|---|
bool | true if they can use it, otherwise false |
methtestPermissionSilentlyconst
bool testPermissionSilently(const CommandSender& target) constTests the given CommandSender to see if they can perform this command. No error is sent to the sender.
Parameters
| Name | Type | Description |
|---|---|---|
target | const CommandSender& | User to test |
Returns
| Type | Description |
|---|---|
bool | true if they can use it, otherwise false |
methregisterTo
bool registerTo(const CommandMap& command_map)Registers this command to a CommandMap.
Parameters
| Name | Type | Description |
|---|---|---|
command_map | const CommandMap& | the CommandMap to register to |
Returns
| Type | Description |
|---|---|
bool | true if the registration was successful, false otherwise |
methunregisterFrom
bool unregisterFrom(const CommandMap& command_map)Unregisters this command from a CommandMap
Parameters
| Name | Type | Description |
|---|---|---|
command_map | const CommandMap& | the CommandMap to unregister from |
Returns
| Type | Description |
|---|---|
bool | true if the unregistration was successful, false otherwise |
methisRegisteredconst
bool isRegistered() constReturns the current registered state of this command
Returns
| Type | Description |
|---|---|
bool | true if this command is currently registered false otherwise |
methasPluginCommandvirtualconst
PluginCommand* asPluginCommand() constclassCommandExecutor
Defined in <endstone/command/command_executor.h>
Represents a class which contains a single method for executing commands.
Methods
| Name | Description |
|---|---|
~CommandExecutor | |
onCommand |
meth~CommandExecutorvirtual
~CommandExecutor() =defaultmethonCommandvirtual
bool onCommand(CommandSender& sender, const Command& command, const std::vector<std::string>& args)Executes the given command, returning its success.
Parameters
| Name | Type | Description |
|---|---|---|
sender | CommandSender& | Source of the command |
command | const Command& | Command which was executed |
args | const std::vector<std::string>& | Passed command arguments |
Returns
| Type | Description |
|---|---|
bool | true 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
| Name | Description |
|---|---|
CommandMap | |
CommandMap | |
operator= | |
CommandMap | |
operator= | |
~CommandMap | |
registerCommand | |
dispatch | Looks for the requested command and executes it if found. |
clearCommands | |
getCommand |
methCommandMap
CommandMap() =defaultmethCommandMap
CommandMap(const CommandMap&) =deletemethoperator=
CommandMap& operator=(const CommandMap&) =deletemethCommandMap
CommandMap(CommandMap&&) =defaultmethoperator=
CommandMap& operator=(CommandMap&&) =defaultmeth~CommandMapvirtual
~CommandMap() =defaultmethregisterCommandabstract
bool registerCommand(std::shared_ptr<Command> command) =0Registers a command.
Parameters
| Name | Type | Description |
|---|---|---|
command | std::shared_ptr<Command> | the command to register |
Returns
| Type | Description |
|---|---|
bool | true on success, false if a command with the same name is already registered |
methdispatchabstractconst
bool dispatch(CommandSender& sender, std::string command_line) const =0Looks for the requested command and executes it if found.
Parameters
| Name | Type | Description |
|---|---|---|
sender | CommandSender& | The command's sender |
command_line | std::string | command + arguments. Example: "/test abc 123" |
Returns
| Type | Description |
|---|---|
bool | true if execution is successful, false otherwise |
methclearCommandsabstract
void clearCommands() =0Clears all registered commands.
methgetCommandabstractconst
std::shared_ptr<Command> getCommand(std::string name) const =0Gets the command registered to the specified name
Parameters
| Name | Type | Description |
|---|---|---|
name | std::string | Name of the command to retrieve |
Returns
| Type | Description |
|---|---|
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
| Name | Description |
|---|---|
asCommandSender | Casts a Permissible as CommandSender. |
asConsole | Gets a CommandSender as ConsoleCommandSender. |
asBlock | Gets a CommandSender as BlockCommandSender. |
asActor | Gets a CommandSender as Actor. |
asPlayer | Gets a CommandSender as Player. |
sendMessage | Sends this sender a message. |
sendMessage | |
sendErrorMessage | Sends this sender a error message. |
sendErrorMessage | |
getServer | Returns the server instance that this command is running on. |
getName | Gets the name of this command sender. |
methasCommandSendervirtualconstoverride
CommandSender* asCommandSender() const overrideCasts a Permissible as CommandSender.
Returns
| Type | Description |
|---|---|
CommandSender* | CommandSender, nullptr if not a CommandSender |
methasConsoleabstractconst
ConsoleCommandSender* asConsole() const =0Gets a CommandSender as ConsoleCommandSender.
Returns
| Type | Description |
|---|---|
ConsoleCommandSender* | CommandSender, nullptr if not a ConsoleCommandSender |
methasBlockabstractconst
BlockCommandSender* asBlock() const =0Gets a CommandSender as BlockCommandSender.
Returns
| Type | Description |
|---|---|
BlockCommandSender* | CommandSender, nullptr if not a BlockCommandSender |
methasActorabstractconst
Actor* asActor() const =0Gets a CommandSender as Actor.
methasPlayerabstractconst
Player* asPlayer() const =0Gets a CommandSender as Player.
methsendMessageabstractconst
void sendMessage(const Message& message) const =0Sends this sender a message.
methsendMessageconst
void sendMessage(const std::format_string<Args...> format, Args&&... args) constmethsendErrorMessageabstractconst
void sendErrorMessage(const Message& message) const =0Sends this sender a error message.
Parameters
| Name | Type | Description |
|---|---|---|
message | const Message& | Error message to be displayed |
methsendErrorMessageconst
void sendErrorMessage(const std::format_string<Args...> format, Args&&... args) constmethgetServerabstractconst
Server& getServer() const =0Returns the server instance that this command is running on.
methgetNameabstractconst
std::string getName() const =0Gets the name of this command sender.
Returns
| Type | Description |
|---|---|
std::string | Name 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
| Name | Description |
|---|---|
Callback |
Methods
| Name | Description |
|---|---|
CommandSenderWrapper | |
sendMessage | Sends this sender a message. |
sendErrorMessage | Sends this sender a error message. |
getPermissionLevel | Gets the permission level of this object. |
isPermissionSet | Checks if this object contains an override for the specified permission, by fully qualified name. |
isPermissionSet | Checks if this object contains an override for the specified Permission. |
hasPermission | 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. |
hasPermission | 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. |
addAttachment | Adds a new PermissionAttachment with a single permission by name and value. |
addAttachment | Adds a new empty PermissionAttachment to this object. |
removeAttachment | Removes the given PermissionAttachment from this object. |
recalculatePermissions | Recalculates the permissions for this object, if the attachments have changed values. This should very rarely need to be called from a plugin. |
getEffectivePermissions | Gets a set containing all the permissions currently in effect by this object. |
asConsole | Gets a CommandSender as ConsoleCommandSender. |
asBlock | Gets a CommandSender as BlockCommandSender. |
asActor | Gets a CommandSender as Actor. |
asPlayer | Gets a CommandSender as Player. |
getServer | Returns the server instance that this command is running on. |
getName | Gets the name of this command sender. |
typeCallback
std::function<void(const Message&)> CallbackmethCommandSenderWrapperexplicit
CommandSenderWrapper(CommandSender& sender, Callback on_message = {}, Callback on_error = {})methsendMessagevirtualconstoverride
void sendMessage(const Message& message) const overrideSends this sender a message.
methsendErrorMessagevirtualconstoverride
void sendErrorMessage(const Message& message) const overrideSends this sender a error message.
Parameters
| Name | Type | Description |
|---|---|---|
message | const Message& | Error message to be displayed |
methgetPermissionLevelvirtualconstoverride
PermissionLevel getPermissionLevel() const overrideGets the permission level of this object.
Returns
| Type | Description |
|---|---|
PermissionLevel | The permission level |
methisPermissionSetvirtualconstoverride
bool isPermissionSet(std::string name) const overrideChecks if this object contains an override for the specified permission, by fully qualified name.
Parameters
| Name | Type | Description |
|---|---|---|
name | std::string | Name of the permission |
Returns
| Type | Description |
|---|---|
bool | true if the permission is set, otherwise false |
methisPermissionSetvirtualconstoverride
bool isPermissionSet(const Permission& perm) const overrideChecks if this object contains an override for the specified Permission.
Parameters
| Name | Type | Description |
|---|---|---|
perm | const Permission& | Permission to check |
Returns
| Type | Description |
|---|---|
bool | true if the permission is set, otherwise false |
methhasPermissionvirtualconstoverride
bool hasPermission(std::string name) const overrideGets 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
| Name | Type | Description |
|---|---|---|
name | std::string | Name of the permission |
Returns
| Type | Description |
|---|---|
bool | Value of the permission |
methhasPermissionvirtualconstoverride
bool hasPermission(const Permission& perm) const overrideGets 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
| Name | Type | Description |
|---|---|---|
perm | const Permission& | Permission to get |
Returns
| Type | Description |
|---|---|
bool | Value of the permission |
methaddAttachmentvirtualoverride
PermissionAttachment* addAttachment(Plugin& plugin, const std::string& name, bool value) overrideAdds a new PermissionAttachment with a single permission by name and value.
Parameters
| Name | Type | Description |
|---|---|---|
plugin | Plugin& | Plugin responsible for this attachment, may not be null or disabled |
name | const std::string& | Name of the permission to attach |
value | bool | Value of the permission |
Returns
| Type | Description |
|---|---|
PermissionAttachment* | The PermissionAttachment that was just created |
methaddAttachmentvirtualoverride
PermissionAttachment* addAttachment(Plugin& plugin) overrideAdds a new empty PermissionAttachment to this object.
Parameters
Returns
| Type | Description |
|---|---|
PermissionAttachment* | The PermissionAttachment that was just created |
methremoveAttachmentvirtualoverride
bool removeAttachment(PermissionAttachment& attachment) overrideRemoves the given PermissionAttachment from this object.
Parameters
| Name | Type | Description |
|---|---|---|
attachment | PermissionAttachment& | Attachment to remove |
Returns
| Type | Description |
|---|---|
bool | true if the specified attachment was removed successfully, false when it isn't part of this object |
methrecalculatePermissionsvirtualoverride
void recalculatePermissions() overrideRecalculates 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 overrideGets a set containing all the permissions currently in effect by this object.
Returns
| Type | Description |
|---|---|
std::unordered_set<PermissionAttachmentInfo*> | Set of currently effective permissions |
methasConsolevirtualconstoverride
ConsoleCommandSender* asConsole() const overrideGets a CommandSender as ConsoleCommandSender.
Returns
| Type | Description |
|---|---|
ConsoleCommandSender* | CommandSender, nullptr if not a ConsoleCommandSender |
methasBlockvirtualconstoverride
BlockCommandSender* asBlock() const overrideGets a CommandSender as BlockCommandSender.
Returns
| Type | Description |
|---|---|
BlockCommandSender* | CommandSender, nullptr if not a BlockCommandSender |
methasActorvirtualconstoverride
Actor* asActor() const overrideGets a CommandSender as Actor.
methasPlayervirtualconstoverride
Player* asPlayer() const overrideGets a CommandSender as Player.
methgetServervirtualconstoverride
Server& getServer() const overrideReturns the server instance that this command is running on.
methgetNamevirtualconstoverride
std::string getName() const overrideGets the name of this command sender.
Returns
| Type | Description |
|---|---|
std::string | Name 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
methexecutevirtualconstoverride
bool execute(CommandSender& sender, const std::vector<std::string>& args) const overrideExecutes the command, returning its success
Parameters
| Name | Type | Description |
|---|---|---|
sender | CommandSender& | Source of the command |
args | const std::vector<std::string>& | Arguments passed to the command |
Returns
| Type | Description |
|---|---|
bool | true 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
| Name | Type | Description |
|---|---|---|
executor | std::shared_ptr<CommandExecutor> | New executor to run |
methgetExecutorvirtualconst
CommandExecutor& getExecutor() constGets the CommandExecutor associated with this command
Returns
| Type | Description |
|---|---|
CommandExecutor& | CommandExecutor object linked to this command |
methgetPluginconst
Plugin& getPlugin() constGets the owner of this PluginCommand
methasPluginCommandvirtualconstoverride
PluginCommand* asPluginCommand() const override