From 709972ffd493632949282ca848fee848146a01ad Mon Sep 17 00:00:00 2001 From: HacktheTime Date: Sun, 10 Dec 2023 21:25:48 +0100 Subject: crash fix with NumPad Codes when typing a dot. --- .../java/de/hype/bbsentials/fabric/DoubleFieldWidget.java | 2 +- .../de/hype/bbsentials/fabric/IntegerFieldWidget.java | 15 +++++++-------- 2 files changed, 8 insertions(+), 9 deletions(-) (limited to 'fabric') diff --git a/fabric/src/main/java/de/hype/bbsentials/fabric/DoubleFieldWidget.java b/fabric/src/main/java/de/hype/bbsentials/fabric/DoubleFieldWidget.java index 968cb92..67cbf21 100644 --- a/fabric/src/main/java/de/hype/bbsentials/fabric/DoubleFieldWidget.java +++ b/fabric/src/main/java/de/hype/bbsentials/fabric/DoubleFieldWidget.java @@ -20,7 +20,7 @@ public class DoubleFieldWidget extends IntegerFieldWidget { @Override public boolean charTyped(char chr, int modifiers) { - if (chr == '.' || chr == ',') return super.typeChar('.', modifiers); + if (chr == '.' || chr == ',') return super.typeChar('.', modifiers, true); return super.charTyped(chr, modifiers); } diff --git a/fabric/src/main/java/de/hype/bbsentials/fabric/IntegerFieldWidget.java b/fabric/src/main/java/de/hype/bbsentials/fabric/IntegerFieldWidget.java index fbbd649..d5f9a2e 100644 --- a/fabric/src/main/java/de/hype/bbsentials/fabric/IntegerFieldWidget.java +++ b/fabric/src/main/java/de/hype/bbsentials/fabric/IntegerFieldWidget.java @@ -20,6 +20,13 @@ public class IntegerFieldWidget extends TextFieldWidget { @Override public boolean charTyped(char chr, int modifiers) { + return typeChar(chr, modifiers, false); + } + + public boolean typeChar(char chr, int modifiers, boolean doNotBlock) { + if (doNotBlock) { + return super.charTyped(chr, modifiers); + } // Allow removal (backspace and delete) and specific key combinations (Ctrl+A) if (chr == 8 || chr == 127 || (modifiers & 1) == 1) { return super.charTyped(chr, modifiers); @@ -30,12 +37,4 @@ public class IntegerFieldWidget extends TextFieldWidget { } return false; // Block other characters } - - /** - * Use this to bypass the check from the own charTyped. Passes this to the super Class of this. - */ - public boolean typeChar(char chr, int modifiers) { - return charTyped(chr, modifiers); - } - } -- cgit