From 235391e65808ba0c74596fc01322bfc1c9a13157 Mon Sep 17 00:00:00 2001 From: Him188 Date: Sun, 13 Sep 2020 01:12:46 +0800 Subject: [PATCH] Rename PermissionId.id to PermissionId.name --- .../mirai/console/command/CommandOwner.kt | 2 +- .../mirai/console/permission/PermissionId.kt | 8 ++++---- .../permission/PermissionIdNamespace.kt | 2 +- .../console/plugin/jvm/AbstractJvmPlugin.kt | 2 +- .../console/plugin/loader/PluginLoader.kt | 20 +++++++++++++------ 5 files changed, 21 insertions(+), 13 deletions(-) diff --git a/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/command/CommandOwner.kt b/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/command/CommandOwner.kt index 05685e137..f9c627edf 100644 --- a/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/command/CommandOwner.kt +++ b/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/command/CommandOwner.kt @@ -36,5 +36,5 @@ public interface CommandOwner : PermissionIdNamespace { internal object ConsoleCommandOwner : CommandOwner { override val parentPermission: Permission get() = BuiltInCommands.parentPermission - override fun permissionId(id: String): PermissionId = PermissionId("console", id) + override fun permissionId(name: String): PermissionId = PermissionId("console", name) } \ No newline at end of file diff --git a/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/permission/PermissionId.kt b/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/permission/PermissionId.kt index caabfd017..8ec7a7f90 100644 --- a/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/permission/PermissionId.kt +++ b/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/permission/PermissionId.kt @@ -23,26 +23,26 @@ import net.mamoe.mirai.console.internal.data.map @Serializable(with = PermissionId.PermissionIdAsStringSerializer::class) public data class PermissionId( public val namespace: String, - public val id: String, + public val name: String, ) { init { require(!namespace.contains(':')) { "':' is not allowed in namespace" } - require(!id.contains(':')) { + require(!name.contains(':')) { "':' is not allowed in id" } } public object PermissionIdAsStringSerializer : KSerializer by String.serializer().map( - serializer = { it.namespace + ":" + it.id }, + serializer = { it.namespace + ":" + it.name }, deserializer = { it.split(':').let { (namespace, id) -> PermissionId(namespace, id) } } ) /** * 返回 `$namespace:$id` */ - public override fun toString(): String = "$namespace:$id" + public override fun toString(): String = "$namespace:$name" public companion object { /** diff --git a/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/permission/PermissionIdNamespace.kt b/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/permission/PermissionIdNamespace.kt index 60e47ff91..6c8cb4b4c 100644 --- a/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/permission/PermissionIdNamespace.kt +++ b/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/permission/PermissionIdNamespace.kt @@ -16,5 +16,5 @@ public interface PermissionIdNamespace { /** * 创建一个此命名空间下的 [PermitteeId] */ - public fun permissionId(id: String): PermissionId + public fun permissionId(name: String): PermissionId } \ No newline at end of file diff --git a/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/plugin/jvm/AbstractJvmPlugin.kt b/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/plugin/jvm/AbstractJvmPlugin.kt index e52f03038..95dcfb1d0 100644 --- a/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/plugin/jvm/AbstractJvmPlugin.kt +++ b/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/plugin/jvm/AbstractJvmPlugin.kt @@ -37,7 +37,7 @@ public abstract class AbstractJvmPlugin @JvmOverloads constructor( public final override val loader: JvmPluginLoader get() = super.loader - public final override fun permissionId(id: String): PermissionId = PermissionId(description.id, id) + public final override fun permissionId(name: String): PermissionId = PermissionId(description.id, "command.$name") /** * 重载 [PluginData] diff --git a/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/plugin/loader/PluginLoader.kt b/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/plugin/loader/PluginLoader.kt index 9d7307c53..dc68b75ec 100644 --- a/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/plugin/loader/PluginLoader.kt +++ b/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/plugin/loader/PluginLoader.kt @@ -11,18 +11,20 @@ package net.mamoe.mirai.console.plugin.loader +import net.mamoe.mirai.console.extensions.PluginLoaderProvider import net.mamoe.mirai.console.plugin.Plugin import net.mamoe.mirai.console.plugin.PluginManager import net.mamoe.mirai.console.plugin.PluginManager.INSTANCE.disable import net.mamoe.mirai.console.plugin.PluginManager.INSTANCE.enable import net.mamoe.mirai.console.plugin.description.PluginDescription import net.mamoe.mirai.console.plugin.jvm.JvmPluginLoader -import java.util.* /** * 插件加载器. * - * 插件加载器只实现寻找插件列表, 加载插件, 启用插件, 关闭插件这四个功能. + * 插件加载器只实现寻找插件列表, 加载插件, 启用插件, 关闭插件这四个功能。 + * + * 一个插件要在何时被加载,依赖如何处理,[PluginLoader] 都无需关心。 * * 有关插件的依赖和已加载的插件列表由 [PluginManager] 维护. * @@ -33,7 +35,7 @@ import java.util.* * 插件被允许扩展一个加载器. * * ### 实现扩展加载器 - * 直接实现接口 [PluginLoader] 或 [FilePluginLoader], 并添加 [ServiceLoader] 相关资源文件即可. + * 直接实现接口 [PluginLoader] 或 [FilePluginLoader], 并注册 [PluginLoaderProvider] * * @see JvmPluginLoader Jar 插件加载器 */ @@ -43,9 +45,9 @@ public interface PluginLoader

{ * * 这些插件都应处于还未被加载的状态. * - * 在 console 启动时, [PluginManager] 会获取所有 [PluginDescription], 分析依赖关系, 确认插件加载顺序. + * 在 Console 启动时, [PluginManager] 会获取所有 [PluginDescription], 分析依赖关系, 确认插件加载顺序. * - * **实现细节:** 此函数*只应该*在 console 启动时被调用一次. 但取决于前端实现不同, 或由于被一些插件需要, 此函数也可能会被多次调用. + * **实现细节:** 此函数*只应该*在 Console 启动时被调用一次. 但取决于前端实现不同, 或由于被一些插件需要, 此函数也可能会被多次调用. */ public fun listPlugins(): List

@@ -54,7 +56,7 @@ public interface PluginLoader

{ * * **实现细节**: 此函数只允许抛出 [PluginLoadException] 作为正常失败原因, 其他任意异常都属于意外错误. * - * 若在 console 启动并加载所有插件的过程中, 本函数抛出异常, 则会放弃此插件的加载, 并影响依赖它的其他插件. + * 若在 Console 启动并加载所有插件的过程中, 本函数抛出异常, 则会放弃此插件的加载, 并影响依赖它的其他插件. * * @throws PluginLoadException 在加载插件遇到意料之中的错误时抛出 (如无法读取插件信息等). * @@ -67,10 +69,13 @@ public interface PluginLoader

{ /** * 主动加载一个插件 (实例), 但不 [启用][enable] 它. 返回加载成功的主类实例 * + * **实现注意**: Console 不会把一个已经启用了的插件再次调用 [load] 或 [enable], 但不排除意外情况. 实现本函数时应在这种情况时立即抛出异常 [IllegalStateException]. + * * **实现细节**: 此函数只允许抛出 [PluginLoadException] 作为正常失败原因, 其他任意异常都属于意外错误. * 当异常发生时, 插件将会直接被放弃加载, 并影响依赖它的其他插件. * * @throws PluginLoadException 在加载插件遇到意料之中的错误时抛出 (如找不到主类等). + * @throws IllegalStateException 在插件已经被加载时抛出. 这属于意料之外的情况. */ @Throws(PluginLoadException::class) public fun load(plugin: P) @@ -78,10 +83,13 @@ public interface PluginLoader

{ /** * 主动启用这个插件. * + * **实现注意**: Console 不会把一个已经启用了的插件再次调用 [load] 或 [enable], 但不排除意外情况. 实现本函数时应在这种情况时立即抛出异常 [IllegalStateException]. + * * **实现细节**: 此函数可抛出 [PluginLoadException] 作为正常失败原因, 其他任意异常都属于意外错误. * 当异常发生时, 插件将会直接被放弃加载, 并影响依赖它的其他插件. * * @throws PluginLoadException 在加载插件遇到意料之中的错误时抛出 (如找不到主类等). + * @throws IllegalStateException 在插件已经被加载时抛出. 这属于意料之外的情况. * * @see PluginManager.enable */