Class CommandAPI

java.lang.Object
dev.jorel.commandapi.CommandAPI

public class CommandAPI extends Object
Class to register commands with the 1.13 command UI
  • Method Details

    • isLoaded

      public static boolean isLoaded()
      Returns whether the CommandAPI is currently loaded. This should be true when onLoad(CommandAPIConfig) is called. If the CommandAPI is loaded, commands are available to register.
      Returns:
      whether the CommandAPI has been loaded properly
    • stopCommandRegistration

      public static void stopCommandRegistration()
      Flag that commands should no longer be registered. After running this, canRegister() will return false.
    • canRegister

      public static boolean canRegister()
      Determines whether command registration is permitted via the CommandAPI
      Returns:
      true if commands can still be registered
    • getConfiguration

      public static InternalConfig getConfiguration()
      Returns the internal configuration used to manage the CommandAPI
      Returns:
      the internal configuration used to manage the CommandAPI
    • setLogger

      public static void setLogger(CommandAPILogger logger)
    • getLogger

      public static CommandAPILogger getLogger()
      Returns:
      the CommandAPI's logger
    • onLoad

      public static void onLoad(CommandAPIConfig<?> config)
      Initializes the CommandAPI for loading. This should be placed at the start of your onLoad() method.
      Parameters:
      config - the configuration to use for the CommandAPI. This should be a CommandAPIConfig subclass corresponding to the active platform.
    • onEnable

      public static void onEnable()
      Enables the CommandAPI. This should be placed at the start of your onEnable() method.
    • onDisable

      public static void onDisable()
      Unloads the CommandAPI.
    • logInfo

      public static void logInfo(String message)
      Logs a message to the console using Logger.info() if the configuration has verbose logging enabled
      Parameters:
      message - the message to log to the console
    • logNormal

      public static void logNormal(String message)
      Logs a message from the CommandAPI. If silent logs are enabled, this message is not logged.
      Parameters:
      message - the message to log
    • logWarning

      public static void logWarning(String message)
      Logs a warning from the CommandAPI. If silent logs are enabled, this warning is not logged.
      Parameters:
      message - the message to log as a warning
    • logError

      public static void logError(String message)
      Logs an error from the CommandAPI. This always gets logged, even if silent logs are enabled.
      Parameters:
      message - the message to log as an error
    • reloadDatapacks

      public static void reloadDatapacks()
      Reloads all the datapacks that are on the server. This should be used if you change a datapack and want to reload a server. Execute this method after running /minecraft:reload, NOT before.
    • updateRequirements

      public static <CommandSender, Player extends CommandSender> void updateRequirements(Player player)
      Updates the requirements required for a given player to execute a command.
      Parameters:
      player - the player whose requirements should be updated
    • failWithString

      public static WrapperCommandSyntaxException failWithString(String message)
      Forces a command to return a success value of 0
      Parameters:
      message - Description of the error message
      Returns:
      a WrapperCommandSyntaxException that wraps Brigadier's CommandSyntaxException
    • failWithMessage

      public static WrapperCommandSyntaxException failWithMessage(com.mojang.brigadier.Message message)
      Forces a command to return a success value of 0
      Parameters:
      message - Description of the error message, formatted as a brigadier message
      Returns:
      a WrapperCommandSyntaxException that wraps Brigadier's CommandSyntaxException
    • unregister

      public static void unregister(String command)
      Unregisters a command
      Parameters:
      command - the name of the command to unregister
    • unregister

      public static void unregister(String command, boolean force)
      Unregisters a command, by force (removes all instances of that command)
      Parameters:
      command - the name of the command to unregister
      force - if true, attempt to unregister all instances of the command across all plugins as well as minecraft, bukkit and spigot
    • registerCommand

      public static void registerCommand(Class<?> commandClass)
      Registers a command. Used with the CommandAPI's Annotation API.
      Parameters:
      commandClass - the class to register
    • getRegisteredCommands

      public static List<RegisteredCommand> getRegisteredCommands()
      Returns:
      A list of all RegisteredCommands that have been registered by the CommandAPI so far. The returned list is immutable.