night-config
night-config copied to clipboard
[Forge Related] Reloading config skips validators
I added string config value as represented below:
ForgeConfigSpec.ConfigValue<String> DEBUG_LEVEL = new ForgeConfigSpec.Builder()
.comment("Level of debug, if it is enabled in enable_debug. Available variants: debug, trace",
"Debug: additionally prints debug messages.",
"Trace: additionally prints debug and trace messages.")
.defineInList("debug_level", "debug", Lists.newArrayList("debug", "trace"));
As you can see, I allowed debug_level
to contain only debug
and trace
.
At first time, when I placed smth like test
in debug_level
value, config was automatically corrected to debug
during config initialization, and that's right.
But after changing this value in config file again with already launched Forge, it just skips validators and sets the value without validating, so it can contain any other string.
Hi! Thanks for reporting this issue. I'm not sure whether it's a problem with NightConfig of with MinecraftForge itself, I'll have to do some testing.
It's easily fixable in Forge (by adding this line), making me believe that it's a Forge bug. I'm not 100% sure that Forge should be doing this validation though, so please still do some investigation/testing.
Since #152, it is now possible to add a "load filter" on a FileConfig
, which allows to cancel loading operations based on an arbitrary condition (the new content of the configuration is available to make this decision).
Usage:
FileConfig config = FileConfig.builder(file)
.onLoadFilter(newConfig -> {
return mySpec.isCorrect(newConfig); // reject incorrect configurations: the reload will not occur
})
.build();
It is also possible to be notified of (successfull) loading operations, which could be used to trigger the correction:
FileConfig config = FileConfig.builder(file)
.onLoad(() -> {
mySpec.correct(config);
})
.build();