mirror of
https://github.com/mamoe/mirai.git
synced 2025-01-11 02:50:15 +08:00
Close JvmPlugin when server is closing
This commit is contained in:
parent
b5ab460bf8
commit
c479856380
@ -9,12 +9,16 @@
|
|||||||
|
|
||||||
package net.mamoe.mirai.console.internal.plugin
|
package net.mamoe.mirai.console.internal.plugin
|
||||||
|
|
||||||
import kotlinx.coroutines.*
|
import kotlinx.coroutines.CoroutineExceptionHandler
|
||||||
|
import kotlinx.coroutines.CoroutineScope
|
||||||
|
import kotlinx.coroutines.Job
|
||||||
|
import kotlinx.coroutines.ensureActive
|
||||||
import net.mamoe.mirai.console.MiraiConsole
|
import net.mamoe.mirai.console.MiraiConsole
|
||||||
import net.mamoe.mirai.console.data.PluginDataStorage
|
import net.mamoe.mirai.console.data.PluginDataStorage
|
||||||
import net.mamoe.mirai.console.internal.MiraiConsoleImplementationBridge
|
import net.mamoe.mirai.console.internal.MiraiConsoleImplementationBridge
|
||||||
import net.mamoe.mirai.console.internal.command.qualifiedNameOrTip
|
import net.mamoe.mirai.console.internal.command.qualifiedNameOrTip
|
||||||
import net.mamoe.mirai.console.internal.data.createInstanceOrNull
|
import net.mamoe.mirai.console.internal.data.createInstanceOrNull
|
||||||
|
import net.mamoe.mirai.console.internal.util.childScopeContext
|
||||||
import net.mamoe.mirai.console.plugin.AbstractFilePluginLoader
|
import net.mamoe.mirai.console.plugin.AbstractFilePluginLoader
|
||||||
import net.mamoe.mirai.console.plugin.PluginLoadException
|
import net.mamoe.mirai.console.plugin.PluginLoadException
|
||||||
import net.mamoe.mirai.console.plugin.jvm.*
|
import net.mamoe.mirai.console.plugin.jvm.*
|
||||||
@ -40,11 +44,9 @@ internal object JarPluginLoaderImpl :
|
|||||||
get() = MiraiConsoleImplementationBridge.dataStorageForJarPluginLoader
|
get() = MiraiConsoleImplementationBridge.dataStorageForJarPluginLoader
|
||||||
|
|
||||||
override val coroutineContext: CoroutineContext =
|
override val coroutineContext: CoroutineContext =
|
||||||
MiraiConsole.coroutineContext +
|
MiraiConsole.childScopeContext(CoroutineExceptionHandler { _, throwable ->
|
||||||
SupervisorJob(MiraiConsole.coroutineContext[Job]) +
|
logger.error("Unhandled Jar plugin exception: ${throwable.message}", throwable)
|
||||||
CoroutineExceptionHandler { _, throwable ->
|
})
|
||||||
logger.error("Unhandled Jar plugin exception: ${throwable.message}", throwable)
|
|
||||||
}
|
|
||||||
|
|
||||||
private val classLoader: PluginsLoader = PluginsLoader(this.javaClass.classLoader)
|
private val classLoader: PluginsLoader = PluginsLoader(this.javaClass.classLoader)
|
||||||
|
|
||||||
|
@ -127,6 +127,11 @@ internal abstract class JvmPluginInternal(
|
|||||||
CoroutineExceptionHandler { _, throwable -> logger.error(throwable) }
|
CoroutineExceptionHandler { _, throwable -> logger.error(throwable) }
|
||||||
.plus(parentCoroutineContext)
|
.plus(parentCoroutineContext)
|
||||||
.plus(SupervisorJob(parentCoroutineContext[Job]))
|
.plus(SupervisorJob(parentCoroutineContext[Job]))
|
||||||
|
.also {
|
||||||
|
JarPluginLoaderImpl.coroutineContext[Job]!!.invokeOnCompletion {
|
||||||
|
this.cancel()
|
||||||
|
}
|
||||||
|
}
|
||||||
.plus(_intrinsicCoroutineContext)
|
.plus(_intrinsicCoroutineContext)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user