diff --git a/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/plugin/PluginLoader.kt b/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/plugin/PluginLoader.kt
index 60df456ca..2b4dc1e56 100644
--- a/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/plugin/PluginLoader.kt
+++ b/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/plugin/PluginLoader.kt
@@ -50,6 +50,8 @@ interface PluginLoader
{
fun disable(plugin: P)
}
+fun PluginLoader.getDescription(plugin: P): D = plugin.description
+
open class PluginLoadException : RuntimeException {
constructor() : super()
constructor(message: String?) : super(message)
diff --git a/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/plugin/PluginManager.kt b/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/plugin/PluginManager.kt
index 9140403c0..76647cef3 100644
--- a/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/plugin/PluginManager.kt
+++ b/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/plugin/PluginManager.kt
@@ -13,12 +13,16 @@ package net.mamoe.mirai.console.plugin
import kotlinx.atomicfu.locks.withLock
import net.mamoe.mirai.console.MiraiConsole
+import net.mamoe.mirai.console.setting.internal.cast
import net.mamoe.mirai.utils.info
import java.io.File
import java.util.concurrent.locks.ReentrantLock
val Plugin.description: PluginDescription
- get() = PluginManager.resolvedPlugins.firstOrNull { it == this }?.description ?: error("Plugin is unloaded")
+ get() = PluginManager.resolvedPlugins.firstOrNull { it == this }?.loader?.cast>()
+ ?.getDescription(
+ this
+ ) ?: error("Plugin is unloaded")
inline fun PluginLoader<*, *>.register() = PluginManager.registerPluginLoader(this)
inline fun PluginLoader<*, *>.unregister() = PluginManager.unregisterPluginLoader(this)
diff --git a/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/plugin/jvm/JarPluginLoader.kt b/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/plugin/jvm/JarPluginLoader.kt
index c70bc47da..37a66942b 100644
--- a/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/plugin/jvm/JarPluginLoader.kt
+++ b/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/plugin/jvm/JarPluginLoader.kt
@@ -21,7 +21,7 @@ import net.mamoe.mirai.console.utils.ConsoleExperimentalAPI
import net.mamoe.mirai.utils.MiraiLogger
import net.mamoe.yamlkt.Yaml
import java.io.File
-import java.net.URL
+import java.net.URI
import kotlin.coroutines.CoroutineContext
import kotlin.reflect.full.createInstance
@@ -54,17 +54,18 @@ object JarPluginLoader : AbstractFilePluginLoader.mapToDescription(): List {
- return this.associateWith { URL("jar:${it.absolutePath}!/plugin.yml") }.mapNotNull { (file, url) ->
- kotlin.runCatching {
- url.readText()
- }.fold(
- onSuccess = { yaml ->
- Yaml.nonStrict.parse(JvmPluginDescription.serializer(), yaml)
- },
- onFailure = {
- logger.error("Cannot load plugin file ${file.name}", it)
- null
- }
+ return this.associateWith { URI("jar:file:${it.absolutePath.replace('\\', '/')}!/plugin.yml").toURL() }
+ .mapNotNull { (file, url) ->
+ kotlin.runCatching {
+ url.readText()
+ }.fold(
+ onSuccess = { yaml ->
+ Yaml.nonStrict.parse(JvmPluginDescription.serializer(), yaml)
+ },
+ onFailure = {
+ logger.error("Cannot load plugin file ${file.name}", it)
+ null
+ }
)?.also { it._file = file }
}
}
diff --git a/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/setting/internal/Setting.value composite impl.kt b/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/setting/internal/Setting.value composite impl.kt
index c70db9e71..19883207e 100644
--- a/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/setting/internal/Setting.value composite impl.kt
+++ b/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/setting/internal/Setting.value composite impl.kt
@@ -141,7 +141,7 @@ internal fun KClass<*>.isPrimitiveOrBuiltInSerializableValue(): Boolean {
@PublishedApi
@Suppress("UNCHECKED_CAST")
-internal inline fun T.cast(): R = this as R
+internal inline fun Any.cast(): R = this as R
/**
* Copied from kotlinx.serialization, modifications are marked with "/* mamoe modify */"