mirror of
https://github.com/mamoe/mirai.git
synced 2025-01-10 18:40:15 +08:00
Fix serializers for StorablePermissionService.SaveData
This commit is contained in:
parent
900eac58b4
commit
048a10cc50
@ -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<P
|
||||
PermissionImpl(id, description, base)
|
||||
|
||||
override val config: StorablePermissionService.ConcurrentSaveData<PermissionImpl> =
|
||||
StorablePermissionService.ConcurrentSaveData("PermissionService", AutoSavePluginConfig())
|
||||
StorablePermissionService.ConcurrentSaveData(
|
||||
PermissionImpl::class.createType(),
|
||||
"PermissionService",
|
||||
AutoSavePluginConfig()
|
||||
)
|
||||
}
|
@ -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<P : Permission> : PermissionService<P> {
|
||||
@ -14,13 +19,34 @@ public interface StorablePermissionService<P : Permission> : PermissionService<P
|
||||
public val config: PluginConfig
|
||||
|
||||
@ExperimentalPermission
|
||||
public class ConcurrentSaveData<P : Permission>(
|
||||
public class ConcurrentSaveData<P : Permission> 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<PermissionId, P> by value<MutableMap<PermissionId, P>>(ConcurrentHashMap())
|
||||
public val permissions: MutableMap<PermissionId, P>
|
||||
by valueFromKType<MutableMap<PermissionId, P>>(
|
||||
MutableMap::class.createType(
|
||||
listOf(
|
||||
KTypeProjection(KVariance.INVARIANT, PermissionId::class.createType()),
|
||||
KTypeProjection(KVariance.INVARIANT, permissionType),
|
||||
)
|
||||
),
|
||||
ConcurrentHashMap()
|
||||
)
|
||||
|
||||
public val grantedPermissionMap: MutableMap<PermissionId, MutableCollection<PermissibleIdentifier>> by
|
||||
value<MutableMap<PermissionId, MutableCollection<PermissibleIdentifier>>>(ConcurrentHashMap()).withDefault { CopyOnWriteArrayList() }
|
||||
public val grantedPermissionMap: MutableMap<PermissionId, MutableCollection<PermissibleIdentifier>>
|
||||
by value<MutableMap<PermissionId, MutableCollection<PermissibleIdentifier>>>(ConcurrentHashMap())
|
||||
.withDefault { CopyOnWriteArrayList() }
|
||||
|
||||
public companion object {
|
||||
@JvmStatic
|
||||
public operator fun <P : Permission> invoke(
|
||||
permissionType: KType,
|
||||
saveName: String,
|
||||
delegate: PluginConfig,
|
||||
): ConcurrentSaveData<P> = ConcurrentSaveData(permissionType, saveName, delegate, null)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user