SimpleCommand

abstract class SimpleCommand(owner: CommandOwner, primaryName: String, secondaryNames: String, description: String = "no description available", parentPermission: Permission = owner.parentPermission, overrideContext: CommandArgumentContext = EmptyCommandArgumentContext) : AbstractCommand, Command, CommandArgumentContextAware

简单的, 支持参数自动解析的指令.

要查看指令解析流程, 参考 CommandManager.executeCommand. 要查看参数解析方式, 参考 CommandValueArgumentParser.

Java 示例查看 JSimpleCommand.

Kotlin 示例:

object MySimpleCommand : SimpleCommand(
MyPlugin, "tell",
description = "Message somebody"
) {
@Handler
suspend fun CommandSender.onCommand(target: User, message: String) {
target.sendMessage(message)
}
}

其中 CommandSender 也可以替换为 CommandContext,可通过 CommandContext.originalMessage 获得触发指令的原消息链。

See also

Inheritors

Constructors

Link copied to clipboard
constructor(owner: CommandOwner, primaryName: String, vararg secondaryNames: String, description: String = "no description available", parentPermission: Permission = owner.parentPermission, overrideContext: CommandArgumentContext = EmptyCommandArgumentContext)

Functions

Link copied to clipboard
inline suspend fun Command.execute(sender: CommandSender, vararg arguments: Message = emptyArray(), checkPermission: Boolean = true): CommandExecuteResult
inline suspend fun Command.execute(sender: CommandSender, arguments: String = "", checkPermission: Boolean = true): CommandExecuteResult

执行一个确切的指令

Link copied to clipboard
Link copied to clipboard
inline fun Command.register(override: Boolean = false): Boolean
Link copied to clipboard
inline fun Command.unregister(): Boolean

Properties

Link copied to clipboard

获取所有指令名称 (包含 primaryNamesecondaryNames).

Link copied to clipboard
open override val context: CommandArgumentContext

指令参数环境. 默认为 CommandArgumentContext.Builtins + overrideContext

Link copied to clipboard
abstract val description: String

描述, 用于显示在 BuiltInCommands.HelpCommand

Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
abstract val owner: CommandOwner

指令拥有者.

Link copied to clipboard
abstract val permission: Permission

为此指令分配的权限.

Link copied to clipboard

true 时表示 指令前缀 可选.

Link copied to clipboard
abstract val primaryName: String

主指令名. 将会参与构成 Permission.id.

Link copied to clipboard
abstract val secondaryNames: Array<out String>

次要指令名

Link copied to clipboard
open override val usage: String

自动根据带有 Handler 注解的函数签名生成 usage. 也可以被覆盖.