Class ConfigurableCommand
A command that is able to be modified via configuration
To set up hierarchies of commands, simply start with your root command, then create your sub commands, adding each to the root.
Example:
// Root commands
ConfigurableCommand root = new ConfigurableCommand(this, "root", SenderType.ANYONE);
ConfigurableCommand group;
// Add sub commands
root.addSubCommands(
new ConfigurableCommand(this, "list", SenderType.ANYONE, new ListFunction(), "Lists available things", "", "perm.list"),
group = new ConfigurableCommand(this, "group", SenderType.ANYONE, "Handles group functions")
);
group.addSubCommands(
new ConfigurableCommand(this, "add", SenderType.ANYONE, new AddFunction(), "Adds a member to a group", "<player>", "perm.add"),
new ConfigurableCommand(this, "remove", SenderType.ANYONE, new RemoveFunction(), "Removes a member from a group", "<player>", "perm.remove")
);
// Register everything
CommandManager.registerCommand(root);
-
Field Summary
Fields inherited from class org.bukkit.command.Command
timings, usageMessage -
Constructor Summary
ConstructorsConstructorDescriptionConfigurableCommand(org.bukkit.plugin.java.JavaPlugin plugin, String key, SenderType senderType) Creates a new command that can only hold other commands and displays a command usage for sub commands when executed.ConfigurableCommand(org.bukkit.plugin.java.JavaPlugin plugin, String key, SenderType senderType, String description) Creates a new command that can only hold other commands and displays a command usage for sub commands when executed.ConfigurableCommand(org.bukkit.plugin.java.JavaPlugin plugin, String key, SenderType senderType, IFunction function) Creates a new command that performs its own action when run but cannot have sub commands.ConfigurableCommand(org.bukkit.plugin.java.JavaPlugin plugin, String key, SenderType senderType, IFunction function, String description) Creates a new command that performs its own action when run but cannot have sub commands.ConfigurableCommand(org.bukkit.plugin.java.JavaPlugin plugin, String key, SenderType senderType, IFunction function, String description, String args) Creates a new command that performs its own action when run but cannot have sub commands.ConfigurableCommand(org.bukkit.plugin.java.JavaPlugin plugin, String key, SenderType senderType, IFunction function, String description, String args, String permission) Creates a new command that performs its own action when run but cannot have sub commands. -
Method Summary
Modifier and TypeMethodDescriptionvoidaddSubCommand(ConfigurableCommand command) Adds a sub command to this commandvoidaddSubCommands(ConfigurableCommand... commands) Adds multiple sub commands to this commandbooleancanUseCommand(org.bukkit.command.CommandSender sender) Checks whether or not the sender can use this commandvoiddisplayHelp(org.bukkit.command.CommandSender sender) Displays the help for this commandvoiddisplayHelp(org.bukkit.command.CommandSender sender, int page) Displays the help for this command using the given pagevoiddisplayHelp(org.bukkit.command.CommandSender sender, String[] args) Displays the help for this command according to the argumentsbooleanExecutes the command using the provided argumentsbooleanBukkit executiton of the command.getArgs()Retrieves the described arguments for this commandRetrieves the description for this commandgetMessage(String key, String defaultMessage, CustomFilter... filters) Retrieves a message for the command, using the default and adding it to the configuration if not already set.getName()Retrieves the name of the commandRetrieves the parent of the command.Retrieves the permission required to use this commandgetPlayerTabCompletions(org.bukkit.command.CommandSender sender, String arg) org.bukkit.plugin.java.JavaPluginRetrieves the plugin that owns this commandRetrieves the type of sender required to use this commandgetSubCommand(String name) Retrieves a sub command by namegetTabCompletions(Collection<String> options, String[] args) getUsableCommands(org.bukkit.command.CommandSender sender) Retrieves the list of commands that are usable by the senderbooleanChecks whether or not this command has described argumentsbooleanChecks whether or not this command has a descriptionbooleanChecks whether or not the command has a parent command.booleanhasSubCommand(String name) Checks whether or not this command has the given sub commandbooleanChecks whether or not this command is a container command.booleanChecks whether or not this command is a functional command.booleanChecks whether or not this is a root commandvoidMarks the command as registered so that it cannot be added to other commands.booleanChecks whether or not this command requires a permissionvoidsendMessage(org.bukkit.command.CommandSender sender, String key, String defaultMessage, boolean silent, CustomFilter... filters) Sends a command message to the sender if the message is not an empty string.voidsendMessage(org.bukkit.command.CommandSender sender, String key, String defaultMessage, CustomFilter... filters) tabComplete(org.bukkit.command.CommandSender sender, String alias, String[] args) toString()Returns a string of the command nameMethods inherited from class org.bukkit.command.Command
broadcastCommandMessage, broadcastCommandMessage, getAliases, getLabel, getPermissionMessage, getUsage, isRegistered, register, setAliases, setDescription, setLabel, setName, setPermission, setPermissionMessage, setUsage, tabComplete, testPermission, testPermissionSilent, unregister
-
Constructor Details
-
ConfigurableCommand
public ConfigurableCommand(org.bukkit.plugin.java.JavaPlugin plugin, String key, SenderType senderType) Creates a new command that can only hold other commands and displays a command usage for sub commands when executed.
The key is used to tell commands apart and is also the default name of the command.
The command created by this has no default description. It must be set via the configuration.
- Parameters:
plugin- plugin referencekey- command keysenderType- type of sender needed for the command
-
ConfigurableCommand
public ConfigurableCommand(org.bukkit.plugin.java.JavaPlugin plugin, String key, SenderType senderType, String description) Creates a new command that can only hold other commands and displays a command usage for sub commands when executed.
The key is used to tell commands apart and is also the default name of the command.
- Parameters:
plugin- plugin referencekey- command keysenderType- type of sender needed for the commanddescription- default description
-
ConfigurableCommand
public ConfigurableCommand(org.bukkit.plugin.java.JavaPlugin plugin, String key, SenderType senderType, IFunction function) Creates a new command that performs its own action when run but cannot have sub commands.
The key is used to tell commands apart and is also the default name of the command.
The command created by this has no default description, arguments, or required permission. They must be set via the configuration.
- Parameters:
plugin- plugin referencekey- command keysenderType- type of sender needed for the commandfunction- command executor
-
ConfigurableCommand
public ConfigurableCommand(org.bukkit.plugin.java.JavaPlugin plugin, String key, SenderType senderType, IFunction function, String description) Creates a new command that performs its own action when run but cannot have sub commands.
The key is used to tell commands apart and is also the default name of the command.
The command created by this has no default arguments or required permission. They must be set via the configuration.
- Parameters:
plugin- plugin referencekey- command keysenderType- type of sender needed for the commandfunction- command executordescription- default description
-
ConfigurableCommand
public ConfigurableCommand(org.bukkit.plugin.java.JavaPlugin plugin, String key, SenderType senderType, IFunction function, String description, String args) Creates a new command that performs its own action when run but cannot have sub commands.
The key is used to tell commands apart and is also the default name of the command.
The command created by this has no default required permission. It must be set via the configuration.
- Parameters:
plugin- plugin referencekey- command keysenderType- type of sender needed for the commandfunction- command executordescription- default descriptionargs- default arguments
-
ConfigurableCommand
public ConfigurableCommand(org.bukkit.plugin.java.JavaPlugin plugin, String key, SenderType senderType, IFunction function, String description, String args, String permission) Creates a new command that performs its own action when run but cannot have sub commands.
The key is used to tell commands apart and is also the default name of the command.
- Parameters:
plugin- plugin referencekey- command keysenderType- type of sender needed for the commandfunction- command executordescription- default descriptionargs- default argumentspermission- default required permission
-
-
Method Details
-
getTabCompletions
@Contract("null, _ -> null") public static List<String> getTabCompletions(@Nullable Collection<String> options, @NotNull String[] args) -
getPlayerTabCompletions
-
hasDescription
public boolean hasDescription()Checks whether or not this command has a description
- Returns:
- true if the command has a description, false otherwise
-
hasArguments
public boolean hasArguments()Checks whether or not this command has described arguments
- Returns:
- true if it has described arguments, false otherwise
-
requiresPermission
public boolean requiresPermission()Checks whether or not this command requires a permission
- Returns:
- true if requires a permission, false otherwise
-
hasSubCommand
Checks whether or not this command has the given sub command
This is not case-sensitive
- Parameters:
name- sub command name- Returns:
- true if the command has the sub command, false otherwise
-
canUseCommand
public boolean canUseCommand(org.bukkit.command.CommandSender sender) Checks whether or not the sender can use this command
- Parameters:
sender- sender of the command- Returns:
- true if can use, false otherwise
-
isRootCommand
public boolean isRootCommand()Checks whether or not this is a root command
A "root" command would be a command with no parent command
- Returns:
- true if root command, false otherwise
-
getName
Retrieves the name of the command
- Overrides:
getNamein classorg.bukkit.command.Command- Returns:
- command name
-
getPlugin
public org.bukkit.plugin.java.JavaPlugin getPlugin()Retrieves the plugin that owns this command
- Returns:
- owning plugin
-
getDescription
Retrieves the description for this command
If this doesn't have a description, this returns null
- Overrides:
getDescriptionin classorg.bukkit.command.Command- Returns:
- required permission or null if none
-
getArgs
Retrieves the described arguments for this command
If this doesn't have any arguments described, this returns null
- Returns:
- required permission or null if none
-
getPermission
Retrieves the permission required to use this command
If this doesn't require a permission, this returns null
- Overrides:
getPermissionin classorg.bukkit.command.Command- Returns:
- required permission or null if none
-
getSenderType
Retrieves the type of sender required to use this command
- Returns:
- required sender type
-
getUsableCommands
Retrieves the list of commands that are usable by the sender
- Parameters:
sender- sender of the command- Returns:
- list of usable commands
-
getSubCommand
Retrieves a sub command by name
If there are no sub commands with the given name, this will return null instead
- Parameters:
name- sub command name- Returns:
- sub command or null if not found
-
hasParent
public boolean hasParent()Checks whether or not the command has a parent command.
This command will have a parent if it was added as a sub command to another command
- Returns:
- true if has a parent, false otherwise
-
getParent
Retrieves the parent of the command.
If this does not have a parent, this will return null.
- Returns:
- parent of the command
-
isContainer
public boolean isContainer()Checks whether or not this command is a container command.
A container command is one that doesn't have a function of its own but contains other commands that have functions.
- Returns:
- true if a container command, false otherwise
-
isFunction
public boolean isFunction()Checks whether or not this command is a functional command.
A functional command performs a task when executed and cannot hold other commands in it.
- Returns:
- true if functional command, false otherwise
-
markAsRegistered
public void markAsRegistered()Marks the command as registered so that it cannot be added to other commands.
This is called on commands as they are registered through the CommandManager class. You do not need to use this method.
-
addSubCommand
Adds a sub command to this command
The sub command cannot be a registered command
You cannot register a command if this command is attached to a function
- Parameters:
command- sub command to add- Throws:
IllegalStateException- when unable to add sub commandsIllegalArgumentException- when the command is registered
-
addSubCommands
Adds multiple sub commands to this command
The sub commands cannot be a registered command
You cannot register a command if this command is attached to a function
- Parameters:
commands- sub commands to add- Throws:
IllegalStateException- when unable to add sub commandsIllegalArgumentException- when the command is registered
-
execute
public boolean execute(@NotNull org.bukkit.command.CommandSender sender, @NotNull String label, String[] args) Bukkit executiton of the command.
Use execute(CommandSender, String[]) instead.
- Specified by:
executein classorg.bukkit.command.Command- Parameters:
sender- sender of the commandlabel- label of the commandargs- arguments provided by the sender- Returns:
- true
-
execute
Executes the command using the provided arguments
Root commands will pass the arguments onto sub commands or display the command usage if the args don't match any sub commands.
- Parameters:
sender- sender of the commandargs- arguments provided by the sender
-
tabComplete
@NotNull public List<String> tabComplete(@NotNull org.bukkit.command.CommandSender sender, @NotNull String alias, @NotNull String[] args) throws IllegalArgumentException - Overrides:
tabCompletein classorg.bukkit.command.Command- Throws:
IllegalArgumentException
-
displayHelp
public void displayHelp(org.bukkit.command.CommandSender sender) Displays the help for this command
This displays the first page of the usage
If this is a function command, this will display the usage for this command including the arguments.
If this is a command that contains others, this will display the list of sub commands and their descriptions.
- Parameters:
sender- sender of the command
-
displayHelp
Displays the help for this command according to the arguments
The displayed page is determined by the provided arguments
If this is a function command, this will display the usage for this command including the arguments.
If this is a command that contains others, this will display the list of sub commands and their descriptions.
- Parameters:
sender- sender of the commandargs- arguments provided by the sender
-
displayHelp
public void displayHelp(org.bukkit.command.CommandSender sender, int page) Displays the help for this command using the given page
If the page is less than one, the first page will be displayed
If the page is greater than the number of pages, the last page will be displayed
If this is a function command, this will display the usage for this command including the arguments.
If this is a command that contains others, this will display the list of sub commands and their descriptions.
- Parameters:
sender- sender of the commandpage- page number
-
getMessage
Retrieves a message for the command, using the default and adding it to the configuration if not already set.- Parameters:
key- the message keydefaultMessage- the message to use if not setfilters- filters to use on the message- Returns:
- the message from the config or default message if not set
-
sendMessage
public void sendMessage(org.bukkit.command.CommandSender sender, String key, String defaultMessage, boolean silent, CustomFilter... filters) Sends a command message to the sender if the message is not an empty string.- Parameters:
sender- sender of the commandkey- the message keydefaultMessage- the message to use if not setsilent- indicates whether the message should be sent or notfilters- filters to use on the message
-
sendMessage
public void sendMessage(org.bukkit.command.CommandSender sender, String key, String defaultMessage, CustomFilter... filters) -
toString
Returns a string of the command name
If this is a sub command, this returns the parent's name as well as the name of this command.
For example, if this is the command "add" and is the sub command of "group", this will return "group add"
- Overrides:
toStringin classorg.bukkit.command.Command- Returns:
- command path
-