Make ObservedConfigValue implement GetterSetter
This commit is contained in:
parent
ad54cfeb9b
commit
7ba96185e5
@ -2,12 +2,13 @@ package ru.dbotthepony.mc.otm.config
|
||||
|
||||
import net.minecraftforge.common.ForgeConfigSpec.ConfigValue
|
||||
import org.apache.logging.log4j.LogManager
|
||||
import ru.dbotthepony.mc.otm.core.GetterSetter
|
||||
import java.util.function.Consumer
|
||||
import java.util.function.Supplier
|
||||
import kotlin.properties.ReadWriteProperty
|
||||
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
|
||||
private var observedValue: String? = null
|
||||
private var cachedValue: V? = null
|
||||
@ -43,7 +44,7 @@ abstract class ObservedConfigValue<V : Any>(val parent: ConfigValue<String>) : R
|
||||
return cachedValue ?: throw ConcurrentModificationException()
|
||||
}
|
||||
|
||||
override fun getValue(thisRef: Any, property: KProperty<*>): V {
|
||||
override fun getValue(thisRef: Any?, property: KProperty<*>): V {
|
||||
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)
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user