mirror of
https://github.com/PolyhedralDev/Terra.git
synced 2026-06-19 07:11:14 +00:00
implement ModDependentConfigSection#withDefault
This commit is contained in:
+10
-4
@@ -13,7 +13,7 @@ public class ModDependentConfigSection<T> {
|
|||||||
private final Map<String, T> results = new HashMap<>();
|
private final Map<String, T> results = new HashMap<>();
|
||||||
private final T defaultValue;
|
private final T defaultValue;
|
||||||
|
|
||||||
public ModDependentConfigSection(TerraPlugin main, T defaultValue) {
|
protected ModDependentConfigSection(TerraPlugin main, T defaultValue) {
|
||||||
this.main = main;
|
this.main = main;
|
||||||
this.defaultValue = defaultValue;
|
this.defaultValue = defaultValue;
|
||||||
}
|
}
|
||||||
@@ -22,10 +22,16 @@ public class ModDependentConfigSection<T> {
|
|||||||
results.put(id, value);
|
results.put(id, value);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static <T1> ModDependentConfigSection<T1> withDefault(T1 defaultValue) {
|
||||||
|
return new ModDependentConfigSection<>(null, defaultValue);
|
||||||
|
}
|
||||||
|
|
||||||
public T get() {
|
public T get() {
|
||||||
Set<String> mods = main.getMods().stream().map(Mod::getID).collect(Collectors.toSet());
|
if(main != null) {
|
||||||
for(Map.Entry<String, T> entry : results.entrySet()) {
|
Set<String> mods = main.getMods().stream().map(Mod::getID).collect(Collectors.toSet());
|
||||||
if(mods.contains(entry.getKey())) return entry.getValue();
|
for(Map.Entry<String, T> entry : results.entrySet()) {
|
||||||
|
if(mods.contains(entry.getKey())) return entry.getValue();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return defaultValue;
|
return defaultValue;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user