From 6a524a6595c9d7b36512de2bd301c7472e3f6ea2 Mon Sep 17 00:00:00 2001 From: ChomeNS <95471003+ChomeNS@users.noreply.github.com> Date: Wed, 8 Jan 2025 17:10:20 +0700 Subject: [PATCH] fix: lazily fix integer overflow on translate placeholder %6942000000000000$s --- build-number.txt | 2 +- .../chomens_bot/util/ComponentUtilities.java | 42 ++++++++++--------- 2 files changed, 23 insertions(+), 21 deletions(-) diff --git a/build-number.txt b/build-number.txt index 7939e3d3..fdbec449 100644 --- a/build-number.txt +++ b/build-number.txt @@ -1 +1 @@ -1458 \ No newline at end of file +1459 \ No newline at end of file diff --git a/src/main/java/me/chayapak1/chomens_bot/util/ComponentUtilities.java b/src/main/java/me/chayapak1/chomens_bot/util/ComponentUtilities.java index 3147c80c..83949652 100644 --- a/src/main/java/me/chayapak1/chomens_bot/util/ComponentUtilities.java +++ b/src/main/java/me/chayapak1/chomens_bot/util/ComponentUtilities.java @@ -301,29 +301,31 @@ public class ComponentUtilities { } else { final String idxStr = matcher.group(1); - int idx = idxStr == null ? i++ : (Integer.parseInt(idxStr) - 1); + try { + int idx = idxStr == null ? i++ : (Integer.parseInt(idxStr) - 1); - if (idx >= 0 && idx < message.arguments().size()) { - final ComponentParser parser = new ComponentParser(); + if (idx >= 0 && idx < message.arguments().size()) { + final ComponentParser parser = new ComponentParser(); - parser.lastStyle = lastStyle + color + style; - parser.depth = depth; - parser.isSubParsing = true; + parser.lastStyle = lastStyle + color + style; + parser.depth = depth; + parser.isSubParsing = true; - matcher.appendReplacement( - sb, - Matcher.quoteReplacement( - parser.stringify( - message.arguments() - .get(idx) - .asComponent(), - type - ) + lastStyle + color + style // IMPORTANT!!!! - ) - ); - } else { - matcher.appendReplacement(sb, ""); - } + matcher.appendReplacement( + sb, + Matcher.quoteReplacement( + parser.stringify( + message.arguments() + .get(idx) + .asComponent(), + type + ) + lastStyle + color + style // IMPORTANT!!!! + ) + ); + } else { + matcher.appendReplacement(sb, ""); + } + } catch (NumberFormatException ignored) {} // is this a good idea? } }