1
0
mirror of https://github.com/SquidDev-CC/CC-Tweaked synced 2024-11-05 01:26:20 +00:00

Fix enums not being added to config files

The default validator allows for null (why???), and so accepts it not
being present at all.
This commit is contained in:
Jonathan Coates 2023-05-30 22:20:47 +01:00
parent e153839a98
commit d3b39be9a8
No known key found for this signature in database
GPG Key ID: B9E431FF07C98D06

View File

@ -4,10 +4,7 @@
package dan200.computercraft.shared.platform;
import com.electronwill.nightconfig.core.Config;
import com.electronwill.nightconfig.core.ConfigSpec;
import com.electronwill.nightconfig.core.EnumGetMethod;
import com.electronwill.nightconfig.core.UnmodifiableConfig;
import com.electronwill.nightconfig.core.*;
import com.electronwill.nightconfig.core.file.CommentedFileConfig;
import com.electronwill.nightconfig.core.file.FileNotFoundAction;
import com.electronwill.nightconfig.core.file.FileWatcher;
@ -200,10 +197,10 @@ public class FabricConfigFile implements ConfigFile {
@Override
public <V extends Enum<V>> Value<V> defineEnum(String path, V defaultValue) {
var fullPath = getFullPath(path);
spec.defineEnum(fullPath, defaultValue, EnumGetMethod.NAME_IGNORECASE);
spec.define(fullPath, defaultValue, o -> o != null && o != NullObject.NULL_OBJECT && EnumGetMethod.NAME_IGNORECASE.validate(o, defaultValue.getDeclaringClass()));
var suffix = "Allowed Values: " + Arrays.stream(defaultValue.getDeclaringClass().getEnumConstants()).map(Enum::name).collect(Collectors.joining(", "));
return defineValue(path, takeComment(suffix), defaultValue, (c, p, d) -> c.getEnumOrElse(p, d, EnumGetMethod.NAME_IGNORECASE));
return defineValue(fullPath, takeComment(suffix), defaultValue, (c, p, d) -> c.getEnumOrElse(p, d, EnumGetMethod.NAME_IGNORECASE));
}
@Override