mirror of
https://github.com/PolyhedralDev/Terra.git
synced 2025-07-03 00:15:35 +00:00
cache value of ModDependentConfigSection
This commit is contained in:
parent
788a3c2d48
commit
ed2fa85d81
@ -9,9 +9,12 @@ import java.util.Set;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public class ModDependentConfigSection<T> {
|
||||
private static final Object NULL = new Object(); // Null object
|
||||
private final TerraPlugin main;
|
||||
private final Map<String, T> results = new HashMap<>();
|
||||
private final T defaultValue;
|
||||
@SuppressWarnings("unchecked")
|
||||
private T value = (T) NULL;
|
||||
|
||||
protected ModDependentConfigSection(TerraPlugin main, T defaultValue) {
|
||||
this.main = main;
|
||||
@ -27,6 +30,11 @@ public class ModDependentConfigSection<T> {
|
||||
}
|
||||
|
||||
public T get() {
|
||||
if(value == NULL) value = compute(); // Cache the value.
|
||||
return value;
|
||||
}
|
||||
|
||||
private T compute() {
|
||||
if(main != null) {
|
||||
Set<String> mods = main.getMods().stream().map(Mod::getID).collect(Collectors.toSet());
|
||||
for(Map.Entry<String, T> entry : results.entrySet()) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user