diff --git a/core/src/main/java/com/seibel/lod/core/config/Config.java b/core/src/main/java/com/seibel/lod/core/config/Config.java index b4dd0be44..1c98cbbee 100644 --- a/core/src/main/java/com/seibel/lod/core/config/Config.java +++ b/core/src/main/java/com/seibel/lod/core/config/Config.java @@ -841,7 +841,7 @@ public class Config .build(); public static ConfigEntry longTest = new ConfigEntry.Builder() - .set(42069l) + .set(42069L) .build(); public static ConfigEntry floatTest = new ConfigEntry.Builder() @@ -857,7 +857,7 @@ public class Config .build(); public static ConfigEntry> mapTest = new ConfigEntry.Builder>() - .set(new HashMap<>()) + .set(new HashMap()) .build(); } diff --git a/core/src/main/java/com/seibel/lod/core/config/ConfigBase.java b/core/src/main/java/com/seibel/lod/core/config/ConfigBase.java index b94cf0653..da104a63a 100644 --- a/core/src/main/java/com/seibel/lod/core/config/ConfigBase.java +++ b/core/src/main/java/com/seibel/lod/core/config/ConfigBase.java @@ -23,7 +23,6 @@ public class ConfigBase { /** Our own config instance, don't modify */ public static ConfigBase INSTANCE; - /** Our own config instance, dont modify */ public ConfigFileHandling configFileINSTANCE; public static final Logger LOGGER = LogManager.getLogger(ConfigBase.class.getSimpleName()); @@ -59,13 +58,15 @@ public class ConfigBase add(Long.class); add(Float.class); add(String.class); + + // TODO[CONFIG]: Check the type of these is valid add(List.class); add(ArrayList.class); - add(Map.class); // TODO[CONFIG]: This is handled separately to check the first input is String and the second input is valid + add(Map.class); add(HashMap.class); }}; - /** Disables the minimum and maximum of a variable */ + /** Disables the minimum and maximum of any variable */ public boolean disableMinMax = false; // Very fun to use public final List> entries = new ArrayList<>(); diff --git a/core/src/main/java/com/seibel/lod/core/config/file/ConfigTypeConverters.java b/core/src/main/java/com/seibel/lod/core/config/file/ConfigTypeConverters.java index fa6adb6a0..f7fa0033c 100644 --- a/core/src/main/java/com/seibel/lod/core/config/file/ConfigTypeConverters.java +++ b/core/src/main/java/com/seibel/lod/core/config/file/ConfigTypeConverters.java @@ -16,6 +16,8 @@ import java.util.Map; public class ConfigTypeConverters { // Once you've made a converter add it to here where the first value is the type you want to convert and the 2nd value is the converter public static final Map convertObjects = new HashMap() {{ + put(Short.class, new ShortConverter()); + put(Long.class, new LongConverter()); put(Float.class, new FloatConverter()); put(Byte.class, new ByteConverter()); @@ -51,8 +53,16 @@ public class ConfigTypeConverters { - // Float and Bytes are a bit wack with the config parser + // Some number types are a bit wack with the config parser // So we just store them as strings + public static class ShortConverter extends ConverterBase { + @Override public String convertToString(Object item) { return ((Short) item).toString(); } + @Override public Short convertFromString(String s) { return Short.valueOf(s); } + } + public static class LongConverter extends ConverterBase { + @Override public String convertToString(Object item) { return ((Long) item).toString(); } + @Override public Long convertFromString(String s) { return Long.valueOf(s); } + } public static class FloatConverter extends ConverterBase { @Override public String convertToString(Object item) { return ((Float) item).toString(); } @Override public Float convertFromString(String s) { return Float.valueOf(s); } diff --git a/core/src/main/java/com/seibel/lod/core/config/types/ConfigEntry.java b/core/src/main/java/com/seibel/lod/core/config/types/ConfigEntry.java index ea70c7e38..8114175aa 100644 --- a/core/src/main/java/com/seibel/lod/core/config/types/ConfigEntry.java +++ b/core/src/main/java/com/seibel/lod/core/config/types/ConfigEntry.java @@ -146,7 +146,14 @@ public class ConfigEntry extends AbstractConfigType> implem */ @Override public byte isValid() { return isValid(this.value); } - /** Checks if a value is valid */ + /** + * Checks if a new value is valid + * + * @return 0 == valid + *

2 == invalid + *

1 == number too high + *

-1 == number too low + */ @Override public byte isValid(T value) { if (this.configBase.disableMinMax) @@ -155,9 +162,9 @@ public class ConfigEntry extends AbstractConfigType> implem if (value.getClass() != this.value.getClass()) // If the 2 variables aren't the same type then it will be invalid return 2; if (Number.class.isAssignableFrom(value.getClass())) { // Only check min max if it is a number - if (this.max != null && Double.parseDouble(value.toString()) > Double.parseDouble(max.toString())) // TODO: Use something larger and more precise like float + if (this.max != null && Float.parseFloat(value.toString()) > Float.parseFloat(max.toString())) return 1; - if (this.min != null && Double.parseDouble(value.toString()) < Double.parseDouble(min.toString())) + if (this.min != null && Float.parseFloat(value.toString()) < Float.parseFloat(min.toString())) return -1; return 0;