Compare commits
3 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
ff61527939 | ||
|
|
7ff578f89b | ||
|
|
27da03e8db |
@@ -16,11 +16,16 @@ open class EcoConfig(
|
|||||||
private val values = ConcurrentHashMap<String, Any?>()
|
private val values = ConcurrentHashMap<String, Any?>()
|
||||||
|
|
||||||
@Transient
|
@Transient
|
||||||
var injections = ConcurrentHashMap<String, InjectablePlaceholder>()
|
private val injections = mutableMapOf<String, InjectablePlaceholder>()
|
||||||
|
|
||||||
fun init(values: Map<String, Any?>) {
|
@Transient
|
||||||
|
private var injectionHash = 0
|
||||||
|
|
||||||
|
fun init(values: Map<String, Any?>, injections: Map<String, InjectablePlaceholder>) {
|
||||||
this.values.clear()
|
this.values.clear()
|
||||||
this.values.putAll(values.normalizeToConfig(this.type))
|
this.values.putAll(values.normalizeToConfig(this.type))
|
||||||
|
|
||||||
|
this.addInjectablePlaceholder(injections.values)
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun toPlaintext(): String {
|
override fun toPlaintext(): String {
|
||||||
@@ -179,6 +184,7 @@ open class EcoConfig(
|
|||||||
override fun addInjectablePlaceholder(placeholders: Iterable<InjectablePlaceholder>) {
|
override fun addInjectablePlaceholder(placeholders: Iterable<InjectablePlaceholder>) {
|
||||||
for (placeholder in placeholders) {
|
for (placeholder in placeholders) {
|
||||||
injections[placeholder.pattern.pattern()] = placeholder
|
injections[placeholder.pattern.pattern()] = placeholder
|
||||||
|
injectionHash = injectionHash xor placeholder.hashCode()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -188,6 +194,7 @@ open class EcoConfig(
|
|||||||
|
|
||||||
override fun clearInjectedPlaceholders() {
|
override fun clearInjectedPlaceholders() {
|
||||||
injections.clear()
|
injections.clear()
|
||||||
|
injectionHash = 0 // Reset the hash
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun toMap(): MutableMap<String, Any?> {
|
override fun toMap(): MutableMap<String, Any?> {
|
||||||
@@ -239,18 +246,6 @@ open class EcoConfig(
|
|||||||
}
|
}
|
||||||
|
|
||||||
override fun hashCode(): Int {
|
override fun hashCode(): Int {
|
||||||
/*
|
|
||||||
The keys are completely redundant, as they are only used to prevent
|
|
||||||
duplicate keys in the map. Therefore, we can ignore them and just
|
|
||||||
hash the actual placeholder values.
|
|
||||||
*/
|
|
||||||
|
|
||||||
var injectionHash = 0
|
|
||||||
|
|
||||||
injections.forEachValue(5) {
|
|
||||||
injectionHash = injectionHash xor (it.hashCode() shl 5)
|
|
||||||
}
|
|
||||||
|
|
||||||
// hashCode() has to compute extremely quickly, so we're using bitwise, because why not?
|
// hashCode() has to compute extremely quickly, so we're using bitwise, because why not?
|
||||||
// Fucking filthy to use identityHashCode here, but it should be extremely fast
|
// Fucking filthy to use identityHashCode here, but it should be extremely fast
|
||||||
val identityHash = System.identityHashCode(this)
|
val identityHash = System.identityHashCode(this)
|
||||||
|
|||||||
@@ -10,7 +10,6 @@ class EcoConfigSection(
|
|||||||
injections: Map<String, InjectablePlaceholder> = emptyMap()
|
injections: Map<String, InjectablePlaceholder> = emptyMap()
|
||||||
) : EcoConfig(type) {
|
) : EcoConfig(type) {
|
||||||
init {
|
init {
|
||||||
this.init(values)
|
this.init(values, injections)
|
||||||
this.injections = ConcurrentHashMap(injections)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -91,7 +91,7 @@ open class EcoLoadableConfig(
|
|||||||
protected fun init(reader: Reader) {
|
protected fun init(reader: Reader) {
|
||||||
val string = reader.readToString()
|
val string = reader.readToString()
|
||||||
makeHeader(string)
|
makeHeader(string)
|
||||||
super.init(type.toMap(string))
|
super.init(type.toMap(string), emptyMap())
|
||||||
}
|
}
|
||||||
|
|
||||||
fun init(file: File) {
|
fun init(file: File) {
|
||||||
|
|||||||
@@ -50,7 +50,7 @@ open class EcoUpdatableConfig(
|
|||||||
val reader = BufferedReader(InputStreamReader(newIn, StandardCharsets.UTF_8))
|
val reader = BufferedReader(InputStreamReader(newIn, StandardCharsets.UTF_8))
|
||||||
|
|
||||||
val config = EcoConfigSection(type, emptyMap())
|
val config = EcoConfigSection(type, emptyMap())
|
||||||
config.init(type.toMap(reader.readToString()))
|
config.init(type.toMap(reader.readToString()), emptyMap())
|
||||||
return config
|
return config
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,3 +1,3 @@
|
|||||||
version = 6.65.2
|
version = 6.65.3
|
||||||
plugin-name = eco
|
plugin-name = eco
|
||||||
kotlin.code.style = official
|
kotlin.code.style = official
|
||||||
Reference in New Issue
Block a user