diff --git a/backend/mirai-console/src/extension/ExtensionPoint.kt b/backend/mirai-console/src/extension/ExtensionPoint.kt index b2cfa16e7..0a768d6e6 100644 --- a/backend/mirai-console/src/extension/ExtensionPoint.kt +++ b/backend/mirai-console/src/extension/ExtensionPoint.kt @@ -74,7 +74,7 @@ public abstract class AbstractSingletonExtensionPoint, * 由 [SingletonExtensionSelector] 选择后的实例. */ @ConsoleExperimentalApi - public val selectedInstance: T by lazy { + public open val selectedInstance: T by lazy { GlobalComponentStorage.run { this@AbstractSingletonExtensionPoint.findSingletonInstance(extensionType, builtinImplementation) } } } \ No newline at end of file diff --git a/backend/mirai-console/src/extensions/PermissionServiceProvider.kt b/backend/mirai-console/src/extensions/PermissionServiceProvider.kt index 6a8546ef8..ccd6b6495 100644 --- a/backend/mirai-console/src/extensions/PermissionServiceProvider.kt +++ b/backend/mirai-console/src/extensions/PermissionServiceProvider.kt @@ -25,6 +25,8 @@ import net.mamoe.mirai.console.util.ConsoleExperimentalApi public interface PermissionServiceProvider : SingletonExtension> { public companion object ExtensionPoint : AbstractSingletonExtensionPoint>(PermissionServiceProvider::class, BuiltInPermissionService) { + internal var permissionServiceOk = false + @ConsoleExperimentalApi public val providerPlugin: Plugin? by lazy { GlobalComponentStorage.run { @@ -33,6 +35,15 @@ public interface PermissionServiceProvider : SingletonExtension + get() { + if (!permissionServiceOk) { + error("PermissionService not yet loaded") + } + return super.selectedInstance + } } } @@ -46,4 +57,4 @@ public class PermissionServiceProviderImpl(override val instance: PermissionServ */ public class PermissionServiceProviderImplLazy(initializer: () -> PermissionService<*>) : PermissionServiceProvider { override val instance: PermissionService<*> by lazy(initializer) -} \ No newline at end of file +} diff --git a/backend/mirai-console/src/internal/MiraiConsoleImplementationBridge.kt b/backend/mirai-console/src/internal/MiraiConsoleImplementationBridge.kt index 2bdb53b0c..9b14bb3d0 100644 --- a/backend/mirai-console/src/internal/MiraiConsoleImplementationBridge.kt +++ b/backend/mirai-console/src/internal/MiraiConsoleImplementationBridge.kt @@ -180,6 +180,7 @@ internal object MiraiConsoleImplementationBridge : CoroutineScope, MiraiConsoleI phase("load PermissionService") { mainLogger.verbose { "Loading PermissionService..." } + PermissionServiceProvider.permissionServiceOk = true PermissionService.INSTANCE.let { ps -> if (ps is BuiltInPermissionService) { ConsoleDataScope.addAndReloadConfig(ps.config)