Fix internal PluginData deserializing: MutableCollection.patchImpl

This commit is contained in:
Him188 2020-09-01 22:24:05 +08:00
parent e676117744
commit aca8582bdf
3 changed files with 5 additions and 3 deletions

View File

@ -14,7 +14,6 @@ package net.mamoe.mirai.console.data
*
* :
* ```
* @ValueName("accounts")
* object AccountPluginData : PluginData by ... {
* @ValueName("info")
* val map: Map<String, String> by value("a" to "b")
@ -23,7 +22,7 @@ package net.mamoe.mirai.console.data
*
* 将被保存为配置 (YAML 作为示例):
* ```yaml
* accounts:
* AccountPluginData:
* info:
* a: b
* ```

View File

@ -188,7 +188,8 @@ internal fun <K, V> MutableMap<K, V>.patchImpl(_new: Map<K, V>) {
}
internal fun <C : MutableCollection<E>, E> C.patchImpl(_new: Collection<E>) {
this.retainAll(_new)
this.clear()
this.addAll(_new)
}
/**

View File

@ -18,6 +18,7 @@ import net.mamoe.mirai.console.util.ConsoleExperimentalAPI
import net.mamoe.mirai.utils.MiraiLogger
import net.mamoe.mirai.utils.SilentLogger
import net.mamoe.mirai.utils.debug
import net.mamoe.mirai.utils.warning
import net.mamoe.yamlkt.Yaml
import java.io.File
import java.nio.file.Path
@ -36,6 +37,7 @@ internal open class MultiFilePluginDataStorageImpl(
val text = getPluginDataFile(holder, instance).readText()
if (text.isNotBlank()) {
logger.warning { "Deserializing $text" }
Yaml.default.decodeFromString(instance.updaterSerializer, text)
} else {
this.store(holder, instance) // save an initial copy