public abstract class Command extends Object
CommandType to this class ,or you should register it with your plugin manually.| 限定符和类型 | 类和说明 |
|---|---|
static class |
Command.Executor
This class is used to help define the executor of certain command.
|
| 限定符 | 构造器和说明 |
|---|---|
protected |
Command()
Provide a constructor to help
PluginType design. |
|
Command(@NotNull String name,
String... aliases)
Instance a
Command Class with special name and aliases. |
| 限定符和类型 | 方法和说明 |
|---|---|
@NotNull Command.Executor |
addExecutor(int count,
@NotNull CommandExecutor executor,
String... subCommands)
Add default executor to define how to execute this command.
|
boolean |
execute(@NotNull CommandSender sender,
@NotNull String[] args,
@NotNull IOHandler ioHandler)
Execute the command with special arguments
|
@NotNull List<String> |
getAliases() |
static List<Command> |
getCommands()
Get all commands
|
java.util.function.Predicate<CommandSender> |
getExecutorPermission() |
@NotNull String |
getName() |
@NotNull CommandPermission |
getPermission() |
@NotNull Plugin |
getPlugin() |
abstract void |
init()
Used to initialize the command (the primary goal is to define the default executors)
|
boolean |
isInitialize() |
boolean |
isRegistered() |
static void |
register(@NotNull Plugin plugin,
@NotNull Command command)
Register the command
|
void |
setExecutorPermission(@NotNull java.util.function.Predicate<CommandSender> executorPermission) |
void |
setPermission(CommandPermission permission)
Set the default permission
|
void |
setPermission(@NotNull net.mamoe.mirai.contact.MemberPermission permission)
已过时。
|
void |
unregister()
Unregister this command
|
static void |
unregister(Plugin plugin)
Unregister all commands in the plugin
|
static boolean |
unregisterAll()
Unregister all commands
|
abstract void |
usage(CommandSender sender,
IOHandler ioHandler)
Used to print help information when execute this command with wrong arguments or the executor returns
CommandResult.ARGS |
public Command(@NotNull
@NotNull String name,
@NotNull
String... aliases)
Command Class with special name and aliases.name - the name of the commandaliases - the aliases of the commandCommandLoadException - if there is any exception thrown in the initializing processprotected Command()
PluginType design.
Never instance it! It will be instanced when this class is loaded automatically.public void setExecutorPermission(@NotNull
@NotNull java.util.function.Predicate<CommandSender> executorPermission)
public static void unregister(Plugin plugin)
plugin - the plugin that the commands that need to be unregistered belongs topublic static boolean unregisterAll()
public static void register(@NotNull
@NotNull Plugin plugin,
@NotNull
@NotNull Command command)
plugin - the plugin the command belongs tocommand - the command that need to be registeredCommandDuplicateException - if the command name already exists in the registered commandspublic boolean isRegistered()
@NotNull public @NotNull Plugin getPlugin()
public void unregister()
@NotNull public @NotNull String getName()
public java.util.function.Predicate<CommandSender> getExecutorPermission()
@NotNull public final @NotNull Command.Executor addExecutor(int count, @NotNull @NotNull CommandExecutor executor, String... subCommands)
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.count - the arguments' length that you needexecutor - the executor to define this commandsubCommands - the known arguments for this executorpublic final boolean execute(@NotNull
@NotNull CommandSender sender,
@NotNull
@NotNull String[] args,
@NotNull
@NotNull IOHandler ioHandler)
sender - the executorargs - the arguments that command spilt by spacesioHandler - the receiverMain.CommandLine#exec(CommandSender, String, IOHandler)@NotNull public @NotNull CommandPermission getPermission()
@Deprecated public final void setPermission(@NotNull @NotNull net.mamoe.mirai.contact.MemberPermission permission)
permission - the target permission the command needpublic abstract void init()
public abstract void usage(CommandSender sender, IOHandler ioHandler)
CommandResult.ARGSsender - the executor which need to print help informationioHandler - the receiver which need to print help informationpublic boolean isInitialize()
public void setPermission(CommandPermission permission)
permission - the target permission the command needCopyright © 2022. All rights reserved.