Class CyberSuperCommand
java.lang.Object
com.github.cyberryan1.cybercore.spigot.command.settings.CommandSettings
com.github.cyberryan1.cybercore.spigot.command.settings.BaseCommand
com.github.cyberryan1.cybercore.spigot.command.CyberSuperCommand
- All Implemented Interfaces:
org.bukkit.command.CommandExecutor
,org.bukkit.command.TabCompleter
public abstract class CyberSuperCommand
extends BaseCommand
implements org.bukkit.command.CommandExecutor, org.bukkit.command.TabCompleter
Used to easily create a command that can be registered to the server. This command
also has support for subcommands.
-
Constructor Summary
ConstructorsConstructorDescriptionCyberSuperCommand
(String name, String usage) Creates a new CyberSuperCommand with the provided arguments.CyberSuperCommand
(String name, String permission, String usage) Creates a new CyberSuperCommand with the provided arguments.CyberSuperCommand
(String name, String permission, String permissionMsg, String usage) Creates a new CyberSuperCommand with the provided arguments. -
Method Summary
Modifier and TypeMethodDescriptionvoid
addSubCommand
(CyberSubCommand subcommand) Adds aCyberSubCommand
to the commandabstract boolean
execute
(SentCommand command) The execute method is called when the player executes a command.boolean
getSubCommand
(String name) getSubCommandsForSender
(org.bukkit.command.CommandSender sender) final boolean
onCommand
(org.bukkit.command.CommandSender sender, org.bukkit.command.Command command, String label, String[] args) This should be ignored by most developersonTabComplete
(org.bukkit.command.CommandSender sender, org.bukkit.command.Command command, String label, String[] args) This should be ignored by most developersfinal void
register
(boolean includeTabComplete) Required to be executed for the command to work properlyvoid
sendUsage
(org.bukkit.command.CommandSender sender) Sends the usage message of this command along with any subcommands to the sendervoid
setExecuteSubCommands
(boolean executeSubcommands) tabComplete
(SentCommand command) The tabComplete method is called when the player presses tab while typing a command.Methods inherited from class com.github.cyberryan1.cybercore.spigot.command.settings.BaseCommand
getArgIndexes, getArgType, getArgTypes, getMinArgLength, getStringArgOptions, getStringArgOptions, isSendingValidationMsg, isValidatingArgs, sendInvalidDoubleArg, sendInvalidIntegerArg, sendInvalidPlayerArg, sendPermissionMsg, sendPermMsg, setArgType, setMinArgLength, setSendValidationMsg, setStringArgOptions, setValidateArgs, validateArgument
Methods inherited from class com.github.cyberryan1.cybercore.spigot.command.settings.CommandSettings
demandConsole, demandPermission, demandPlayer, getInvalidDoubleMsg, getInvalidIntegerMsg, getInvalidPlayerMsg, getName, getPermission, getPermissionMsg, getUsage, isDemandConsole, isDemandPermission, isDemandPlayer, isTabCompleteEnabled, permissionsAllowed, permsAllowed, runAsync, setDemandConsole, setDemandPermission, setDemandPlayer, setInvalidDoubleMsg, setInvalidIntegerMsg, setInvalidPlayerMsg, setRunAsync, setTabCompleteEnabled
-
Constructor Details
-
CyberSuperCommand
Creates a new CyberSuperCommand with the provided arguments.Note: this is where you should call the
register(boolean)
method.- Parameters:
name
- The name of the commandpermission
- The permission to use the command (null for no permission)permissionMsg
- The message to send to the player if they do not have the permissionusage
- The usage of the command (Note: if anyCyberSubCommand
are added to this command, their usages will also be sent, unless you override thesendUsage(CommandSender)
method)
-
CyberSuperCommand
Creates a new CyberSuperCommand with the provided arguments. The permission message is set to the default permission message provided byCyberCommandUtils.getDefaultPermissionMsg()
.Note: this is where you should call the
register(boolean)
method.- Parameters:
name
- The name of the commandpermission
- The permission to use the command (null for no permission)usage
- The usage of the command (Note: if anyCyberSubCommand
are added to this command, their usages will also be sent, unless you override thesendUsage(CommandSender)
method)
-
CyberSuperCommand
Creates a new CyberSuperCommand with the provided arguments. The permission message is set to the default permission message provided byCyberCommandUtils.getDefaultPermissionMsg()
. The permission is assumed to be null, meaning that no permission is needed to execute this command.Note: this is where you should call the
register(boolean)
method.- Parameters:
name
- The name of the commandusage
- The usage of the command (Note: if anyCyberSubCommand
are added to this command, their usages will also be sent, unless you override thesendUsage(CommandSender)
method)
-
-
Method Details
-
onTabComplete
public final List<String> onTabComplete(org.bukkit.command.CommandSender sender, org.bukkit.command.Command command, String label, String[] args) This should be ignored by most developers- Specified by:
onTabComplete
in interfaceorg.bukkit.command.TabCompleter
-
tabComplete
The tabComplete method is called when the player presses tab while typing a command.Returning an empty list will do the following:
-
If this command has any subcommands (added by the
addSubCommand(CyberSubCommand)
method):-
If the current argument the player is typing is the first argument, the names of each
CyberSubCommand
added will be returned
-
If the current argument the player is typing is not the first argument, a
CyberSubCommand
will attempted to be found with the name of the first argument, and return the list provided by theCyberSubCommand.tabComplete(SentCommand, SentSubCommand)
method
-
If the current argument the player is typing is the first argument, the names of each
-
If the argument the command sender is currently typing has been set (via
BaseCommand.setArgType(int, ArgType)
) to eitherArgType.ONLINE_PLAYER
orArgType.OFFLINE_PLAYER
), then a list of players will be sent to the command sender. - If the above yields no results, an empty list will be sent to the command sender.
- Parameters:
command
- TheSentCommand
of the command that is being typed- Returns:
- A list of strings to return to the command sender
-
If this command has any subcommands (added by the
-
onCommand
public final boolean onCommand(org.bukkit.command.CommandSender sender, org.bukkit.command.Command command, String label, String[] args) This should be ignored by most developers- Specified by:
onCommand
in interfaceorg.bukkit.command.CommandExecutor
-
execute
The execute method is called when the player executes a command. All information about the command, who executed it, the arguments, etc. are provided in theSentCommand
parameter.If any subcommands are added to this command and the
getExecuteSubCommands()
method return true, then the corresponding subcommand (from the first argument) will be executed. If no subcommand can be found or thegetExecuteSubCommands()
method is false, then this method will be called.The value returned by this method will be returned to the
CommandExecutor.onCommand(CommandSender, Command, String, String[])
method.- Parameters:
command
- TheSentCommand
of the command that was executed- Returns:
- What to return to the
CommandExecutor.onCommand(CommandSender, Command, String, String[])
method - See Also:
-
CommandExecutor.onCommand(CommandSender, Command, String, String[])
-
register
public final void register(boolean includeTabComplete) Required to be executed for the command to work properly- Parameters:
includeTabComplete
- if the command should be tab completable
-
sendUsage
public void sendUsage(org.bukkit.command.CommandSender sender) Sends the usage message of this command along with any subcommands to the sender- Overrides:
sendUsage
in classBaseCommand
- Parameters:
sender
- the sender of the command
-
addSubCommand
Adds aCyberSubCommand
to the command- Parameters:
subcommand
- TheCyberSubCommand
to add
-
getSubCommandList
- Returns:
- All
CyberSubCommand
s that are added to this command
-
getSubCommandNames
- Returns:
- The names of all the
CyberSubCommand
s in this command
-
getSubCommand
- Parameters:
name
- The name of theCyberSubCommand
to get- Returns:
- The
CyberSubCommand
with the provided name, or null if not found
-
getSubCommandsForSender
- Parameters:
sender
- TheCommandSender
- Returns:
- A list of
CyberSubCommand
that the providedCommandSender
has permission to use
-
setExecuteSubCommands
public void setExecuteSubCommands(boolean executeSubcommands) - Parameters:
executeSubcommands
- True if the command, when executed, should try to execute a subcommand before executing the command itself, otherwise false.
-
getExecuteSubCommands
public boolean getExecuteSubCommands()- Returns:
- True if the command, when executed, should try to execute a subcommand before executing the command itself, otherwise false.
-