And they dont stop coming

This commit is contained in:
Auxilor
2022-03-23 14:21:25 +00:00
parent ddcef7cf0c
commit c5b47ed073
2 changed files with 24 additions and 24 deletions

View File

@@ -13,6 +13,28 @@ import org.yaml.snakeyaml.representer.Representer
val ConfigType.handler: ConfigTypeHandler
get() = if (this == ConfigType.JSON) JSONConfigTypeHandler else YamlConfigTypeHandler
fun Map<*, *>.ensureTypesForConfig(): Map<String, Any?> {
val building = mutableMapOf<String, Any?>()
for (entry in this.entries) {
val value = entry.value?.let {
if (it is Map<*, *>) {
it.ensureTypesForConfig()
} else {
it
}
}
if (entry.key == null || value == null) {
continue
}
building[entry.key.toString()] = value
}
return building
}
abstract class ConfigTypeHandler(
val type: ConfigType
) {
@@ -21,29 +43,7 @@ abstract class ConfigTypeHandler(
return emptyMap()
}
return ensureMapTypes(parseToMap(input))
}
private fun ensureMapTypes(map: Map<*, *>): Map<String, Any?> {
val building = mutableMapOf<String, Any?>()
for (entry in map.entries) {
val value = entry.value?.let {
if (it is Map<*, *>) {
ensureMapTypes(it.toMutableMap())
} else {
it
}
}
if (entry.key == null) {
continue
}
building[entry.key.toString()] = value
}
return building
return parseToMap(input).ensureTypesForConfig()
}
protected abstract fun parseToMap(input: String): Map<*, *>

View File

@@ -16,7 +16,7 @@ open class EcoConfig(
fun init(values: Map<String, Any?>) {
this.values.clear()
this.values.putAll(values)
this.values.putAll(values.ensureTypesForConfig())
}
override fun clearCache() {