Package top.focess.qq.api.command
Class Command
- java.lang.Object
-
- top.focess.qq.api.command.Command
-
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 FocessQQ Bot. You should declareCommandTypeto this class ,or you should register it with your plugin manually.
-
-
Constructor Summary
Constructors Modifier Constructor Description protectedCommand()Provide a constructor to helpCommandTypedesign.Command(@NotNull String name, @NotNull String... aliases)Instance aCommandClass with special name and aliases.
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description top.focess.command.Command.ExecutoraddExecutor(@NotNull CommandExecutor executor, @NotNull top.focess.command.CommandArgument<?>... commandArguments)Add default executor to define how to execute this command.top.focess.command.CommandResultexecute(@NotNull CommandSender sender, @NotNull String[] args, @NotNull IOHandler ioHandler)Execute the command with special arguments@NotNull @UnmodifiableView List<String>getAliases()static @NotNull @UnmodifiableView List<Command>getCommands()Get all commandsjava.util.function.Predicate<CommandSender>getExecutorPermission()@NotNull StringgetName()@NotNull top.focess.command.CommandPermissiongetPermission()@NotNull PlugingetPlugin()voidinfoUsage(CommandSender sender, IOHandler ioHandler)abstract voidinit()Used to initialize the command (the primary goal is to define the default executors)booleanisRegistered()static voidregister(@NotNull Plugin plugin, @NotNull Command command)Register the commandvoidsetExecutorPermission(@NotNull java.util.function.Predicate<CommandSender> executorPermission)voidsetPermission(top.focess.command.CommandPermission permission)Set the default permissionvoidunregister()Unregister this commandstatic voidunregister(Plugin plugin)Unregister all commands in the pluginstatic booleanunregisterAll()Unregister all commandsabstract @NotNull 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 @NotNull String name, @NotNull @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 helpCommandTypedesign. Never instance it!Command will be instanced when this class is loaded automatically.
-
-
Method Detail
-
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
@NotNull public static @NotNull @UnmodifiableView List<Command> getCommands()
Get all commands- Returns:
- All commands as a list
-
register
public static void register(@NotNull @NotNull Plugin plugin, @NotNull @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 commandsIllegalStateException- if the command is not initialized
-
isRegistered
public boolean isRegistered()
-
getPlugin
@NotNull public @NotNull Plugin getPlugin()
-
unregister
public void unregister()
Unregister this command
-
getName
@NotNull public @NotNull String getName()
-
getExecutorPermission
public java.util.function.Predicate<CommandSender> getExecutorPermission()
-
setExecutorPermission
public void setExecutorPermission(@NotNull @NotNull java.util.function.Predicate<CommandSender> executorPermission)
-
addExecutor
@NotNull public final top.focess.command.Command.Executor addExecutor(@NotNull @NotNull CommandExecutor executor, @NotNull @NotNull top.focess.command.CommandArgument<?>... commandArguments)Add default executor to define how to execute this command. for example :this.addExecutor(... ,CommandArgument.ofString("example"),CommandArgument.ofString());which means that it runs when you execute the command with "example" "xxx".this.addExecutor(...);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 top.focess.command.CommandResult execute(@NotNull @NotNull CommandSender sender, @NotNull @NotNull String[] args, @NotNull @NotNull IOHandler ioHandler) throws ExceptionExecute the command with special arguments- Parameters:
sender- the executorargs- the arguments that command spilt by spacesioHandler- the receiver- Returns:
- the command result
- Throws:
Exception- the exception that occurred when executing the command- See Also:
CommandLine.exec(CommandSender, String, IOHandler)
-
getPermission
@NotNull public @NotNull top.focess.command.CommandPermission getPermission()
-
setPermission
public void setPermission(top.focess.command.CommandPermission permission)
Set the default permission- Parameters:
permission- the target permission the command need
-
init
public abstract void init()
Used to initialize the command (the primary goal is to define the default executors)
-
usage
@NotNull public abstract @NotNull 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)
-
-