Fix loadFromResource

This commit is contained in:
Him188 2020-11-13 18:24:18 +08:00
parent d1f431e98e
commit cf08c2b767
2 changed files with 5 additions and 2 deletions

View File

@ -11,6 +11,8 @@
package net.mamoe.mirai.console.internal.util
import net.mamoe.mirai.console.internal.plugin.BuiltInJvmPluginLoaderImpl
internal inline fun <reified E : Throwable, R> runIgnoreException(block: () -> R): R? {
try {
return block()
@ -41,6 +43,7 @@ internal fun getCallerClassloader(): ClassLoader? {
net.mamoe.mirai.console.TestMiraiConosleKt.main(TestMiraiConosle.kt)
*/
val traces = Thread.currentThread().stackTrace
Class.forName(traces[3].className).classLoader
val classname = traces[3].className
BuiltInJvmPluginLoaderImpl.classLoaders.firstOrNull { it.findClass(classname, true) != null }
}.getOrNull()
}

View File

@ -67,7 +67,7 @@ public interface JvmPluginDescription : PluginDescription {
* @param filename [ClassLoader.getResourceAsStream] 的参数 `name`
* @param pluginClassloader 默认通过 [Thread.getStackTrace] 获取调用方 [Class] 然后获取其 [Class.getClassLoader].
*/
@JvmOverloads
// @JvmOverloads // compiler error
@JvmStatic
public fun loadFromResource(
filename: String = "plugin.yml",