Limit MiraiConsoleImplementation.backendAccess

This commit is contained in:
Karlatemp 2021-02-18 01:13:06 +08:00
parent 11e7d9f454
commit 7c863e9353
No known key found for this signature in database
GPG Key ID: 21FBDDF664FF06F8

View File

@ -31,6 +31,7 @@ import net.mamoe.mirai.message.data.Message
import net.mamoe.mirai.utils.BotConfiguration import net.mamoe.mirai.utils.BotConfiguration
import net.mamoe.mirai.utils.LoginSolver import net.mamoe.mirai.utils.LoginSolver
import net.mamoe.mirai.utils.MiraiLogger import net.mamoe.mirai.utils.MiraiLogger
import java.lang.IllegalStateException
import java.nio.file.Path import java.nio.file.Path
import java.util.* import java.util.*
import java.util.concurrent.locks.ReentrantLock import java.util.concurrent.locks.ReentrantLock
@ -217,7 +218,13 @@ public interface MiraiConsoleImplementation : CoroutineScope {
public val resolvedPlugins: MutableList<Plugin> public val resolvedPlugins: MutableList<Plugin>
} }
public val backendAccess: BackendAccess get() = backendAccessInstance public val backendAccess: BackendAccess get() {
if (instanceInitialized) {
if (this === instance)
return backendAccessInstance
}
throw IllegalStateException("Permission denied")
}
public companion object { public companion object {
private val backendAccessInstance = object : BackendAccess { private val backendAccessInstance = object : BackendAccess {
@ -226,6 +233,7 @@ public interface MiraiConsoleImplementation : CoroutineScope {
} }
internal lateinit var instance: MiraiConsoleImplementation internal lateinit var instance: MiraiConsoleImplementation
internal val instanceInitialized: Boolean get() = ::instance.isInitialized
private val initLock = ReentrantLock() private val initLock = ReentrantLock()
/** /**