mirror of
https://github.com/mamoe/mirai.git
synced 2025-01-17 07:34:49 +08:00
Prohibit premature usages of PermissionService
This commit is contained in:
parent
044457ae24
commit
77e2a5c3b4
@ -86,6 +86,10 @@ internal class MiraiConsoleImplementationBridge(
|
||||
// used internally
|
||||
val globalComponentStorage: GlobalComponentStorageImpl by lazy { GlobalComponentStorageImpl() }
|
||||
|
||||
// tentative workaround for https://github.com/mamoe/mirai/pull/1889#pullrequestreview-887903183
|
||||
@Volatile
|
||||
var permissionSeviceLoaded: Boolean = false
|
||||
|
||||
override val mainLogger: MiraiLogger by lazy { createLogger("main") }
|
||||
|
||||
init {
|
||||
@ -187,6 +191,7 @@ internal class MiraiConsoleImplementationBridge(
|
||||
phase("load PermissionService") {
|
||||
mainLogger.verbose { "Loading PermissionService..." }
|
||||
|
||||
permissionSeviceLoaded = true
|
||||
PermissionService.INSTANCE.let { ps ->
|
||||
if (ps is BuiltInPermissionService) {
|
||||
consoleDataScope.addAndReloadConfig(ps.config)
|
||||
|
@ -11,6 +11,7 @@
|
||||
|
||||
package net.mamoe.mirai.console.permission
|
||||
|
||||
import net.mamoe.mirai.console.MiraiConsoleImplementation
|
||||
import net.mamoe.mirai.console.compiler.common.ResolveContext
|
||||
import net.mamoe.mirai.console.compiler.common.ResolveContext.Kind.COMMAND_NAME
|
||||
import net.mamoe.mirai.console.extension.instance
|
||||
@ -147,7 +148,12 @@ public interface PermissionService<P : Permission> {
|
||||
@get:JvmName("getInstance")
|
||||
@JvmStatic
|
||||
public val INSTANCE: PermissionService<out Permission>
|
||||
get() = GlobalComponentStorage.getPreferredExtension(PermissionServiceProvider).instance
|
||||
get() {
|
||||
if (!MiraiConsoleImplementation.getBridge().permissionSeviceLoaded) {
|
||||
error("PermissionService is not yet ready.")
|
||||
}
|
||||
return GlobalComponentStorage.getPreferredExtension(PermissionServiceProvider).instance
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取一个权限, 失败时抛出 [NoSuchElementException]
|
||||
|
Loading…
Reference in New Issue
Block a user