From 5ff9bfa27260d6f7cb6b2d935debe12b955779b9 Mon Sep 17 00:00:00 2001 From: "jiahua.liu" Date: Sat, 25 Jan 2020 14:58:49 +0800 Subject: [PATCH] Console Command.kt --- .../kotlin/net/mamoe/mirai/plugin/Command.kt | 33 +++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 mirai-console/src/main/kotlin/net/mamoe/mirai/plugin/Command.kt diff --git a/mirai-console/src/main/kotlin/net/mamoe/mirai/plugin/Command.kt b/mirai-console/src/main/kotlin/net/mamoe/mirai/plugin/Command.kt new file mode 100644 index 000000000..6f9f112e0 --- /dev/null +++ b/mirai-console/src/main/kotlin/net/mamoe/mirai/plugin/Command.kt @@ -0,0 +1,33 @@ +package net.mamoe.mirai.plugin + +object CommandManager { + private val registeredCommand: MutableMap = mutableMapOf() + + + fun register(command: Command) { + val allNames = mutableListOf(command.name).also { it.addAll(command.alias) } + allNames.forEach { + if (registeredCommand.containsKey(it)) { + error("Command Name(or Alias) $it is already registered, consider if same function plugin was installed") + } + } + allNames.forEach { + registeredCommand[it] = command + } + } + + +} + +abstract class Command( + val name: String, + val alias: List = listOf() +) { + /** + * 最高优先级监听器 + * 如果return [false] 这次指令不会被[PluginBase]的全局onCommand监听器监听 + * */ + fun onCommand(args: List): Boolean { + return true + } +}