From d3e4270f44051a2c80ec74bb0bdb7c243f7d4267 Mon Sep 17 00:00:00 2001 From: dfsek Date: Thu, 27 May 2021 19:27:15 -0700 Subject: [PATCH] cleanup ModDependentConfigSectionLoader --- .../mod/ModDependentConfigSectionLoader.java | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/common/src/main/java/com/dfsek/terra/config/loaders/mod/ModDependentConfigSectionLoader.java b/common/src/main/java/com/dfsek/terra/config/loaders/mod/ModDependentConfigSectionLoader.java index 6c5901768..7bf8baca2 100644 --- a/common/src/main/java/com/dfsek/terra/config/loaders/mod/ModDependentConfigSectionLoader.java +++ b/common/src/main/java/com/dfsek/terra/config/loaders/mod/ModDependentConfigSectionLoader.java @@ -23,13 +23,21 @@ public class ModDependentConfigSectionLoader implements TypeLoader map = (Map) c; + if(c instanceof Map && ((Map) c).containsKey("default")) { + Map map = (Map) c; - ModDependentConfigSection configSection = new ModDependentConfigSection<>(main, loader.loadType(generic, map.get("default"))); + ModDependentConfigSection configSection = new ModDependentConfigSection<>(main, loader.loadType(generic, map.get("default"))); - ((Map) ((Map) c).get("mods")).forEach(configSection::add); + if(map.containsKey("mods")) { + for(Map.Entry modEntry : ((Map) map.get("mods")).entrySet()) { + configSection.add(modEntry.getKey(), loader.loadType(generic, modEntry.getValue())); + } + } - return configSection; + return configSection; + } else { + return ModDependentConfigSection.withDefault(loader.loadType(generic, c)); // Load the original type otherwise. + } } else throw new LoadException("Unable to load config! Could not retrieve parameterized type: " + type); } }