From 3f37907256f248224c675ec3c3b5e495602ef09d Mon Sep 17 00:00:00 2001 From: dfsek Date: Sun, 23 May 2021 15:57:36 -0700 Subject: [PATCH] implement ModDependentConfigSection#withDefault --- .../loaders/mod/ModDependentConfigSection.java | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/common/src/main/java/com/dfsek/terra/config/loaders/mod/ModDependentConfigSection.java b/common/src/main/java/com/dfsek/terra/config/loaders/mod/ModDependentConfigSection.java index d1a76a5a4..40d06d74b 100644 --- a/common/src/main/java/com/dfsek/terra/config/loaders/mod/ModDependentConfigSection.java +++ b/common/src/main/java/com/dfsek/terra/config/loaders/mod/ModDependentConfigSection.java @@ -13,7 +13,7 @@ public class ModDependentConfigSection { private final Map results = new HashMap<>(); private final T defaultValue; - public ModDependentConfigSection(TerraPlugin main, T defaultValue) { + protected ModDependentConfigSection(TerraPlugin main, T defaultValue) { this.main = main; this.defaultValue = defaultValue; } @@ -22,10 +22,16 @@ public class ModDependentConfigSection { results.put(id, value); } + public static ModDependentConfigSection withDefault(T1 defaultValue) { + return new ModDependentConfigSection<>(null, defaultValue); + } + public T get() { - Set mods = main.getMods().stream().map(Mod::getID).collect(Collectors.toSet()); - for(Map.Entry entry : results.entrySet()) { - if(mods.contains(entry.getKey())) return entry.getValue(); + if(main != null) { + Set mods = main.getMods().stream().map(Mod::getID).collect(Collectors.toSet()); + for(Map.Entry entry : results.entrySet()) { + if(mods.contains(entry.getKey())) return entry.getValue(); + } } return defaultValue; }