diff --git a/eco-api/src/main/java/com/willfp/eco/core/config/interfaces/Config.java b/eco-api/src/main/java/com/willfp/eco/core/config/interfaces/Config.java index 5a1a1511..81dd03f6 100644 --- a/eco-api/src/main/java/com/willfp/eco/core/config/interfaces/Config.java +++ b/eco-api/src/main/java/com/willfp/eco/core/config/interfaces/Config.java @@ -524,6 +524,25 @@ public interface Config extends Cloneable { @Nullable List getDoublesOrNull(@NotNull String path); + /** + * Get a list of subsections from config. + * + * @param path The key to fetch the value from. + * @return The found value, or a blank {@link java.util.ArrayList} if not found. + */ + @NotNull + List getSubsections(@NotNull String path); + + /** + * Get a list of subsections from config. + * + * @param path The key to fetch the value from. + * @return The found value, or null if not found. + */ + @Nullable + List getSubsectionsOrNull(@NotNull String path); + + /** * Clone the config. * 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 acdbc8fc..524cdfc1 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 @@ -1,6 +1,7 @@ package com.willfp.eco.internal.config.yaml import com.willfp.eco.core.config.interfaces.Config +import com.willfp.eco.internal.config.json.EcoJSONConfigSection import com.willfp.eco.util.StringUtils import org.bukkit.configuration.ConfigurationSection import org.bukkit.configuration.file.YamlConfiguration @@ -262,6 +263,29 @@ open class EcoYamlConfigWrapper : Config { } } + override fun getSubsections(path: String): MutableList { + return if (cache.containsKey(path)) { + (cache[path] as MutableList).toMutableList() + } else { + val mapList = ArrayList(handle.getMapList(path)) as List> + val configList = mutableListOf() + for (map in mapList) { + configList.add(EcoJSONConfigSection(map)) + } + + cache[path] = if (has(path)) configList else emptyList() + getSubsections(path) + } + } + + override fun getSubsectionsOrNull(path: String): MutableList? { + return if (has(path)) { + getSubsections(path) + } else { + null + } + } + override fun clone(): Config { return EcoYamlConfigSection( YamlConfiguration.loadConfiguration(