diff --git a/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/internal/plugin/JvmPluginInternal.kt b/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/internal/plugin/JvmPluginInternal.kt index da2c2aecc..6029f4359 100644 --- a/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/internal/plugin/JvmPluginInternal.kt +++ b/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/internal/plugin/JvmPluginInternal.kt @@ -39,8 +39,8 @@ internal abstract class JvmPluginInternal( ) : JvmPlugin, CoroutineScope { - private val resourceContainerDelegate by lazy { this::class.asResourceContainer() } - override fun getResourceAsStream(name: String): InputStream = resourceContainerDelegate.getResourceAsStream(name) + private val resourceContainerDelegate by lazy { this::class.java.classLoader.asResourceContainer() } + override fun getResourceAsStream(name: String): InputStream? = resourceContainerDelegate.getResourceAsStream(name) // region JvmPlugin /** diff --git a/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/plugin/jvm/JvmPlugin.kt b/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/plugin/jvm/JvmPlugin.kt index 1451a2ecf..d11003d5d 100644 --- a/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/plugin/jvm/JvmPlugin.kt +++ b/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/plugin/jvm/JvmPlugin.kt @@ -24,6 +24,9 @@ import kotlin.reflect.KClass /** * Java, Kotlin 或其他 JVM 平台插件 * + * ### ResourceContainer + * 实现为 [ClassLoader.getResourceAsStream] + * * @see AbstractJvmPlugin 默认实现 * * @see JavaPlugin Java 插件 @@ -46,20 +49,28 @@ public interface JvmPlugin : Plugin, CoroutineScope, get() = JarPluginLoader /** - * 获取一个 [Setting] 实例 + * 从 [JarPluginLoader.settingStorage] 获取一个 [Setting] 实例 */ @JvmDefault public fun loadSetting(clazz: Class): T = loader.settingStorage.load(this, clazz) - // TODO: 2020/7/11 document onLoad, onEnable, onDisable + /** + * 在插件被加载时调用. 只会被调用一次. + */ @JvmDefault public fun onLoad() { } + /** + * 在插件被启用时调用, 可能会被调用多次 + */ @JvmDefault public fun onEnable() { } + /** + * 在插件被关闭时调用, 可能会被调用多次 + */ @JvmDefault public fun onDisable() { } diff --git a/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/util/ResourceContainer.kt b/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/util/ResourceContainer.kt index 2d6952ce2..0184bb302 100644 --- a/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/util/ResourceContainer.kt +++ b/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/util/ResourceContainer.kt @@ -20,7 +20,7 @@ import kotlin.reflect.KClass /** * 资源容器. * - * 资源容器可能使用 [Class.getResourceAsStream], 也可能使用其他方式, 取决于实现方式. + * 资源容器可能使用 [Class.getResourceAsStream], [ClassLoader.getResourceAsStream], 也可能使用其他方式, 取决于实现方式. * * @see JvmPlugin [JvmPlugin] 通过 [ClassLoader.getResourceAsStream] 实现 [ResourceContainer], 使用 [ResourceContainer.asResourceContainer] */ @@ -46,13 +46,15 @@ public interface ResourceContainer { public companion object { /** * 使用 [Class.getResourceAsStream] 读取资源文件 + * + * @see ClassLoader.asResourceContainer */ @JvmStatic @JvmName("create") public fun KClass<*>.asResourceContainer(): ResourceContainer = this.java.asResourceContainer() /** - * 使用 [Class.getResourceAsStream] 读取资源文件 + * 使用 [ClassLoader.getResourceAsStream] 读取资源文件 */ @JvmStatic @JvmName("create") diff --git a/buildSrc/src/main/kotlin/Versions.kt b/buildSrc/src/main/kotlin/Versions.kt index fa5bb9060..bf11e675d 100644 --- a/buildSrc/src/main/kotlin/Versions.kt +++ b/buildSrc/src/main/kotlin/Versions.kt @@ -18,7 +18,7 @@ object Versions { const val core = "1.2.1" - const val console = "1.0-M2" + const val console = "1.0-M2-1" const val consoleGraphical = "0.0.7" const val consoleTerminal = "0.1.0" const val consolePure = console @@ -36,5 +36,5 @@ object Versions { const val bintray = "1.8.5" - const val blockingBridge = "1.0.2" + const val blockingBridge = "1.0.3" } \ No newline at end of file