Class CommandManager

java.lang.Object
studio.magemonkey.codex.mccore.commands.CommandManager

public class CommandManager extends Object

The handler for configurable commands

Only configurable commands registered using this class will function.

It is recommended that you use "ConfigurableCommand" instead as it provides a more flexible structure for your commands and makes them automatically configurable as well.

  • Constructor Details

    • CommandManager

      public CommandManager()
  • Method Details

    • isInvalidRegistration

      public static boolean isInvalidRegistration()

      Checks whether or not the CommandManager was able to register commands successfully with Bukkit. If it is invalid, then commands will be handled by Codex instead of the default command system.

      Returns:
      true if commands could not be registered, false otherwise
    • getDescriptionReplacement

      public static String getDescriptionReplacement()

      Retrieves the replacement for descriptions when they are not set

      This is used by the API for the command usage. You generally will not need to use this.

      Returns:
      description replacement
    • registerCommand

      public static void registerCommand(ConfigurableCommand command)

      Registers a new ConfigurableCommand for the plugin

      Sub commands do not need to be registered as they are linked to the root commands.

      Parameters:
      command - command to register
      Throws:
      IllegalArgumentException - when trying to register a sub command or when the command's name is already taken
    • unregisterCommand

      public static void unregisterCommand(ConfigurableCommand command)

      Unregisters a command

      If the command wasn't registered, this does nothing

      Commands are automatically unregistered when your plugin is disabled, so you generally do not need to manually unregister your commands. This would be more for if you want to unregister a command during run time such as if a command was disabled via a command

      Parameters:
      command - command to unregister
    • unregisterCommands

      public static void unregisterCommands(org.bukkit.plugin.Plugin plugin)

      Unregisters all of the commands registered by a plugin

      If the plugin didn't have any registered commands, this does nothing

      Commands are automatically unregistered when your plugin is disabled, so you generally do not need to manually unregister your commands. This would be more for if you want to unregister commands during run time such as if the commands were disabled via a command

      Parameters:
      plugin - plugin to unregister for
    • unregisterAll

      public static void unregisterAll()

      Unregisters all commands for all plugins

      If no commands were registered, this does nothing

      You shouldn't use this method as it's meant for Codex to clear the data when it's disabled.

    • getCommand

      public static ConfigurableCommand getCommand(String name)

      Retrieves a registered command by name

      If there is no registered command with the name, this will return null instead.

      Parameters:
      name - command name
      Returns:
      registered command or null if not found
    • getConfig

      public static CommentedConfig getConfig(org.bukkit.plugin.java.JavaPlugin plugin)

      Retrieves the command configuration for the plugin

      If a configuration for the plugin hasn't yet been set up, this will create one.

      This is primarily for the commands saving/loading their own data and generally doesn't need to be used.

      Parameters:
      plugin - plugin to get the config for
      Returns:
      command configuration
    • displayUsage

      public static void displayUsage(ConfigurableCommand c, org.bukkit.command.CommandSender sender)

      Displays the usage help for the command, showing only the commands that the sender can use.

      The usage display adjusts to the sender, having different spacing for players and the console.

      When on 1.7.9+, players also can see buttons to navigate through the help menu as long as it is included in the format.

      Parameters:
      c - command to show usage for
      sender - sender of the command
    • displayUsage

      public static void displayUsage(ConfigurableCommand c, org.bukkit.command.CommandSender sender, int page)

      Displays the usage help for the command, showing only the commands that the sender can use.

      The usage display adjusts to the sender, having different spacing for players and the console.

      When on 1.7.9+, players also can see buttons to navigate through the help menu as long as it is included in the format.

      Parameters:
      c - command to show usage for
      sender - sender of the command
      page - page to display
    • trimArgs

      public static String[] trimArgs(String[] args)

      Trims the first element off of an args array

      This is used by the API to handle command execution. You generally will not need to use this.

      Parameters:
      args - initial args
      Returns:
      trimmed args
    • loadOptions

      public static void loadOptions(DataSection config)

      Loads options for displaying command usages from the configuration

      This is called by Codex automatically and doesn't need to be called by you. If you want to override MCCore's default configuration, you could use this method to apply a different one as long as it uses the same format.

      Parameters:
      config - configuration to load from