From 44fe1eafb148191f0e5737f59dae7507cc6ed496 Mon Sep 17 00:00:00 2001 From: James Seibel Date: Sun, 21 Jul 2024 16:09:46 -0500 Subject: [PATCH] Fix ConfigEntry String value saving --- .../interfaces/config/IConfigEntry.java | 3 +- .../core/config/types/ConfigEntry.java | 28 +++++++++++++++---- 2 files changed, 25 insertions(+), 6 deletions(-) diff --git a/api/src/main/java/com/seibel/distanthorizons/coreapi/interfaces/config/IConfigEntry.java b/api/src/main/java/com/seibel/distanthorizons/coreapi/interfaces/config/IConfigEntry.java index a31745a8e..3297a1a26 100644 --- a/api/src/main/java/com/seibel/distanthorizons/coreapi/interfaces/config/IConfigEntry.java +++ b/api/src/main/java/com/seibel/distanthorizons/coreapi/interfaces/config/IConfigEntry.java @@ -67,10 +67,11 @@ public interface IConfigEntry * Checks if the option is valid * * 0 == valid + * 2 == invalid * 1 == number too high * -1 == number too low */ - byte isValid(); + byte isValid(); // TODO replace with an enum /** Checks if a value is valid */ byte isValid(T value); diff --git a/core/src/main/java/com/seibel/distanthorizons/core/config/types/ConfigEntry.java b/core/src/main/java/com/seibel/distanthorizons/core/config/types/ConfigEntry.java index 12bb99e36..5ef257666 100644 --- a/core/src/main/java/com/seibel/distanthorizons/core/config/types/ConfigEntry.java +++ b/core/src/main/java/com/seibel/distanthorizons/core/config/types/ConfigEntry.java @@ -256,20 +256,38 @@ public class ConfigEntry extends AbstractConfigType> implem public byte isValid(T value, T min, T max) { if (this.configBase.disableMinMax) + { return 0; - - if (value == null || this.value == null || value.getClass() != this.value.getClass()) // If the 2 variables aren't the same type then it will be invalid + } + else if (min == null && max == null) + { + // no validation is needed for this field + return 0; + } + else if (value == null || this.value == null + || 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 + } + else if (Number.class.isAssignableFrom(value.getClass())) + { + // Only check min max if it is a number if (max != null && NumberUtil.greaterThan((Number) value, (Number) max)) + { return 1; + } if (min != null && NumberUtil.lessThan((Number) value, (Number) min)) + { return -1; + } return 0; } - return 0; + else + { + return 0; + } } /** This should normally not be called since set() automatically calls this */