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
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionbooleancommandExists(String commandName) Gets if a command with the namecommandNamealready exists or not.createDeclareCommandsPacket(Player player) Gets theDeclareCommandsPacketfor a specific player.execute(CommandSender sender, String command) Executes a command for aCommandSender.executeServerCommand(String command) Executes the command using aServerSender.getCommand(String commandName) Gets theCommandregistered byregister(Command).Gets theConsoleSender(which is used as aCommandSender).Gets the callback executed once an unknown command is run.parseCommand(CommandSender sender, String input) Parses the command based on the registered commandsvoidRegisters aCommand.voidRegister multipleCommands.voidsetUnknownCommandCallback(@Nullable CommandCallback unknownCommandCallback) Sets the callback executed once an unknown command is run.voidunregister(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
-
register
Register multipleCommands.- Parameters:
commands- the array of commands- 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
-
commandExists
Gets if a command with the namecommandNamealready exists or not.- Parameters:
commandName- the command name to check- Returns:
- true if the command does exist
-
execute
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
Gets theDeclareCommandsPacketfor a specific player.Can be used to update a player auto-completion list.
- Parameters:
player- the player to get the commands packet- Returns:
- the
DeclareCommandsPacketforplayer
-
getCommands
-
parseCommand
Parses the command based on the registered commands- Parameters:
input- commands string without prefix- Returns:
- the parsing result
-