Make ObservedConfigValue implement GetterSetter

This commit is contained in:
DBotThePony 2023-07-23 17:56:14 +07:00
parent ad54cfeb9b
commit 7ba96185e5
Signed by: DBot
GPG Key ID: DCC23B5715498507

View File

@ -2,12 +2,13 @@ package ru.dbotthepony.mc.otm.config
import net.minecraftforge.common.ForgeConfigSpec.ConfigValue import net.minecraftforge.common.ForgeConfigSpec.ConfigValue
import org.apache.logging.log4j.LogManager import org.apache.logging.log4j.LogManager
import ru.dbotthepony.mc.otm.core.GetterSetter
import java.util.function.Consumer import java.util.function.Consumer
import java.util.function.Supplier import java.util.function.Supplier
import kotlin.properties.ReadWriteProperty import kotlin.properties.ReadWriteProperty
import kotlin.reflect.KProperty import kotlin.reflect.KProperty
abstract class ObservedConfigValue<V : Any>(val parent: ConfigValue<String>) : ReadWriteProperty<Any, V>, Supplier<V>, Consumer<V> { abstract class ObservedConfigValue<V : Any>(val parent: ConfigValue<String>) : GetterSetter<V> {
var rawValue: String by parent var rawValue: String by parent
private var observedValue: String? = null private var observedValue: String? = null
private var cachedValue: V? = null private var cachedValue: V? = null
@ -43,7 +44,7 @@ abstract class ObservedConfigValue<V : Any>(val parent: ConfigValue<String>) : R
return cachedValue ?: throw ConcurrentModificationException() return cachedValue ?: throw ConcurrentModificationException()
} }
override fun getValue(thisRef: Any, property: KProperty<*>): V { override fun getValue(thisRef: Any?, property: KProperty<*>): V {
return get() return get()
} }
@ -64,7 +65,7 @@ abstract class ObservedConfigValue<V : Any>(val parent: ConfigValue<String>) : R
} }
} }
override fun setValue(thisRef: Any, property: KProperty<*>, value: V) { override fun setValue(thisRef: Any?, property: KProperty<*>, value: V) {
accept(value) accept(value)
} }