Package top.focess.qq.api.command
Class Command
- java.lang.Object
-
- top.focess.qq.api.command.Command
-
- Direct Known Subclasses:
BotCommand,CommandCommand,DebugCommand,FriendCommand,GroupCommand,LoadCommand,PluginCommand,ReloadCommand,StopCommand,UnloadCommand
public abstract class Command extends Object
Represent a Plugin class that can execute. Just like we use the terminal, we could use it to executing some commands. This is an important way to interact with Mirai QQ Bot. You should declareCommandTypeto this class ,or you should register it with your plugin manually.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classCommand.ExecutorThis class is used to help define the executor of certain command.
-
Constructor Summary
Constructors Modifier Constructor Description protectedCommand()Provide a constructor to helpPluginTypedesign.Command(String name, String... aliases)Instance aCommandClass with special name and aliases.
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Concrete Methods Deprecated Methods Modifier and Type Method Description Command.ExecutoraddExecutor(int count, CommandExecutor executor, String... subCommands)Deprecated.Command.ExecutoraddExecutor(CommandExecutor executor, CommandArgument<?>... commandArguments)Add default executor to define how to execute this command.booleanexecute(CommandSender sender, String[] args, IOHandler ioHandler)Execute the command with special argumentsList<String>getAliases()static List<Command>getCommands()Get all commandsjava.util.function.Predicate<CommandSender>getExecutorPermission()StringgetName()CommandPermissiongetPermission()PlugingetPlugin()voidinfoUsage(CommandSender sender, IOHandler ioHandler)abstract voidinit()Used to initialize the command (the primary goal is to define the default executors)booleanisInitialize()booleanisRegistered()static voidregister(Plugin plugin, Command command)Register the commandvoidsetExecutorPermission(java.util.function.Predicate<CommandSender> executorPermission)voidsetPermission(CommandPermission permission)Set the default permissionvoidunregister()Unregister this commandstatic voidunregister(Plugin plugin)Unregister all commands in the pluginstatic booleanunregisterAll()Unregister all commandsabstract List<String>usage(CommandSender sender)Used to get help information when execute this command with wrong arguments or the executor returnsCommandResult.ARGS
-
-
-
Constructor Detail
-
Command
public Command(@NotNull String name, @NotNull String... aliases)Instance aCommandClass with special name and aliases.- Parameters:
name- the name of the commandaliases- the aliases of the command- Throws:
CommandLoadException- if there is any exception thrown in the initializing process
-
Command
protected Command()
Provide a constructor to helpPluginTypedesign. Never instance it! It will be instanced when this class is loaded automatically.
-
-
Method Detail
-
setExecutorPermission
public void setExecutorPermission(@NotNull java.util.function.Predicate<CommandSender> executorPermission)
-
unregister
public static void unregister(Plugin plugin)
Unregister all commands in the plugin- Parameters:
plugin- the plugin that the commands that need to be unregistered belongs to
-
unregisterAll
public static boolean unregisterAll()
Unregister all commands- Returns:
- true if there are some commands not belonging to MainPlugin not been unregistered, false otherwise
-
getCommands
public static List<Command> getCommands()
Get all commands- Returns:
- All commands as a
List
-
register
public static void register(@NotNull Plugin plugin, @NotNull Command command)Register the command- Parameters:
plugin- the plugin the command belongs tocommand- the command that need to be registered- Throws:
CommandDuplicateException- if the command name already exists in the registered commands
-
isRegistered
public boolean isRegistered()
-
getPlugin
@NotNull public Plugin getPlugin()
-
unregister
public void unregister()
Unregister this command
-
getName
@NotNull public String getName()
-
getExecutorPermission
public java.util.function.Predicate<CommandSender> getExecutorPermission()
-
addExecutor
@NotNull @Deprecated public final Command.Executor addExecutor(int count, @NotNull CommandExecutor executor, String... subCommands)
Deprecated.Add default executor to define how to execute this command. for example :this.addExecutor(1, ... ,"example");which means that it runs when you execute the command with "example" "xxx".this.addExecutor(0, ...);which means that it runs when you just execute the command without anything.- Parameters:
count- the arguments' length that you needexecutor- the executor to define this commandsubCommands- the known arguments for this executor- Returns:
- the Executor to define other proprieties
-
addExecutor
@NotNull public final Command.Executor addExecutor(@NotNull CommandExecutor executor, @NotNull CommandArgument<?>... commandArguments)
Add default executor to define how to execute this command. for example :this.addExecutor(1, ... ,"example");which means that it runs when you execute the command with "example" "xxx".this.addExecutor(0, ...);which means that it runs when you just execute the command without anything.- Parameters:
executor- the executor to define this commandcommandArguments- the defined arguments for this executor- Returns:
- the Executor to define other proprieties
-
execute
public final boolean execute(@NotNull CommandSender sender, @NotNull String[] args, @NotNull IOHandler ioHandler)Execute the command with special arguments- Parameters:
sender- the executorargs- the arguments that command spilt by spacesioHandler- the receiver- Returns:
- an Executor that help to define the executor of this command
- See Also:
CommandLine.exec(CommandSender, String, IOHandler)
-
getPermission
@NotNull public CommandPermission getPermission()
-
init
public abstract void init()
Used to initialize the command (the primary goal is to define the default executors)
-
usage
@NotNull public abstract List<String> usage(CommandSender sender)
Used to get help information when execute this command with wrong arguments or the executor returnsCommandResult.ARGS- Parameters:
sender- the executor which need to get help information- Returns:
- the help information
-
infoUsage
public final void infoUsage(CommandSender sender, IOHandler ioHandler)
-
isInitialize
public boolean isInitialize()
-
setPermission
public void setPermission(CommandPermission permission)
Set the default permission- Parameters:
permission- the target permission the command need
-
-