mirror of
https://github.com/mamoe/mirai.git
synced 2025-01-25 15:40:28 +08:00
Implement PluginConfig, update docs
This commit is contained in:
parent
f862f7d4f5
commit
a4d5a4cbf2
@ -76,6 +76,7 @@ public interface MiraiConsoleImplementation : CoroutineScope {
|
||||
public val consoleCommandSender: ConsoleCommandSender
|
||||
|
||||
public val dataStorageForJarPluginLoader: PluginDataStorage
|
||||
public val configStorageForJarPluginLoader: PluginDataStorage
|
||||
public val dataStorageForBuiltIns: PluginDataStorage
|
||||
|
||||
public companion object {
|
||||
|
@ -12,7 +12,10 @@ package net.mamoe.mirai.console.data
|
||||
/**
|
||||
* 一个插件的配置数据, 用于和用户交互.
|
||||
*
|
||||
* 用户可通过 mirai-console 前端修改这些配置, 修改会自动写入这个对象中.
|
||||
* 用户可通过 mirai-console 前端 (如在 Android 中可视化实现) 修改这些配置, 修改会自动写入这个对象中.
|
||||
*
|
||||
* **提示**:
|
||||
* 插件内部的数据应用 [PluginData] 存储, 而不能使用 [PluginConfig].
|
||||
*/
|
||||
@ExperimentalPluginConfig
|
||||
public interface PluginConfig : PluginData
|
@ -59,6 +59,7 @@ internal object MiraiConsoleImplementationBridge : CoroutineScope, MiraiConsoleI
|
||||
override val consoleCommandSender: ConsoleCommandSender get() = instance.consoleCommandSender
|
||||
|
||||
override val dataStorageForJarPluginLoader: PluginDataStorage get() = instance.dataStorageForJarPluginLoader
|
||||
override val configStorageForJarPluginLoader: PluginDataStorage get() = instance.configStorageForJarPluginLoader
|
||||
override val dataStorageForBuiltIns: PluginDataStorage get() = instance.dataStorageForBuiltIns
|
||||
|
||||
init {
|
||||
|
@ -13,14 +13,12 @@ import kotlin.reflect.KClass
|
||||
* 当任一相关 [Value] 的值被修改时, 将在一段时间无其他修改时保存
|
||||
*
|
||||
* 若 [AutoSavePluginDataHolder.coroutineContext] 含有 [Job], 则 [AutoSavePluginData] 会通过 [Job.invokeOnCompletion] 在 Job 完结时触发自动保存.
|
||||
*
|
||||
* @see loadPluginData
|
||||
*/
|
||||
internal open class AutoSavePluginData(
|
||||
private val owner: AutoSavePluginDataHolder,
|
||||
internal val originPluginDataClass: KClass<out PluginData>
|
||||
) :
|
||||
AbstractPluginData(), PluginConfig {
|
||||
) : AbstractPluginData(), PluginConfig {
|
||||
|
||||
private lateinit var storage: PluginDataStorage
|
||||
|
||||
override fun setStorage(storage: PluginDataStorage) {
|
||||
|
@ -1,3 +1,12 @@
|
||||
/*
|
||||
* Copyright 2019-2020 Mamoe Technologies and contributors.
|
||||
*
|
||||
* 此源代码的使用受 GNU AFFERO GENERAL PUBLIC LICENSE version 3 with Mamoe Exceptions 许可证的约束, 可以在以下链接找到该许可证.
|
||||
* Use of this source code is governed by the GNU AFFERO GENERAL PUBLIC LICENSE version 3 with Mamoe Exceptions license that can be found via the following link.
|
||||
*
|
||||
* https://github.com/mamoe/mirai/blob/master/LICENSE
|
||||
*/
|
||||
|
||||
package net.mamoe.mirai.console.internal.data
|
||||
|
||||
import net.mamoe.mirai.console.data.*
|
||||
|
@ -1,3 +1,12 @@
|
||||
/*
|
||||
* Copyright 2019-2020 Mamoe Technologies and contributors.
|
||||
*
|
||||
* 此源代码的使用受 GNU AFFERO GENERAL PUBLIC LICENSE version 3 with Mamoe Exceptions 许可证的约束, 可以在以下链接找到该许可证.
|
||||
* Use of this source code is governed by the GNU AFFERO GENERAL PUBLIC LICENSE version 3 with Mamoe Exceptions license that can be found via the following link.
|
||||
*
|
||||
* https://github.com/mamoe/mirai/blob/master/LICENSE
|
||||
*/
|
||||
|
||||
package net.mamoe.mirai.console.internal.data
|
||||
|
||||
import net.mamoe.mirai.console.data.*
|
||||
|
@ -1,11 +0,0 @@
|
||||
/*
|
||||
* Copyright 2019-2020 Mamoe Technologies and contributors.
|
||||
*
|
||||
* 此源代码的使用受 GNU AFFERO GENERAL PUBLIC LICENSE version 3 with Mamoe Exceptions 许可证的约束, 可以在以下链接找到该许可证.
|
||||
* Use of this source code is governed by the GNU AFFERO GENERAL PUBLIC LICENSE version 3 with Mamoe Exceptions license that can be found via the following link.
|
||||
*
|
||||
* https://github.com/mamoe/mirai/blob/master/LICENSE
|
||||
*/
|
||||
|
||||
package net.mamoe.mirai.console.internal.data
|
||||
|
@ -1,11 +0,0 @@
|
||||
/*
|
||||
* Copyright 2020 Mamoe Technologies and contributors.
|
||||
*
|
||||
* 此源代码的使用受 GNU AFFERO GENERAL PUBLIC LICENSE version 3 许可证的约束, 可以在以下链接找到该许可证.
|
||||
* Use of this source code is governed by the GNU AGPLv3 license that can be found through the following link.
|
||||
*
|
||||
* https://github.com/mamoe/mirai/blob/master/LICENSE
|
||||
*/
|
||||
|
||||
package net.mamoe.mirai.console.internal.data
|
||||
|
@ -99,7 +99,6 @@ internal fun PluginData.valueFromKTypeImpl(type: KType): SerializerAwareValue<*>
|
||||
}
|
||||
}
|
||||
|
||||
@PublishedApi
|
||||
internal fun KClass<*>.createInstanceSmart(): Any? {
|
||||
return when (this) {
|
||||
MutableMap::class,
|
||||
|
@ -32,6 +32,9 @@ internal object JarPluginLoaderImpl :
|
||||
CoroutineScope,
|
||||
JarPluginLoader {
|
||||
|
||||
override val configStorage: PluginDataStorage
|
||||
get() = MiraiConsoleImplementationBridge.dataStorageForJarPluginLoader
|
||||
|
||||
private val logger: MiraiLogger = MiraiConsole.newLogger(JarPluginLoader::class.simpleName!!)
|
||||
|
||||
@ConsoleExperimentalAPI
|
||||
|
@ -25,6 +25,12 @@ public interface JarPluginLoader : CoroutineScope, FilePluginLoader<JvmPlugin, J
|
||||
@ConsoleExperimentalAPI
|
||||
public val dataStorage: PluginDataStorage
|
||||
|
||||
/**
|
||||
* [JvmPlugin.loadPluginData] 默认使用的实例
|
||||
*/
|
||||
@ConsoleExperimentalAPI
|
||||
public val configStorage: PluginDataStorage
|
||||
|
||||
public companion object INSTANCE : JarPluginLoader by JarPluginLoaderImpl {
|
||||
@Suppress("EXTENSION_SHADOWED_BY_MEMBER")
|
||||
override val JvmPlugin.description: JvmPluginDescription
|
||||
|
@ -50,16 +50,16 @@ public interface JvmPlugin : Plugin, CoroutineScope,
|
||||
get() = JarPluginLoader
|
||||
|
||||
/**
|
||||
* 从 [JarPluginLoader.dataStorage] 获取一个 [PluginData] 实例
|
||||
* 读取一个 [PluginData] 实例
|
||||
*/
|
||||
@JvmDefault
|
||||
public fun <T : PluginData> loadPluginData(clazz: Class<T>): T = loader.dataStorage.load(this, clazz)
|
||||
|
||||
/**
|
||||
* 从 [JarPluginLoader.dataStorage] 获取一个 [PluginData] 实例
|
||||
* 读取一个 [PluginConfig] 实例
|
||||
*/
|
||||
@JvmDefault
|
||||
public fun <T : PluginConfig> loadPluginConfig(clazz: Class<T>): T = loader.dataStorage.load(this, clazz)
|
||||
public fun <T : PluginConfig> loadPluginConfig(clazz: Class<T>): T = loader.configStorage.load(this, clazz)
|
||||
|
||||
/**
|
||||
* 在插件被加载时调用. 只会被调用一次.
|
||||
@ -84,25 +84,25 @@ public interface JvmPlugin : Plugin, CoroutineScope,
|
||||
}
|
||||
|
||||
/**
|
||||
* 读取一个插件数据.
|
||||
* 读取一个 [PluginData] 实例
|
||||
*/
|
||||
@JvmSynthetic
|
||||
public inline fun <T : PluginData> JvmPlugin.loadPluginData(clazz: KClass<T>): T = this.loadPluginData(clazz.java)
|
||||
|
||||
/**
|
||||
* 读取一个插件数据.
|
||||
* 读取一个 [PluginData] 实例
|
||||
*/
|
||||
@JvmSynthetic
|
||||
public inline fun <reified T : PluginData> JvmPlugin.loadPluginData(): T = this.loadPluginData(T::class)
|
||||
|
||||
/**
|
||||
* 读取一个插件配置.
|
||||
* 读取一个 [PluginConfig] 实例
|
||||
*/
|
||||
@JvmSynthetic
|
||||
public inline fun <T : PluginConfig> JvmPlugin.loadPluginConfig(clazz: KClass<T>): T = this.loadPluginConfig(clazz.java)
|
||||
|
||||
/**
|
||||
* 读取一个插件配置.
|
||||
* 读取一个 [PluginConfig] 实例
|
||||
*/
|
||||
@JvmSynthetic
|
||||
public inline fun <reified T : PluginConfig> JvmPlugin.loadPluginConfig(): T = this.loadPluginConfig(T::class)
|
Loading…
Reference in New Issue
Block a user