From ab62c62079d01cfb80afd3776a7234a09d4697f2 Mon Sep 17 00:00:00 2001 From: coolGi Date: Mon, 17 Jul 2023 00:27:32 +0930 Subject: [PATCH] Fixed values being able to go over number limit --- .../common/wrappers/gui/ClassicConfigGUI.java | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/common/src/main/java/com/seibel/distanthorizons/common/wrappers/gui/ClassicConfigGUI.java b/common/src/main/java/com/seibel/distanthorizons/common/wrappers/gui/ClassicConfigGUI.java index ccd573db3..73826aa76 100644 --- a/common/src/main/java/com/seibel/distanthorizons/common/wrappers/gui/ClassicConfigGUI.java +++ b/common/src/main/java/com/seibel/distanthorizons/common/wrappers/gui/ClassicConfigGUI.java @@ -118,12 +118,19 @@ public class ClassicConfigGUI Number value = 0; ((EntryInfo) info.guiValue).error = null; if (isNumber && !stringValue.isEmpty() && !stringValue.equals("-") && !stringValue.equals(".")) { - value = func.apply(stringValue); + try { + value = func.apply(stringValue); + } catch (Exception e) { + value = null; + } + byte isValid = ((ConfigEntry) info).isValid(value); - ((EntryInfo) info.guiValue).error = isValid == 0 ? null : - new AbstractMap.SimpleEntry<>(editBox, TextOrTranslatable(isValid == -1 ? - "§cMinimum " + "length" + (cast ? " is " + (int) ((ConfigEntry) info).getMin() : " is " + ((ConfigEntry) info).getMin()) : - "§cMaximum " + "length" + (cast ? " is " + (int) ((ConfigEntry) info).getMax() : " is " + ((ConfigEntry) info).getMax()))); + switch (isValid) { + case 0: ((EntryInfo) info.guiValue).error = null; break; + case -1: ((EntryInfo) info.guiValue).error = new AbstractMap.SimpleEntry<>(editBox, TextOrTranslatable("§cMinimum length is " + ((ConfigEntry) info).getMin())); break; + case 1: ((EntryInfo) info.guiValue).error = new AbstractMap.SimpleEntry<>(editBox, TextOrTranslatable("§cMaximum length is " + ((ConfigEntry) info).getMax())); break; + case 2: ((EntryInfo) info.guiValue).error = new AbstractMap.SimpleEntry<>(editBox, TextOrTranslatable("§cValue is invalid")); break; + } } ((EntryInfo) info.guiValue).tempValue = stringValue;