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 Details

  • Constructor Details

  • Method Details

    • stopConsoleThread

      public void stopConsoleThread()
      Stops the console responsible for the console commands processing.

      WARNING: it cannot be re-run later.

    • register

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

      @Nullable public Command getCommand​(@NotNull java.lang.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
    • register

      public void register​(@NotNull CommandProcessor commandProcessor)
      Registers a CommandProcessor.
      Parameters:
      commandProcessor - the command to register
      Throws:
      java.lang.IllegalStateException - if a command with the same name already exists
    • getCommandProcessor

      @Nullable public CommandProcessor getCommandProcessor​(@NotNull java.lang.String commandName)
      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 name commandName already exists or name.
      Parameters:
      commandName - the command name to check
      Returns:
      true if the command does exist
    • execute

      public boolean execute​(@NotNull CommandSender sender, @NotNull java.lang.String command)
      Executes a command for a ConsoleSender.
      Parameters:
      sender - the sender of the command
      command - the raw command string (without the command prefix)
      Returns:
      true if the command hadn't been cancelled and has been successful
    • getUnknownCommandCallback

      @Nullable public 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 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

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

      @NotNull public DeclareCommandsPacket createDeclareCommandsPacket​(@NotNull 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