Package net.minestom.server.command
Class CommandManager
java.lang.Object
net.minestom.server.command.CommandManager
public final class CommandManager
extends java.lang.Object
Manager used to register
Command
and CommandProcessor
.
It is also possible to simulate a command using execute(CommandSender, String)
.
-
Field Summary
Fields Modifier and Type Field Description static java.lang.String
COMMAND_PREFIX
-
Constructor Summary
Constructors Constructor Description CommandManager()
-
Method Summary
Modifier and Type Method Description boolean
commandExists(java.lang.String commandName)
Gets if a command with the namecommandName
already exists or name.DeclareCommandsPacket
createDeclareCommandsPacket(Player player)
Gets theDeclareCommandsPacket
for a specific player.boolean
execute(CommandSender sender, java.lang.String command)
Executes a command for aConsoleSender
.Command
getCommand(java.lang.String commandName)
Gets theCommand
registered byregister(Command)
.CommandProcessor
getCommandProcessor(java.lang.String commandName)
Gets theCommandProcessor
registered byregister(CommandProcessor)
.ConsoleSender
getConsoleSender()
Gets theConsoleSender
(which is used as aCommandSender
).CommandCallback
getUnknownCommandCallback()
Gets the callback executed once an unknown command is run.void
register(Command command)
Registers aCommand
.void
register(CommandProcessor commandProcessor)
Registers aCommandProcessor
.void
setUnknownCommandCallback(CommandCallback unknownCommandCallback)
Sets the callback executed once an unknown command is run.void
stopConsoleThread()
Stops the console responsible for the console commands processing.
-
Field Details
-
COMMAND_PREFIX
public static final java.lang.String COMMAND_PREFIX- See Also:
- Constant Field Values
-
-
Constructor Details
-
CommandManager
public CommandManager()
-
-
Method Details
-
stopConsoleThread
public void stopConsoleThread()Stops the console responsible for the console commands processing.WARNING: it cannot be re-run later.
-
register
Registers aCommand
.- Parameters:
command
- the command to register- Throws:
java.lang.IllegalStateException
- if a command with the same name already exists
-
getCommand
Gets theCommand
registered byregister(Command)
.- Parameters:
commandName
- the command name- Returns:
- the command associated with the name, null if not any
-
register
Registers aCommandProcessor
.- Parameters:
commandProcessor
- the command to register- Throws:
java.lang.IllegalStateException
- if a command with the same name already exists
-
getCommandProcessor
Gets theCommandProcessor
registered byregister(CommandProcessor)
.- Parameters:
commandName
- the command name- Returns:
- the command associated with the name, null if not any
-
commandExists
public boolean commandExists(@NotNull java.lang.String commandName)Gets if a command with the namecommandName
already exists or name.- Parameters:
commandName
- the command name to check- Returns:
- true if the command does exist
-
execute
Executes a command for aConsoleSender
.- Parameters:
sender
- the sender of the commandcommand
- the raw command string (without the command prefix)- Returns:
- true if the command hadn't been cancelled and has been successful
-
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 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
-