Interface CommandSourceStack
While the general use case for CommandSourceStack is similar to that of CommandSender, it provides access to
important additional context for the command execution.
Specifically, commands such as /execute may alter the location or executor of the source stack before
passing it to another command.
The CommandSender returned by getSender() may be a "no-op"
instance of CommandSender in cases where the server either doesn't
exist yet, or no specific sender is available. Methods on such a CommandSender
will either have no effect or throw an UnsupportedOperationException.
-
Method Summary
Modifier and TypeMethodDescriptionReturns theEntitythat is executing this command.Gets the entity that executes this command.Gets the location that this command is being executed at.Returns thePlayerthat is executing this command.Gets the command sender that executed this command.voidsendFailure(ComponentLike message) Sends a system message indicating a failed command execution to thegetSender().voidsendReply(ComponentLike message) Sends a system message to thegetExecutor()if it is aPlayer, otherwise sends a system message to thegetSender().default voidsendRichFailure(String message, TagResolver... resolvers) Sends a system message with the MiniMessage format indicating a failed command execution to thegetSender().default voidsendRichReply(String message, TagResolver... resolvers) Sends a system message with the MiniMessage format to thegetExecutor()if it is aPlayer, otherwise sends it to thegetSender().default voidsendRichSuccess(String message, TagResolver... resolvers) Sends a system message with the MiniMessage format to thegetSender(), admins, and console indicating successful command execution according to vanilla semantics.default voidsendSuccess(ComponentLike message) Sends a system message to thegetSender(), admins, and console indicating successful command execution according to vanilla semantics.voidsendSuccess(ComponentLike message, boolean allowInformingAdmins) Sends a system message to thegetSender(), admins, and console indicating successful command execution according to vanilla semantics.withExecutor(Entity executor) Creates a new CommandSourceStack object with a different executor for redirecting commands to other nodes.withLocation(Location location) Creates a new CommandSourceStack object with a different location for redirecting commands to other nodes.
-
Method Details
-
getLocation
Location getLocation()Gets the location that this command is being executed at.- Returns:
- a cloned location instance.
-
getSender
CommandSender getSender()Gets the command sender that executed this command. The sender of a command source stack is the one that initiated/triggered the execution of a command. It differs togetExecutor()as the executor can be changed by a command, e.g. /execute.- Returns:
- the command sender instance
-
getExecutor
Gets the entity that executes this command. May not always begetSender()as the executor of a command can be changed to a different entity than the one that triggered the command.- Returns:
- entity that executes this command
-
getPlayerOrThrow
Returns thePlayerthat is executing this command. -
getEntityOrThrow
Returns theEntitythat is executing this command. -
withLocation
Creates a new CommandSourceStack object with a different location for redirecting commands to other nodes.- Parameters:
location- The location to create a new CommandSourceStack object with- Returns:
- The newly created CommandSourceStack
- See Also:
-
withExecutor
Creates a new CommandSourceStack object with a different executor for redirecting commands to other nodes.- Parameters:
executor- The executing entity to create a new CommandSourceStack object with- Returns:
- The newly created CommandSourceStack
- See Also:
-
sendReply
Sends a system message to thegetExecutor()if it is aPlayer, otherwise sends a system message to thegetSender().- Parameters:
message- the message to send- Throws:
IllegalArgumentException- if the message is null
-
sendRichReply
Sends a system message with the MiniMessage format to thegetExecutor()if it is aPlayer, otherwise sends it to thegetSender().See MiniMessage docs and MiniMessage Placeholders docs for more information on the format.
This method provides the target of the system message as a
Pointeredto the MiniMessageMiniMessage.deserialize(String, Pointered, TagResolver...)method.- Parameters:
message- the MiniMessage message to sendresolvers- resolvers to use- Throws:
IllegalArgumentException- if the message is null
-
sendSuccess
Sends a system message to thegetSender(), admins, and console indicating successful command execution according to vanilla semantics.This currently includes checking for environments with suppressed output,
GameRules.SEND_COMMAND_FEEDBACK, andGameRules.LOG_ADMIN_COMMANDS.- Parameters:
message- the message to sendallowInformingAdmins- whether admins and console may be informed of this success- Throws:
IllegalArgumentException- if the message is null
-
sendSuccess
Sends a system message to thegetSender(), admins, and console indicating successful command execution according to vanilla semantics. This method informs admins and the console of this success.This currently includes checking for environments with suppressed output,
GameRules.SEND_COMMAND_FEEDBACK, andGameRules.LOG_ADMIN_COMMANDS.- Parameters:
message- the message to send- Throws:
IllegalArgumentException- if the message is null- See Also:
-
sendRichSuccess
Sends a system message with the MiniMessage format to thegetSender(), admins, and console indicating successful command execution according to vanilla semantics. This method informs admins and the console of this success.This currently includes checking for environments with suppressed output,
GameRules.SEND_COMMAND_FEEDBACK, andGameRules.LOG_ADMIN_COMMANDS.See MiniMessage docs and MiniMessage Placeholders docs for more information on the format.
This method provides the
CommandSenderof this command as aPointeredto the MiniMessageMiniMessage.deserialize(String, Pointered, TagResolver...)method.- Parameters:
message- the MiniMessage message to sendresolvers- resolvers to use- Throws:
IllegalArgumentException- if the message is null- See Also:
-
sendFailure
Sends a system message indicating a failed command execution to thegetSender(). Does not apply red styling to the message as vanilla does to allow for custom failure message styling.Respects vanilla semantics for accepting failure output and suppressed output environments.
- Parameters:
message- the message to send- Throws:
IllegalArgumentException- if the message is null
-
sendRichFailure
Sends a system message with the MiniMessage format indicating a failed command execution to thegetSender(). Does not apply red styling to the message as vanilla does to allow for custom failure message styling.Respects vanilla semantics for accepting failure output and suppressed output environments.
See MiniMessage docs and MiniMessage Placeholders docs for more information on the format.
This method provides the
CommandSenderof this command as aPointeredto the MiniMessageMiniMessage.deserialize(String, Pointered, TagResolver...)method.- Parameters:
message- the MiniMessage message to sendresolvers- resolvers to use- Throws:
IllegalArgumentException- if the message is null
-