Package net.minestom.server.command
Class CommandManager
java.lang.Object
net.minestom.server.command.CommandManager
Manager used to register
commands
.
It is also possible to simulate a command using execute(CommandSender, String)
.
-
Field Summary
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionboolean
commandExists
(@NotNull String commandName) Gets if a command with the namecommandName
already exists or not.@NotNull DeclareCommandsPacket
createDeclareCommandsPacket
(@NotNull Player player) Gets theDeclareCommandsPacket
for a specific player.@NotNull CommandResult
execute
(@NotNull CommandSender sender, @NotNull String command) Executes a command for aCommandSender
.@NotNull CommandResult
executeServerCommand
(@NotNull String command) Executes the command using aServerSender
.@Nullable Command
getCommand
(@NotNull String commandName) Gets theCommand
registered byregister(Command)
.@NotNull ConsoleSender
Gets theConsoleSender
(which is used as aCommandSender
).@NotNull CommandDispatcher
@Nullable CommandCallback
Gets the callback executed once an unknown command is run.parseCommand
(@NotNull CommandSender sender, String input) Parses the command based on the registered commandsvoid
Registers aCommand
.void
setUnknownCommandCallback
(@Nullable CommandCallback unknownCommandCallback) Sets the callback executed once an unknown command is run.void
unregister
(@NotNull Command command) Removes a command from the currently registered commands.
-
Field Details
-
COMMAND_PREFIX
- See Also:
-
-
Constructor Details
-
CommandManager
public CommandManager()
-
-
Method Details
-
register
Registers aCommand
.- Parameters:
command
- the command to register- Throws:
IllegalStateException
- if a command with the same name already exists
-
unregister
Removes a command from the currently registered commands. Does nothing if the command was not registered before- Parameters:
command
- the command to remove
-
getCommand
Gets theCommand
registered byregister(Command)
.- Parameters:
commandName
- the command name- Returns:
- the command associated with the name, null if not any
-
commandExists
Gets if a command with the namecommandName
already exists or not.- Parameters:
commandName
- the command name to check- Returns:
- true if the command does exist
-
execute
@NotNull public @NotNull CommandResult execute(@NotNull @NotNull CommandSender sender, @NotNull @NotNull String command) Executes a command for aCommandSender
.- Parameters:
sender
- the sender of the commandcommand
- the raw command string (without the command prefix)- Returns:
- the execution result
-
executeServerCommand
Executes the command using aServerSender
. This can be used to run a silent command (nothing is printed to console).- See Also:
-
getDispatcher
-
getUnknownCommandCallback
Gets the callback executed once an unknown command is run.- Returns:
- the unknown command callback, null if not any
-
setUnknownCommandCallback
Sets the callback executed once an unknown command is run.- Parameters:
unknownCommandCallback
- the new unknown command callback, setting it to null mean that nothing will be executed
-
getConsoleSender
Gets theConsoleSender
(which is used as aCommandSender
).- Returns:
- the
ConsoleSender
-
createDeclareCommandsPacket
@NotNull public @NotNull DeclareCommandsPacket createDeclareCommandsPacket(@NotNull @NotNull Player player) Gets theDeclareCommandsPacket
for a specific player.Can be used to update a player auto-completion list.
- Parameters:
player
- the player to get the commands packet- Returns:
- the
DeclareCommandsPacket
forplayer
-
getCommands
-
parseCommand
Parses the command based on the registered commands- Parameters:
input
- commands string without prefix- Returns:
- the parsing result
-