Class CommandManager

java.lang.Object
net.minestom.server.command.CommandManager

public final class CommandManager extends Object
Manager used to register commands.

It is also possible to simulate a command using execute(CommandSender, String).

  • Field Details

  • Constructor Details

    • CommandManager

      public CommandManager()
  • Method Details

    • register

      public void register(Command command)
      Registers a Command.
      Parameters:
      command - the command to register
      Throws:
      IllegalStateException - if a command with the same name already exists
    • register

      public void register(Command... commands)
      Register multiple Commands.
      Parameters:
      commands - the array of commands
      Throws:
      IllegalStateException - if a command with the same name already exists
    • unregister

      public void unregister(Command command)
      Removes a command from the currently registered commands. Does nothing if the command was not registered before
      Parameters:
      command - the command to remove
    • getCommand

      @Nullable public @Nullable Command getCommand(String commandName)
      Gets the Command registered by register(Command).
      Parameters:
      commandName - the command name
      Returns:
      the command associated with the name, null if not any
    • commandExists

      public boolean commandExists(String commandName)
      Gets if a command with the name commandName already exists or not.
      Parameters:
      commandName - the command name to check
      Returns:
      true if the command does exist
    • execute

      public CommandResult execute(CommandSender sender, String command)
      Executes a command for a CommandSender.
      Parameters:
      sender - the sender of the command
      command - the raw command string (without the command prefix)
      Returns:
      the execution result
    • executeServerCommand

      public CommandResult executeServerCommand(String command)
      Executes the command using a ServerSender. This can be used to run a silent command (nothing is printed to console).
      See Also:
    • getDispatcher

      public CommandDispatcher getDispatcher()
    • getUnknownCommandCallback

      @Nullable public @Nullable CommandCallback getUnknownCommandCallback()
      Gets the callback executed once an unknown command is run.
      Returns:
      the unknown command callback, null if not any
    • setUnknownCommandCallback

      public void setUnknownCommandCallback(@Nullable @Nullable CommandCallback unknownCommandCallback)
      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

      public ConsoleSender getConsoleSender()
      Gets the ConsoleSender (which is used as a CommandSender).
      Returns:
      the ConsoleSender
    • createDeclareCommandsPacket

      public DeclareCommandsPacket createDeclareCommandsPacket(Player player)
      Gets the DeclareCommandsPacket 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 for player
    • getCommands

      public Set<Command> getCommands()
    • parseCommand

      public CommandParser.Result parseCommand(CommandSender sender, String input)
      Parses the command based on the registered commands
      Parameters:
      input - commands string without prefix
      Returns:
      the parsing result