diff --git a/backend/codegen/src/main/kotlin/net/mamoe/mirai/console/codegen/ValueSettingCodegen.kt b/backend/codegen/src/main/kotlin/net/mamoe/mirai/console/codegen/ValueSettingCodegen.kt index 97fba5246..8cb0fd3b2 100644 --- a/backend/codegen/src/main/kotlin/net/mamoe/mirai/console/codegen/ValueSettingCodegen.kt +++ b/backend/codegen/src/main/kotlin/net/mamoe/mirai/console/codegen/ValueSettingCodegen.kt @@ -74,8 +74,12 @@ internal abstract class ${ktType.standardName}ValueImpl : ${ktType.standardName} get() = _value ?: error("${ktType.standardName}Value.value should be initialized before get.") set(v) { if (v != this._value) { - this._value = v - onChanged() + if (this._value == null) { + this._value = v + } else { + this._value = v + onChanged() + } } } diff --git a/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/internal/data/_PrimitiveValueDeclarations.kt b/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/internal/data/_PrimitiveValueDeclarations.kt index 0cb453154..a45938375 100644 --- a/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/internal/data/_PrimitiveValueDeclarations.kt +++ b/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/internal/data/_PrimitiveValueDeclarations.kt @@ -42,8 +42,12 @@ internal abstract class ByteValueImpl : ByteValue, SerializerAwareValue, K get() = _value ?: error("ByteValue.value should be initialized before get.") set(v) { if (v != this._value) { - this._value = v - onChanged() + if (this._value == null) { + this._value = v + } else { + this._value = v + onChanged() + } } } @@ -77,8 +81,12 @@ internal abstract class ShortValueImpl : ShortValue, SerializerAwareValue get() = _value ?: error("ShortValue.value should be initialized before get.") set(v) { if (v != this._value) { - this._value = v - onChanged() + if (this._value == null) { + this._value = v + } else { + this._value = v + onChanged() + } } } @@ -110,8 +118,12 @@ internal abstract class IntValueImpl : IntValue, SerializerAwareValue, KSer get() = _value ?: error("IntValue.value should be initialized before get.") set(v) { if (v != this._value) { - this._value = v - onChanged() + if (this._value == null) { + this._value = v + } else { + this._value = v + onChanged() + } } } @@ -145,8 +157,12 @@ internal abstract class LongValueImpl : LongValue, SerializerAwareValue, K get() = _value ?: error("LongValue.value should be initialized before get.") set(v) { if (v != this._value) { - this._value = v - onChanged() + if (this._value == null) { + this._value = v + } else { + this._value = v + onChanged() + } } } @@ -180,8 +196,12 @@ internal abstract class FloatValueImpl : FloatValue, SerializerAwareValue get() = _value ?: error("FloatValue.value should be initialized before get.") set(v) { if (v != this._value) { - this._value = v - onChanged() + if (this._value == null) { + this._value = v + } else { + this._value = v + onChanged() + } } } @@ -215,8 +235,12 @@ internal abstract class DoubleValueImpl : DoubleValue, SerializerAwareValue, K get() = _value ?: error("CharValue.value should be initialized before get.") set(v) { if (v != this._value) { - this._value = v - onChanged() + if (this._value == null) { + this._value = v + } else { + this._value = v + onChanged() + } } } @@ -285,8 +313,12 @@ internal abstract class BooleanValueImpl : BooleanValue, SerializerAwareValue