Major config system upgrade

This commit is contained in:
FalsePattern committed 2024-12-05 20:22:56 +01:00
1 parent 644d6ffc62
commit 7f1b6c4276
25 files changed
+668 -303

No files matched your search

@@ -27,7 +27,11 @@ import com.falsepattern.lib.config.Config;
import com.falsepattern.lib.config.ConfigurationManager;
import com.falsepattern.lib.internal.Tags;
@Config(modid = Tags.MODID)
@Config.Comment("Miscellaneous FalsePatternLib settings")
@Config.LangKey
@Config(modid = Tags.MODID,
category = "misc",
categoryMigrations = "general")
public class LibraryConfig {
static {
ConfigurationManager.selfInit();
@@ -36,14 +40,19 @@ public class LibraryConfig {
@Config.Comment({"Fixes the mod options menu in-game.",
"By default, the mod options when in already in a game will show \"Test1, Test2, DISABLED\" in bright red.",
"This replaces that interface with the one from the main menu."})
@Config.LangKey("config.falsepatternlib.ingamemodoptionsfix")
@Config.LangKey
@Config.DefaultBoolean(true)
@Config.Name(value = "inGameModOptionsFix",
migrations = "")
public static boolean IN_GAME_MOD_OPTIONS_FIX;
@Config.Comment("How \"loud\" the config error logging should be.")
@Config.LangKey("config.falsepatternlib.configlogging")
@Config.Comment({"How the config error logging should be set up.",
"[None] disables all built-in config validation error logging"})
@Config.LangKey
@Config.DefaultEnum("Log")
public static ValidationLogging CONFIG_ERROR_LOUDNESS;
@Config.Name(value = "configErrorLogging",
migrations = "CONFIG_ERROR_LOUDNESS")
public static ValidationLogging CONFIG_ERROR_LOGGING;
public enum ValidationLogging {
@StableAPI.Expose(since = "__INTERNAL__") None,
@@ -27,10 +27,8 @@ import com.falsepattern.lib.config.Config;
import com.falsepattern.lib.config.ConfigurationManager;
import com.falsepattern.lib.internal.Tags;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
@SideOnly(Side.CLIENT)
@Config.Comment("Toast notification settings")
@Config.LangKey
@Config(modid = Tags.MODID,
category = "toasts")
public class ToastConfig {
@@ -38,23 +36,29 @@ public class ToastConfig {
ConfigurationManager.selfInit();
}
@Config.Comment("The maximum amount of toasts to show on the screen")
@Config.LangKey("config.falsepatternlib.maxtoasts")
@Config.Comment("The maximum amount of toasts to show on the screen.")
@Config.LangKey
@Config.DefaultInt(5)
@Config.RangeInt(min = 1,
max = 10)
@Config.Name(value = "maxVisible",
migrations = "")
public static int MAX_VISIBLE;
@Config.Comment("The amount of empty space from the top of the screen in pixels")
@Config.LangKey("config.falsepatternlib.toastoffset")
@Config.Comment("The amount of empty space from the top of the screen in pixels.")
@Config.LangKey
@Config.DefaultInt(0)
@Config.RangeInt(min = 0,
max = 10000)
@Config.Name(value = "yOffset",
migrations = "")
public static int Y_OFFSET;
@Config.Comment("Which side of the screen should toasts show up on")
@Config.LangKey("config.falsepatternlib.toastalign")
@Config.Comment("Which side of the screen should toasts show up on.")
@Config.LangKey
@Config.DefaultEnum("Right")
@Config.Name(value = "align",
migrations = "")
public static Side ALIGN;
public static boolean leftAlign() {
@@ -35,10 +35,12 @@ import java.util.regex.Pattern;
public class ConfigElementProxy<T> implements IConfigElement<T> {
private final ConfigElement<T> element;
private final String comment;
private final Runnable syncCallback;
public ConfigElementProxy(Property prop, Runnable syncCallback) {
public ConfigElementProxy(Property prop, String comment, Runnable syncCallback) {
this.element = new ConfigElement<>(prop);
this.comment = comment;
this.syncCallback = syncCallback;
}
@@ -74,7 +76,7 @@ public class ConfigElementProxy<T> implements IConfigElement<T> {
@Override
public String getComment() {
return element.getComment();
return comment;
}
@Override
@@ -82,6 +84,7 @@ public class ConfigElementProxy<T> implements IConfigElement<T> {
return element.getChildElements();
}
// Caller sensitive
@Override
public ConfigGuiType getType() {
return element.getType();
@@ -0,0 +1,38 @@
/*
* This file is part of FalsePatternLib.
*
* Copyright (C) 2022-2024 FalsePattern
* All Rights Reserved
*
* The above copyright notice and this permission notice shall be included
* in all copies or substantial portions of the Software.
*
* FalsePatternLib is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* FalsePatternLib is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with FalsePatternLib. If not, see <https://www.gnu.org/licenses/>.
*/
package com.falsepattern.lib.internal.impl.config;
import com.github.bsideup.jabel.Desugar;
import net.minecraftforge.common.config.Configuration;
import java.lang.reflect.Field;
@Desugar
public record ConfigFieldParameters(
Field field,
Configuration configuration,
String modid,
String category
) {}
@@ -34,8 +34,11 @@ import com.google.common.collect.HashBiMap;
import lombok.AccessLevel;
import lombok.NoArgsConstructor;
import lombok.val;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import net.minecraftforge.common.config.Configuration;
import cpw.mods.fml.client.config.DummyConfigElement;
import cpw.mods.fml.client.config.IConfigElement;
import cpw.mods.fml.client.event.ConfigChangedEvent;
@@ -47,6 +50,7 @@ import java.io.DataOutput;
import java.io.DataOutputStream;
import java.io.IOException;
import java.lang.reflect.Field;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.ArrayList;
import java.util.HashMap;
@@ -64,7 +68,7 @@ import java.util.function.BiConsumer;
*/
@NoArgsConstructor(access = AccessLevel.PRIVATE)
public final class ConfigurationManagerImpl {
private static final Map<String, Configuration> configs = new HashMap<>();
private static final Map<Path, Configuration> configs = new HashMap<>();
private static final Map<Configuration, Set<Class<?>>> configToClassMap = new HashMap<>();
private static final Map<Class<?>, ParsedConfiguration> parsedConfigMap = new HashMap<>();
private static final BiMap<String, Class<?>> serializedNames = HashBiMap.create();
@@ -81,9 +85,33 @@ public final class ConfigurationManagerImpl {
}
}
static Configuration getForgeConfig(String modid) {
return configs.computeIfAbsent(modid, (ignored) -> {
val c = new Configuration(configDir.resolve(modid + ".cfg").toFile());
private static @Nullable Path resolveConfigFile(String pathSuffix, boolean create) throws ConfigException {
var thePath = configDir.resolve(pathSuffix);
val parent = thePath.getParent();
if (!Files.exists(parent)) {
if (!create) {
return null;
}
try {
Files.createDirectories(parent);
} catch (IOException e) {
throw new ConfigException(String.format("Failed to create config parent directory at %s", parent), e);
}
}
val fileName = thePath.getFileName().toString();
if (!fileName.contains(".")) {
thePath = parent.resolve(fileName + ".cfg");
}
return thePath;
}
static @NotNull Configuration getForgeConfig(String pathSuffix, boolean create) throws ConfigException {
val thePath = resolveConfigFile(pathSuffix, create);
if (thePath == null || !(create || Files.exists(thePath))) {
throw new ConfigException(String.format("Could not find config file at %s", pathSuffix));
}
return configs.computeIfAbsent(thePath, (ignored) -> {
val c = new Configuration(thePath.toFile());
c.load();
return c;
});
@@ -93,14 +121,14 @@ public final class ConfigurationManagerImpl {
if (!parsedConfigMap.containsKey(configClass)) {
throw new ConfigException("Class " + configClass.getName() + " is not a registered configuration!");
}
parsedConfigMap.get(configClass).load();
parsedConfigMap.get(configClass).loadFile();
}
public static void save(Class<?> configClass) throws ConfigException {
if (!parsedConfigMap.containsKey(configClass)) {
throw new ConfigException("Class " + configClass.getName() + " is not a registered configuration!");
}
parsedConfigMap.get(configClass).save();
parsedConfigMap.get(configClass).saveFile();
}
public static boolean validateFields(BiConsumer<Class<?>, Field> invalidFieldHandler, Class<?> configClass, boolean resetInvalid)
@@ -235,6 +263,21 @@ public final class ConfigurationManagerImpl {
initialized = true;
}
public static DummyConfigElement.DummyCategoryElement<?> getConfigCategoryElement(Class<?> configClass) throws ConfigException {
if (!parsedConfigMap.containsKey(configClass)) {
throw new ConfigException("Class " + configClass.getName() + " is not a registered configuration!");
}
val config = parsedConfigMap.get(configClass);
val entry = new DummyConfigElement.DummyCategoryElement<>(
config.category,
config.langKey,
config.getConfigElements()
);
entry.setRequiresWorldRestart(config.requiresWorldRestart());
entry.setRequiresMcRestart(config.requiresMcRestart());
return entry;
}
public static void sendSyncRequest() throws IOException {
val event = new SyncRequest();
event.transmit();
@@ -46,8 +46,11 @@ import java.io.DataOutput;
import java.io.IOException;
import java.lang.reflect.Field;
import java.lang.reflect.Modifier;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Comparator;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Optional;
@@ -76,6 +79,8 @@ public class ParsedConfiguration {
public final Class<?> configClass;
public final String modid;
public final String category;
public final String comment;
public final String langKey;
public final Configuration rawConfig;
public final boolean sync;
private final Map<String, AConfigField<?>> fields = new HashMap<>();
@@ -88,14 +93,76 @@ public class ParsedConfiguration {
+ configClass.getName()
+ " does not have a @Config annotation!"));
val category = Optional.of(cfg.category().trim())
.map((cat) -> cat.length() == 0 ? null : cat)
.map((cat) -> cat.isEmpty() ? null : cat)
.orElseThrow(() -> new ConfigException("Config class "
+ configClass.getName()
+ " has an empty category!"));
val rawConfig = ConfigurationManagerImpl.getForgeConfig(cfg.modid());
val comment = Optional.ofNullable(configClass.getAnnotation(Config.Comment.class))
.map(Config.Comment::value)
.map((lines) -> String.join("\n", lines))
.orElse("");
val langKey = Optional.ofNullable(configClass.getAnnotation(Config.LangKey.class))
.map(Config.LangKey::value)
.map(x -> x.isEmpty() ? "config." + cfg.modid() + "." + category : x)
.orElse(category);
val path = Optional.of(cfg.customPath().trim())
.map(p -> p.isEmpty() ? null : p)
.orElse(cfg.modid());
val rawConfig = ConfigurationManagerImpl.getForgeConfig(path, true);
if (!rawConfig.hasCategory(category)) {
// Process migrations
migrate:
{
val categoryCandidates = new ArrayList<>(Arrays.asList(cfg.categoryMigrations()));
categoryCandidates.add(0, category);
for (var migration : cfg.pathMigrations()) {
migration = migration.trim();
try {
val oldConfig = ConfigurationManagerImpl.getForgeConfig(migration, false);
for (val fromCategory : categoryCandidates) {
if (oldConfig.hasCategory(fromCategory)) {
val oldCat = oldConfig.getCategory(fromCategory);
val newCat = rawConfig.getCategory(category);
val entries = oldCat.keySet();
for (val entry : entries) {
newCat.put(entry, oldCat.get(entry));
}
rawConfig.save();
oldConfig.removeCategory(oldConfig.getCategory(category));
if (oldConfig.getCategoryNames().isEmpty()) {
oldConfig.getConfigFile().delete();
} else {
oldConfig.save();
}
break migrate;
}
}
} catch (ConfigException ignored) {
}
}
// Try to migrate category in local file
categoryCandidates.remove(0);
for (val fromCategory : categoryCandidates) {
if (rawConfig.hasCategory(fromCategory)) {
val oldCategory = rawConfig.getCategory(fromCategory);
val newCategory = rawConfig.getCategory(category);
val entries = oldCategory.keySet();
for (val entry: entries) {
newCategory.put(entry, oldCategory.get(entry));
}
rawConfig.removeCategory(oldCategory);
break migrate;
}
}
}
}
rawConfig.setCategoryComment(category, comment);
rawConfig.setCategoryLanguageKey(category, langKey);
val parsedConfig = new ParsedConfiguration(configClass,
cfg.modid(),
category,
comment,
langKey,
rawConfig,
configClass.isAnnotationPresent(Config.Synchronize.class));
try {
@@ -106,11 +173,15 @@ public class ParsedConfiguration {
return parsedConfig;
}
public void save() {
public void saveFile() {
saveFields();
rawConfig.save();
}
public void saveFields() {
for (val field : fields.values()) {
field.save();
}
rawConfig.save();
}
//Happens when changed through the gui
@@ -121,8 +192,12 @@ public class ParsedConfiguration {
rawConfig.save();
}
public void load() throws ConfigException {
public void loadFile() throws ConfigException {
ConfigurationManagerImpl.loadRawConfig(rawConfig);
loadFields();
}
public void loadFields() {
for (val field : fields.values()) {
field.load();
}
@@ -136,7 +211,7 @@ public class ParsedConfiguration {
syncFields.remove(key);
}
}
while (syncFields.size() > 0) {
while (!syncFields.isEmpty()) {
val fieldName =
StringConfigField.receiveString(input, maxFieldNameLength, "field name", configClass.getName());
if (!syncFields.containsKey(fieldName)) {
@@ -175,6 +250,7 @@ public class ParsedConfiguration {
if (configClass.isAssignableFrom(Config.RequiresMcRestart.class)) {
cat.setRequiresMcRestart(true);
}
val nonFoundKeys = new HashSet<>(rawConfig.getCategory(category).keySet());
for (val field : configClass.getDeclaredFields()) {
if (field.getAnnotation(Config.Ignore.class) != null || (field.getModifiers() & Modifier.FINAL) != 0) {
continue;
@@ -182,14 +258,32 @@ public class ParsedConfiguration {
field.setAccessible(true);
maxFieldNameLength = Math.max(maxFieldNameLength, field.getName().length());
val fieldClass = field.getType();
val name = Optional.ofNullable(field.getAnnotation(Config.Name.class))
.map(Config.Name::value)
.orElse(field.getName());
val nameAnnotation = Optional.ofNullable(field.getAnnotation(Config.Name.class));
val name = nameAnnotation.map(Config.Name::value)
.orElse(field.getName());
if (!cat.containsKey(name) && nameAnnotation.isPresent()) {
val migrations = nameAnnotation.get().migrations();
for (var migration: migrations) {
if (migration.isEmpty()) {
migration = field.getName();
}
if (cat.containsKey(migration)) {
val prop = cat.remove(migration);
prop.setName(name);
cat.put(name, prop);
nonFoundKeys.remove(migration);
break;
}
}
} else {
nonFoundKeys.remove(name);
}
AConfigField<?> configField;
val params = new ConfigFieldParameters(field, rawConfig, modid, category);
if (constructors.containsKey(fieldClass)) {
fields.put(name, configField = constructors.get(fieldClass).construct(field, rawConfig, category));
fields.put(name, configField = constructors.get(fieldClass).construct(params));
} else if (fieldClass.isEnum()) {
fields.put(name, configField = new EnumConfigField<>(field, rawConfig, category));
fields.put(name, configField = new EnumConfigField<>(params));
} else {
throw new ConfigException("Illegal config field: "
+ field.getName()
@@ -206,11 +300,16 @@ public class ParsedConfiguration {
cat.setRequiresWorldRestart(true);
}
configField.init();
elements.computeIfAbsent(name, (name2) -> new ConfigElementProxy<>(configField.getProperty(), () -> {
elements.computeIfAbsent(name, (name2) -> new ConfigElementProxy<>(configField.getProperty(), configField.getComment(), () -> {
configField.load();
save();
configField.save();
}));
}
val rawCategory = rawConfig.getCategory(category);
for (val key : nonFoundKeys) {
rawCategory.remove(key);
}
saveFile();
rawConfig.setCategoryPropertyOrder(category,
fieldsSorted().map((prop) -> prop.name).collect(Collectors.toList()));
}
@@ -224,6 +323,14 @@ public class ParsedConfiguration {
return fieldsSorted().map((field) -> elements.get(field.name)).collect(Collectors.toList());
}
public boolean requiresWorldRestart() {
return rawConfig.getCategory(category).requiresWorldRestart();
}
public boolean requiresMcRestart() {
return rawConfig.getCategory(category).requiresMcRestart();
}
public boolean validate(BiConsumer<Class<?>, Field> invalidFieldHandler, boolean resetInvalid) {
boolean valid = true;
for (val field : fields.values()) {
@@ -239,6 +346,6 @@ public class ParsedConfiguration {
}
private interface FieldRefConstructor {
AConfigField<?> construct(Field field, Configuration configuration, String category) throws ConfigException;
AConfigField<?> construct(ConfigFieldParameters params) throws ConfigException;
}
}
@@ -53,7 +53,7 @@ public class ClientEventHandlerPre {
@SubscribeEvent
@SideOnly(Side.CLIENT)
public void onValidationErrorToast(ConfigValidationFailureEvent e) {
if (LibraryConfig.CONFIG_ERROR_LOUDNESS == LibraryConfig.ValidationLogging.LogAndToast) {
if (LibraryConfig.CONFIG_ERROR_LOGGING == LibraryConfig.ValidationLogging.LogAndToast) {
e.toast();
}
}
@@ -48,7 +48,7 @@ public class CommonEventHandlerPre {
@SubscribeEvent
public void onValidationErrorLog(ConfigValidationFailureEvent e) {
if (LibraryConfig.CONFIG_ERROR_LOUDNESS != LibraryConfig.ValidationLogging.None) {
if (LibraryConfig.CONFIG_ERROR_LOGGING != LibraryConfig.ValidationLogging.None) {
e.logWarn();
}
}
@@ -23,7 +23,9 @@
package com.falsepattern.lib.internal.impl.config.fields;
import com.falsepattern.lib.config.Config;
import com.falsepattern.lib.internal.impl.config.ConfigFieldParameters;
import com.falsepattern.lib.internal.impl.config.DeclOrderInternal;
import lombok.Getter;
import lombok.val;
import net.minecraftforge.common.config.Configuration;
@@ -44,7 +46,9 @@ public abstract class AConfigField<T> {
protected final String category;
protected final String langKey;
protected final Property.Type type;
@Getter
protected final Property property;
@Getter
protected final String comment;
private boolean uninitialized;
@@ -58,23 +62,26 @@ public abstract class AConfigField<T> {
+ " annotation!");
}
protected AConfigField(Field field, Configuration configuration, String category, Property.Type type) {
this(field, configuration, category, type, false);
protected AConfigField(ConfigFieldParameters params, Property.Type type) {
this(params, type, false);
}
protected AConfigField(Field field, Configuration configuration, String category, Property.Type type, boolean isList) {
this.field = field;
this.configuration = configuration;
this.category = category;
protected AConfigField(ConfigFieldParameters params, Property.Type type, boolean isList) {
this.field = params.field();
this.configuration = params.configuration();
this.category = params.category();
comment = Optional.ofNullable(field.getAnnotation(Config.Comment.class))
.map(Config.Comment::value)
.map((lines) -> String.join("\n", lines))
.orElse("");
name = Optional.ofNullable(field.getAnnotation(Config.Name.class))
.map(Config.Name::value)
.orElse(field.getName());
val nameAnnotation = Optional.ofNullable(field.getAnnotation(Config.Name.class));
name = nameAnnotation.map(Config.Name::value)
.orElse(field.getName());
langKey =
Optional.ofNullable(field.getAnnotation(Config.LangKey.class)).map(Config.LangKey::value).orElse(name);
Optional.ofNullable(field.getAnnotation(Config.LangKey.class))
.map(Config.LangKey::value)
.map(x -> x.isEmpty() ? "config." + params.modid() + "." + params.category() + "." + name : x)
.orElse(name);
this.type = type;
val cat = configuration.getCategory(category);
uninitialized = !cat.containsKey(name);
@@ -125,13 +132,11 @@ public abstract class AConfigField<T> {
uninitialized = false;
putField(getDefault());
putConfig(getDefault());
} else {
load();
}
}
public Property getProperty() {
return property;
}
@SuppressWarnings("BooleanMethodIsAlwaysInverted")
public abstract boolean validateField();
@@ -25,6 +25,7 @@ package com.falsepattern.lib.internal.impl.config.fields;
import com.falsepattern.lib.config.Config;
import com.falsepattern.lib.config.ConfigException;
import com.falsepattern.lib.config.event.ConfigValidationFailureEvent;
import com.falsepattern.lib.internal.impl.config.ConfigFieldParameters;
import lombok.SneakyThrows;
import lombok.val;
@@ -41,9 +42,9 @@ public abstract class AListConfigField<T> extends AConfigField<T> {
protected final boolean fixedLength;
protected final int maxLength;
protected AListConfigField(Field field, Configuration configuration, String category, Property.Type type)
protected AListConfigField(ConfigFieldParameters params, Property.Type type)
throws ConfigException {
super(field, configuration, category, type, true);
super(params, type, true);
fixedLength = field.isAnnotationPresent(Config.ListFixedLength.class);
maxLength = Optional.ofNullable(field.getAnnotation(Config.ListMaxLength.class))
.map(Config.ListMaxLength::value)
@@ -24,6 +24,7 @@ package com.falsepattern.lib.internal.impl.config.fields;
import com.falsepattern.lib.config.Config;
import com.falsepattern.lib.config.event.ConfigValidationFailureEvent;
import com.falsepattern.lib.internal.impl.config.ConfigFieldParameters;
import lombok.SneakyThrows;
import net.minecraftforge.common.config.Configuration;
@@ -39,8 +40,8 @@ public class BooleanConfigField extends AConfigField<Boolean> {
private final boolean primitive;
private final boolean defaultValue;
public BooleanConfigField(Field field, Configuration configuration, String category) {
super(field, configuration, category, Property.Type.BOOLEAN);
public BooleanConfigField(ConfigFieldParameters params) {
super(params, Property.Type.BOOLEAN);
primitive = field.getType().isPrimitive();
defaultValue = Optional.ofNullable(field.getAnnotation(Config.DefaultBoolean.class))
.map(Config.DefaultBoolean::value)
@@ -24,6 +24,7 @@ package com.falsepattern.lib.internal.impl.config.fields;
import com.falsepattern.lib.config.Config;
import com.falsepattern.lib.config.ConfigException;
import com.falsepattern.lib.internal.impl.config.ConfigFieldParameters;
import lombok.val;
import net.minecraftforge.common.config.Configuration;
@@ -39,8 +40,8 @@ import java.util.Optional;
public class BooleanListConfigField extends AListConfigField<boolean[]> {
private final boolean[] defaultValue;
public BooleanListConfigField(Field field, Configuration configuration, String category) throws ConfigException {
super(field, configuration, category, Property.Type.BOOLEAN);
public BooleanListConfigField(ConfigFieldParameters params) throws ConfigException {
super(params, Property.Type.BOOLEAN);
defaultValue = Optional.ofNullable(field.getAnnotation(Config.DefaultBooleanList.class))
.map(Config.DefaultBooleanList::value)
.orElseThrow(() -> noDefault(field, "DefaultBooleanList"));
@@ -24,6 +24,7 @@ package com.falsepattern.lib.internal.impl.config.fields;
import com.falsepattern.lib.config.Config;
import com.falsepattern.lib.config.event.ConfigValidationFailureEvent;
import com.falsepattern.lib.internal.impl.config.ConfigFieldParameters;
import lombok.SneakyThrows;
import lombok.val;
@@ -42,8 +43,8 @@ public class DoubleConfigField extends AConfigField<Double> {
private final double min;
private final double max;
public DoubleConfigField(Field field, Configuration configuration, String category) {
super(field, configuration, category, Property.Type.DOUBLE);
public DoubleConfigField(ConfigFieldParameters params) {
super(params, Property.Type.DOUBLE);
primitive = field.getType().isPrimitive();
val range = Optional.ofNullable(field.getAnnotation(Config.RangeDouble.class));
min = range.map(Config.RangeDouble::min).orElse(-Double.MAX_VALUE);
@@ -25,6 +25,7 @@ package com.falsepattern.lib.internal.impl.config.fields;
import com.falsepattern.lib.config.Config;
import com.falsepattern.lib.config.ConfigException;
import com.falsepattern.lib.config.event.ConfigValidationFailureEvent;
import com.falsepattern.lib.internal.impl.config.ConfigFieldParameters;
import lombok.val;
import net.minecraftforge.common.config.Configuration;
@@ -42,8 +43,8 @@ public class DoubleListConfigField extends AListConfigField<double[]> {
private final double max;
private final double[] defaultValue;
public DoubleListConfigField(Field field, Configuration configuration, String category) throws ConfigException {
super(field, configuration, category, Property.Type.DOUBLE);
public DoubleListConfigField(ConfigFieldParameters params) throws ConfigException {
super(params, Property.Type.DOUBLE);
val range = Optional.ofNullable(field.getAnnotation(Config.RangeDouble.class));
min = range.map(Config.RangeDouble::min).orElse(-Double.MAX_VALUE);
max = range.map(Config.RangeDouble::max).orElse(Double.MAX_VALUE);
@@ -25,6 +25,7 @@ package com.falsepattern.lib.internal.impl.config.fields;
import com.falsepattern.lib.config.Config;
import com.falsepattern.lib.config.event.ConfigValidationFailureEvent;
import com.falsepattern.lib.internal.FPLog;
import com.falsepattern.lib.internal.impl.config.ConfigFieldParameters;
import com.google.common.collect.BiMap;
import com.google.common.collect.HashBiMap;
import lombok.SneakyThrows;
@@ -48,8 +49,8 @@ public class EnumConfigField<T extends Enum<T>> extends AConfigField<T> {
private final BiMap<String, T> enumNameMap = HashBiMap.create();
@SuppressWarnings("unchecked")
public EnumConfigField(Field field, Configuration configuration, String category) {
super(field, configuration, category, Property.Type.STRING);
public EnumConfigField(ConfigFieldParameters params) {
super(params, Property.Type.STRING);
enumClass = (Class<T>) field.getType();
val sj = new StringJoiner(", ", "[", "]");
@@ -24,6 +24,7 @@ package com.falsepattern.lib.internal.impl.config.fields;
import com.falsepattern.lib.config.Config;
import com.falsepattern.lib.config.event.ConfigValidationFailureEvent;
import com.falsepattern.lib.internal.impl.config.ConfigFieldParameters;
import lombok.SneakyThrows;
import lombok.val;
@@ -42,8 +43,8 @@ public class IntConfigField extends AConfigField<Integer> {
private final int min;
private final int max;
public IntConfigField(Field field, Configuration configuration, String category) {
super(field, configuration, category, Property.Type.INTEGER);
public IntConfigField(ConfigFieldParameters params) {
super(params, Property.Type.INTEGER);
primitive = field.getType().isPrimitive();
val range = Optional.ofNullable(field.getAnnotation(Config.RangeInt.class));
min = range.map(Config.RangeInt::min).orElse(Integer.MIN_VALUE);
@@ -25,6 +25,7 @@ package com.falsepattern.lib.internal.impl.config.fields;
import com.falsepattern.lib.config.Config;
import com.falsepattern.lib.config.ConfigException;
import com.falsepattern.lib.config.event.ConfigValidationFailureEvent;
import com.falsepattern.lib.internal.impl.config.ConfigFieldParameters;
import lombok.val;
import net.minecraftforge.common.config.Configuration;
@@ -42,8 +43,8 @@ public class IntListConfigField extends AListConfigField<int[]> {
private final int max;
private final int[] defaultValue;
public IntListConfigField(Field field, Configuration configuration, String category) throws ConfigException {
super(field, configuration, category, Property.Type.INTEGER);
public IntListConfigField(ConfigFieldParameters params) throws ConfigException {
super(params, Property.Type.INTEGER);
val range = Optional.ofNullable(field.getAnnotation(Config.RangeInt.class));
min = range.map(Config.RangeInt::min).orElse(Integer.MIN_VALUE);
max = range.map(Config.RangeInt::max).orElse(Integer.MAX_VALUE);
@@ -24,6 +24,7 @@ package com.falsepattern.lib.internal.impl.config.fields;
import com.falsepattern.lib.config.Config;
import com.falsepattern.lib.config.event.ConfigValidationFailureEvent;
import com.falsepattern.lib.internal.impl.config.ConfigFieldParameters;
import lombok.SneakyThrows;
import lombok.val;
@@ -42,8 +43,8 @@ public class StringConfigField extends AConfigField<String> {
private final Pattern pattern;
private final String defaultValue;
public StringConfigField(Field field, Configuration configuration, String category) {
super(field, configuration, category, Property.Type.STRING);
public StringConfigField(ConfigFieldParameters params) {
super(params, Property.Type.STRING);
pattern = Optional.ofNullable(field.getAnnotation(Config.Pattern.class))
.map((ptr) -> Pattern.compile(ptr.value()))
.orElse(null);
@@ -24,6 +24,7 @@ package com.falsepattern.lib.internal.impl.config.fields;
import com.falsepattern.lib.config.Config;
import com.falsepattern.lib.config.ConfigException;
import com.falsepattern.lib.internal.impl.config.ConfigFieldParameters;
import lombok.val;
import net.minecraftforge.common.config.Configuration;
@@ -42,8 +43,8 @@ public class StringListConfigField extends AListConfigField<String[]> {
private final Pattern pattern;
private final int maxStringLength;
public StringListConfigField(Field field, Configuration configuration, String category) throws ConfigException {
super(field, configuration, category, Property.Type.STRING);
public StringListConfigField(ConfigFieldParameters params) throws ConfigException {
super(params, Property.Type.STRING);
pattern = Optional.ofNullable(field.getAnnotation(Config.Pattern.class))
.map((ptr) -> Pattern.compile(ptr.value()))
.orElse(null);