mirror of
https://github.com/MinecraftForge/MinecraftForge.git
synced 2026-11-19 11:59:25 +00:00
Bump NightConfig to 3.7.3, to fix toml sub-configs being completely broken. Fixes #10015
This commit is contained in:
3 files changed
+27
-24
No files matched your search
+8
-2
@@ -6,6 +6,8 @@
|
||||
package net.minecraftforge.fml.loading.moddiscovery;
|
||||
|
||||
import com.electronwill.nightconfig.core.UnmodifiableConfig;
|
||||
import com.google.common.collect.ImmutableMap;
|
||||
|
||||
import net.minecraftforge.forgespi.language.IConfigurable;
|
||||
import net.minecraftforge.forgespi.language.IModFileInfo;
|
||||
|
||||
@@ -38,8 +40,12 @@ class NightConfigWrapper implements IConfigurable {
|
||||
public <T> Optional<T> getConfigElement(final String... key) {
|
||||
var path = asList(key);
|
||||
return this.config.getOptional(path).map(value -> {
|
||||
if (value instanceof UnmodifiableConfig) {
|
||||
return (T) ((UnmodifiableConfig) value).valueMap();
|
||||
if (value instanceof UnmodifiableConfig cfg) {
|
||||
// New Night config doesn't implement valueMap(), so do a copy.
|
||||
var builder = ImmutableMap.builder();
|
||||
for (var e: cfg.entrySet())
|
||||
builder.put(e.getKey(), e.getValue());
|
||||
return (T)builder.build();
|
||||
} else if (value instanceof ArrayList<?> al && al.size() > 0 && al.get(0) instanceof UnmodifiableConfig) {
|
||||
throw new InvalidModFileException("The configuration path " + path + " is invalid. I wasn't expecting a multi-object list - remove one of the [[ ]]", file);
|
||||
}
|
||||
|
||||
+1
-1
@@ -67,7 +67,7 @@ dependencyResolutionManagement {
|
||||
bundle('terminalconsoleappender', ['terminalconsoleappender', 'jline-reader', 'jline-terminal', 'jline-terminal-jna'])
|
||||
|
||||
// The core of our configuration system, it has many flaws, but it works for the most part
|
||||
version('night-config', '3.7.1')
|
||||
version('night-config', '3.7.3')
|
||||
library('night-config-toml', 'com.electronwill.night-config', 'toml').versionRef('night-config')
|
||||
library('night-config-core', 'com.electronwill.night-config', 'core').versionRef('night-config')
|
||||
bundle('night-config', ['night-config-toml', 'night-config-core'])
|
||||
|
||||
@@ -119,17 +119,16 @@ public class ForgeConfigSpec extends UnmodifiableConfigWrapper<UnmodifiableConfi
|
||||
|
||||
@Override
|
||||
public void afterReload() {
|
||||
this.resetCaches(getValues().valueMap().values());
|
||||
this.resetCaches(getValues());
|
||||
}
|
||||
|
||||
private void resetCaches(final Iterable<Object> configValues) {
|
||||
configValues.forEach(value -> {
|
||||
if (value instanceof ConfigValue<?> configValue) {
|
||||
private void resetCaches(UnmodifiableConfig cfg) {
|
||||
for (var entry : cfg.entrySet()) {
|
||||
if (entry.getValue() instanceof ConfigValue<?> configValue)
|
||||
configValue.clearCache();
|
||||
} else if (value instanceof Config innerConfig) {
|
||||
this.resetCaches(innerConfig.valueMap().values());
|
||||
}
|
||||
});
|
||||
else if (entry.getValue() instanceof UnmodifiableConfig innerConfig)
|
||||
resetCaches(innerConfig);
|
||||
}
|
||||
}
|
||||
|
||||
public void save() {
|
||||
@@ -169,13 +168,10 @@ public class ForgeConfigSpec extends UnmodifiableConfigWrapper<UnmodifiableConfi
|
||||
private int correct(UnmodifiableConfig spec, CommentedConfig config, LinkedList<String> parentPath, List<String> parentPathUnmodifiable, CorrectionListener listener, CorrectionListener commentListener, boolean dryRun) {
|
||||
int count = 0;
|
||||
|
||||
Map<String, Object> specMap = spec.valueMap();
|
||||
Map<String, Object> configMap = config.valueMap();
|
||||
|
||||
for (Map.Entry<String, Object> specEntry : specMap.entrySet()) {
|
||||
for (var specEntry : spec.entrySet()) {
|
||||
final String key = specEntry.getKey();
|
||||
final Object specValue = specEntry.getValue();
|
||||
final Object configValue = configMap.get(key);
|
||||
final Object configValue = config.get(key);
|
||||
final CorrectionAction action = configValue == null ? CorrectionAction.ADD : CorrectionAction.REPLACE;
|
||||
|
||||
parentPath.addLast(key);
|
||||
@@ -189,7 +185,7 @@ public class ForgeConfigSpec extends UnmodifiableConfigWrapper<UnmodifiableConfi
|
||||
return 1;
|
||||
} else {
|
||||
CommentedConfig newValue = config.createSubConfig();
|
||||
configMap.put(key, newValue);
|
||||
config.set(key, newValue);
|
||||
listener.onCorrect(action, parentPathUnmodifiable, configValue, newValue);
|
||||
count++;
|
||||
count += correct((Config)specValue, newValue, parentPath, parentPathUnmodifiable, listener, commentListener, dryRun);
|
||||
@@ -213,7 +209,7 @@ public class ForgeConfigSpec extends UnmodifiableConfigWrapper<UnmodifiableConfi
|
||||
return 1;
|
||||
|
||||
Object newValue = valueSpec.correct(configValue);
|
||||
configMap.put(key, newValue);
|
||||
config.set(key, newValue);
|
||||
listener.onCorrect(action, parentPathUnmodifiable, configValue, newValue);
|
||||
count++;
|
||||
}
|
||||
@@ -232,16 +228,17 @@ public class ForgeConfigSpec extends UnmodifiableConfigWrapper<UnmodifiableConfi
|
||||
parentPath.removeLast();
|
||||
}
|
||||
|
||||
var keys = config.entrySet().stream().map(Entry::getKey).toList();
|
||||
// Second step: removes the unspecified values
|
||||
for (Iterator<Map.Entry<String, Object>> ittr = configMap.entrySet().iterator(); ittr.hasNext();) {
|
||||
Map.Entry<String, Object> entry = ittr.next();
|
||||
if (!specMap.containsKey(entry.getKey())) {
|
||||
for (var key : keys) {
|
||||
if (!spec.contains(key)) {
|
||||
if (dryRun)
|
||||
return 1;
|
||||
|
||||
ittr.remove();
|
||||
parentPath.addLast(entry.getKey());
|
||||
listener.onCorrect(CorrectionAction.REMOVE, parentPathUnmodifiable, entry.getValue(), null);
|
||||
var value = config.get(key);
|
||||
config.remove(key);
|
||||
parentPath.addLast(key);
|
||||
listener.onCorrect(CorrectionAction.REMOVE, parentPathUnmodifiable, value, null);
|
||||
parentPath.removeLast();
|
||||
count++;
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user