From 09d444da5895c20ee99c9b9594b8289033184147 Mon Sep 17 00:00:00 2001 From: Auxilor Date: Sat, 7 Aug 2021 13:18:36 +0100 Subject: [PATCH] Added format cache to yaml configs --- .../config/yaml/EcoYamlConfigWrapper.kt | 47 ++++++++++++------- 1 file changed, 29 insertions(+), 18 deletions(-) diff --git a/eco-core/core-backend/src/main/kotlin/com/willfp/eco/internal/config/yaml/EcoYamlConfigWrapper.kt b/eco-core/core-backend/src/main/kotlin/com/willfp/eco/internal/config/yaml/EcoYamlConfigWrapper.kt index 88b02004..6fab9e5a 100644 --- a/eco-core/core-backend/src/main/kotlin/com/willfp/eco/internal/config/yaml/EcoYamlConfigWrapper.kt +++ b/eco-core/core-backend/src/main/kotlin/com/willfp/eco/internal/config/yaml/EcoYamlConfigWrapper.kt @@ -151,26 +151,28 @@ open class EcoYamlConfigWrapper : Config { } override fun getString(path: String): String { - return if (cache.containsKey(path)) { - (cache[path] as String) - } else { - cache[path] = StringUtils.format( - handle.getString(path, "")!! - ) - getString(path) - } + return getString(path, true) } override fun getString( path: String, format: Boolean ): String { - return if (cache.containsKey(path)) { - (cache[path] as String) + if (format) { + return if (cache.containsKey("$path\$FMT")) { + cache["$path\$FMT"] as String + } else { + val string: String = handle.getString(path, "")!! + cache["$path\$FMT"] = StringUtils.format(string) + getString(path, format) + } } else { - val string: String = handle.getString(path, "")!! - cache[path] = if (format) StringUtils.format(string) else string - getString(path) + return if (cache.containsKey(path)) { + cache[path] as String + } else { + cache[path] = handle.getString(path, "")!! + getString(path) + } } } @@ -201,12 +203,21 @@ open class EcoYamlConfigWrapper : Config { path: String, format: Boolean ): List { - return if (cache.containsKey(path)) { - if (format) StringUtils.formatList((cache[path] as List)) else cache[path] as List + if (format) { + return if (cache.containsKey("$path\$FMT")) { + cache["$path\$FMT"] as List + } else { + cache["$path\$FMT"] = StringUtils.formatList(if (has(path)) ArrayList(handle.getStringList(path)) else ArrayList()) + getStrings(path, true) + } } else { - cache[path] = - if (has(path)) ArrayList(handle.getStringList(path)) else ArrayList() - getStrings(path) + return if (cache.containsKey(path)) { + cache[path] as List + } else { + cache[path] = + if (has(path)) ArrayList(handle.getStringList(path)) else ArrayList() + getStrings(path, false) + } } }