mirror of
https://github.com/mamoe/mirai.git
synced 2025-01-11 02:50:15 +08:00
Fix data comparison, fix commands
This commit is contained in:
parent
6ec3390b8d
commit
a6bd7b7d63
@ -183,7 +183,7 @@ public object PluginDataExtensions {
|
|||||||
|
|
||||||
private fun <K, V> createDelegateInstance(
|
private fun <K, V> createDelegateInstance(
|
||||||
origin: SerializerAwareValue<MutableMap<K, V>>,
|
origin: SerializerAwareValue<MutableMap<K, V>>,
|
||||||
defaultValueComputer: (K) -> V
|
defaultValueComputer: (K) -> V,
|
||||||
): MutableMap<K, V> {
|
): MutableMap<K, V> {
|
||||||
return object : MutableMap<K, V>, AbstractMap<K, V>() {
|
return object : MutableMap<K, V>, AbstractMap<K, V>() {
|
||||||
override val entries: MutableSet<MutableMap.MutableEntry<K, V>> get() = origin.value.entries
|
override val entries: MutableSet<MutableMap.MutableEntry<K, V>> get() = origin.value.entries
|
||||||
|
@ -58,6 +58,26 @@ public class SerializableValue<T>(
|
|||||||
) : Value<T> by delegate, SerializerAwareValue<T> {
|
) : Value<T> by delegate, SerializerAwareValue<T> {
|
||||||
public override fun toString(): String = delegate.toString()
|
public override fun toString(): String = delegate.toString()
|
||||||
|
|
||||||
|
public override fun equals(other: Any?): Boolean {
|
||||||
|
if (other === this) return true
|
||||||
|
if (other?.javaClass != this.javaClass) return false
|
||||||
|
|
||||||
|
@Suppress("UNCHECKED_CAST")
|
||||||
|
other as SerializableValue<T>
|
||||||
|
if (other.delegate != this.delegate) return false
|
||||||
|
// if (other.serializer != this.serializer) return false
|
||||||
|
// TODO: 2020/9/9 serializers should be checked here, but it will cause incomparable issue when putting a SerializableValue as a Key
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun hashCode(): Int {
|
||||||
|
@Suppress("UnnecessaryVariable", "CanBeVal")
|
||||||
|
var result = delegate.hashCode()
|
||||||
|
// result = 31 * result + serializer.hashCode()
|
||||||
|
// TODO: 2020/9/9 serializers should be checked here, but it will cause incomparable issue when putting a SerializableValue as a Key
|
||||||
|
return result
|
||||||
|
}
|
||||||
|
|
||||||
public companion object {
|
public companion object {
|
||||||
@JvmStatic
|
@JvmStatic
|
||||||
@JvmName("create")
|
@JvmName("create")
|
||||||
|
@ -196,4 +196,21 @@ internal class LazyReferenceValueImpl<T> : ReferenceValue<T>, AbstractValueImpl<
|
|||||||
initialied = true
|
initialied = true
|
||||||
valueField = value
|
valueField = value
|
||||||
}
|
}
|
||||||
|
|
||||||
|
override fun toString(): String {
|
||||||
|
return valueField.toString()
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun equals(other: Any?): Boolean {
|
||||||
|
if (other === this) return true
|
||||||
|
if (other?.javaClass != this.javaClass) return false
|
||||||
|
|
||||||
|
other as LazyReferenceValueImpl<*>
|
||||||
|
if (other.valueField != valueField) return false
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun hashCode(): Int {
|
||||||
|
return valueField?.hashCode() ?: 0
|
||||||
|
}
|
||||||
}
|
}
|
@ -17,7 +17,9 @@ import net.mamoe.mirai.console.util.ConsoleExperimentalAPI
|
|||||||
/**
|
/**
|
||||||
* 一个权限节点.
|
* 一个权限节点.
|
||||||
*
|
*
|
||||||
* 由 [PermissionService] 实现不同, [Permission] 可能会有多种实例. 但一个权限总是拥有确定的 [id]
|
* 由 [PermissionService] 实现不同, [Permission] 可能会有多种实例. 但一个权限总是拥有确定的 [id].
|
||||||
|
*
|
||||||
|
* 请不要手动实现这个接口. 总是从 [PermissionService.register] 获得实例.
|
||||||
*/
|
*/
|
||||||
@ExperimentalPermission
|
@ExperimentalPermission
|
||||||
public interface Permission {
|
public interface Permission {
|
||||||
@ -26,15 +28,20 @@ public interface Permission {
|
|||||||
public val parentId: PermissionId
|
public val parentId: PermissionId
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@OptIn(ExperimentalPermission::class)
|
||||||
|
private val ROOT_PERMISSION_ID = PermissionId("*", "*")
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 所有权限的父权限.
|
* 所有权限的父权限.
|
||||||
*/
|
*/
|
||||||
|
@get:JvmName("getRootPermission")
|
||||||
@ExperimentalPermission
|
@ExperimentalPermission
|
||||||
public object RootPermission :
|
public val RootPermission: Permission by lazy {
|
||||||
Permission {
|
PermissionService.INSTANCE.register(
|
||||||
override val id: PermissionId = PermissionId("*", "*")
|
ROOT_PERMISSION_ID,
|
||||||
override val description: String get() = "The parent of any permission"
|
"The parent of any permission",
|
||||||
override val parentId: PermissionId get() = id
|
ROOT_PERMISSION_ID
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ConsoleExperimentalAPI
|
@ConsoleExperimentalAPI
|
||||||
|
@ -189,7 +189,7 @@ internal class TestCommand {
|
|||||||
|
|
||||||
val composite = object : CompositeCommand(
|
val composite = object : CompositeCommand(
|
||||||
ConsoleCommandOwner,
|
ConsoleCommandOwner,
|
||||||
"test",
|
"test22",
|
||||||
overrideContext = buildCommandArgumentContext {
|
overrideContext = buildCommandArgumentContext {
|
||||||
add(object : CommandArgumentParser<MyClass> {
|
add(object : CommandArgumentParser<MyClass> {
|
||||||
override fun parse(raw: String, sender: CommandSender): MyClass {
|
override fun parse(raw: String, sender: CommandSender): MyClass {
|
||||||
@ -234,7 +234,7 @@ internal class TestCommand {
|
|||||||
|
|
||||||
simple.withRegistration {
|
simple.withRegistration {
|
||||||
// assertEquals("xxx", withTesting { simple.execute(sender, "xxx") })
|
// assertEquals("xxx", withTesting { simple.execute(sender, "xxx") })
|
||||||
assertEquals("xxx", withTesting { println(sender.executeCommand("/test xxx")) })
|
assertEquals("xxx", withTesting { assertSuccess(sender.executeCommand("/test xxx")) })
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,11 @@
|
|||||||
|
package net.mamoe.mirai.console.permission
|
||||||
|
|
||||||
|
import org.junit.jupiter.api.Test
|
||||||
|
|
||||||
|
internal class PermissionsBasicsTest {
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun parentsWithSelfSequence() {
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user