Fix Configs not generating correctly on first load Closes #6069

This commit is contained in:
LexManos 2019-08-19 19:45:32 -07:00
parent 8c04651301
commit dc0eacb80f
3 changed files with 22 additions and 11 deletions

View File

@ -69,6 +69,8 @@ public class ForgeConfigSpec extends UnmodifiableConfigWrapper<Config>
private Config childConfig;
private boolean isCorrecting = false;
private ForgeConfigSpec(Config storage, Map<List<String>, String> levelComments) {
super(storage);
this.levelComments = levelComments;
@ -87,6 +89,10 @@ public class ForgeConfigSpec extends UnmodifiableConfigWrapper<Config>
}
}
public boolean isCorrecting() {
return isCorrecting;
}
public void save()
{
Preconditions.checkNotNull(childConfig, "Cannot save config value without assigned Config object present");
@ -95,18 +101,25 @@ public class ForgeConfigSpec extends UnmodifiableConfigWrapper<Config>
}
}
public boolean isCorrect(CommentedConfig config) {
public synchronized boolean isCorrect(CommentedConfig config) {
LinkedList<String> parentPath = new LinkedList<>();
return correct(this.config, config, parentPath, Collections.unmodifiableList( parentPath ), null, true) == 0;
return correct(this.config, config, parentPath, Collections.unmodifiableList( parentPath ), (a, b, c, d) -> {}, true) == 0;
}
public int correct(CommentedConfig config) {
return correct(config, (action, path, incorrectValue, correctedValue) -> {});
}
public int correct(CommentedConfig config, CorrectionListener listener) {
public synchronized int correct(CommentedConfig config, CorrectionListener listener) {
LinkedList<String> parentPath = new LinkedList<>(); //Linked list for fast add/removes
return correct(this.config, config, parentPath, Collections.unmodifiableList(parentPath), listener, false);
int ret = -1;
try {
isCorrecting = true;
ret = correct(this.config, config, parentPath, Collections.unmodifiableList(parentPath), listener, false);
} finally {
isCorrecting = false;
}
return ret;
}
private int correct(Config spec, CommentedConfig config, LinkedList<String> parentPath, List<String> parentPathUnmodifiable, CorrectionListener listener, boolean dryRun)

View File

@ -21,7 +21,6 @@ package net.minecraftforge.fml.config;
import com.electronwill.nightconfig.core.ConfigFormat;
import com.electronwill.nightconfig.core.file.CommentedFileConfig;
import com.electronwill.nightconfig.core.file.FileNotFoundAction;
import com.electronwill.nightconfig.core.file.FileWatcher;
import com.electronwill.nightconfig.core.io.WritingMode;
import net.minecraftforge.fml.loading.FMLConfig;
@ -90,9 +89,11 @@ public class ConfigFileTypeHandler {
public void run() {
// Force the regular classloader onto the special thread
Thread.currentThread().setContextClassLoader(realClassLoader);
this.commentedFileConfig.load();
LOGGER.debug(CONFIG, "Config file {} changed, sending notifies", this.modConfig.getFileName());
this.modConfig.fireEvent(new ModConfig.ConfigReloading(this.modConfig));
if (!this.modConfig.getSpec().isCorrecting()) {
this.commentedFileConfig.load();
LOGGER.debug(CONFIG, "Config file {} changed, sending notifies", this.modConfig.getFileName());
this.modConfig.fireEvent(new ModConfig.ConfigReloading(this.modConfig));
}
}
}
}

View File

@ -28,9 +28,6 @@ import net.minecraftforge.fml.loading.StringUtils;
import java.nio.file.Path;
import java.util.concurrent.Callable;
import java.util.function.Consumer;
import static cpw.mods.modlauncher.api.LamdbaExceptionUtils.uncheck;
public class ModConfig
{