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 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)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user