Class CommandManager
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 Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic voiddisplayUsage(ConfigurableCommand c, org.bukkit.command.CommandSender sender) Displays the usage help for the command, showing only the commands that the sender can use.static voiddisplayUsage(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.static ConfigurableCommandgetCommand(String name) Retrieves a registered command by namestatic CommentedConfiggetConfig(org.bukkit.plugin.java.JavaPlugin plugin) Retrieves the command configuration for the pluginstatic StringRetrieves the replacement for descriptions when they are not setstatic booleanChecks whether or not the CommandManager was able to register commands successfully with Bukkit.static voidloadOptions(DataSection config) Loads options for displaying command usages from the configurationstatic voidregisterCommand(ConfigurableCommand command) Registers a new ConfigurableCommand for the pluginstatic String[]Trims the first element off of an args arraystatic voidUnregisters all commands for all pluginsstatic voidunregisterCommand(ConfigurableCommand command) Unregisters a commandstatic voidunregisterCommands(org.bukkit.plugin.Plugin plugin) Unregisters all of the commands registered by a plugin
-
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
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
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
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
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
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
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 forsender- 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 forsender- sender of the commandpage- page to display
-
trimArgs
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
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
-