From 048a10cc508c5f94330ce85912a6ed218fc5a357 Mon Sep 17 00:00:00 2001 From: Him188 Date: Tue, 8 Sep 2020 12:34:20 +0800 Subject: [PATCH] Fix serializers for StorablePermissionService.SaveData --- .../permission/BuiltInPermissionServices.kt | 7 +++- .../permission/StorablePermissionService.kt | 36 ++++++++++++++++--- 2 files changed, 37 insertions(+), 6 deletions(-) diff --git a/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/permission/BuiltInPermissionServices.kt b/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/permission/BuiltInPermissionServices.kt index 42989b3c5..aa4a36d70 100644 --- a/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/permission/BuiltInPermissionServices.kt +++ b/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/permission/BuiltInPermissionServices.kt @@ -12,6 +12,7 @@ package net.mamoe.mirai.console.permission import net.mamoe.mirai.console.data.AutoSavePluginConfig import java.util.concurrent.ConcurrentHashMap import kotlin.reflect.KClass +import kotlin.reflect.full.createType @ExperimentalPermission @@ -84,5 +85,9 @@ internal object BuiltInPermissionService : AbstractConcurrentPermissionService

= - StorablePermissionService.ConcurrentSaveData("PermissionService", AutoSavePluginConfig()) + StorablePermissionService.ConcurrentSaveData( + PermissionImpl::class.createType(), + "PermissionService", + AutoSavePluginConfig() + ) } \ No newline at end of file diff --git a/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/permission/StorablePermissionService.kt b/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/permission/StorablePermissionService.kt index e04bf965a..f0b37efba 100644 --- a/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/permission/StorablePermissionService.kt +++ b/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/permission/StorablePermissionService.kt @@ -3,8 +3,13 @@ package net.mamoe.mirai.console.permission import net.mamoe.mirai.console.data.PluginConfig import net.mamoe.mirai.console.data.PluginDataExtensions.withDefault import net.mamoe.mirai.console.data.value +import net.mamoe.mirai.console.data.valueFromKType import java.util.concurrent.ConcurrentHashMap import java.util.concurrent.CopyOnWriteArrayList +import kotlin.reflect.KType +import kotlin.reflect.KTypeProjection +import kotlin.reflect.KVariance +import kotlin.reflect.full.createType @ExperimentalPermission public interface StorablePermissionService

: PermissionService

{ @@ -14,13 +19,34 @@ public interface StorablePermissionService

: PermissionService

( + public class ConcurrentSaveData

private constructor( + permissionType: KType, public override val saveName: String, - delegate: PluginConfig + delegate: PluginConfig, + @Suppress("UNUSED_PARAMETER") primaryConstructorMark: Any? ) : PluginConfig by delegate { - public val permissions: MutableMap by value>(ConcurrentHashMap()) + public val permissions: MutableMap + by valueFromKType>( + MutableMap::class.createType( + listOf( + KTypeProjection(KVariance.INVARIANT, PermissionId::class.createType()), + KTypeProjection(KVariance.INVARIANT, permissionType), + ) + ), + ConcurrentHashMap() + ) - public val grantedPermissionMap: MutableMap> by - value>>(ConcurrentHashMap()).withDefault { CopyOnWriteArrayList() } + public val grantedPermissionMap: MutableMap> + by value>>(ConcurrentHashMap()) + .withDefault { CopyOnWriteArrayList() } + + public companion object { + @JvmStatic + public operator fun

invoke( + permissionType: KType, + saveName: String, + delegate: PluginConfig, + ): ConcurrentSaveData

= ConcurrentSaveData(permissionType, saveName, delegate, null) + } } }