From d0ea9a159deef4887f7185a5fa3739fc8dbda0bf Mon Sep 17 00:00:00 2001 From: Chip <65827213+ChipmunkMC@users.noreply.github.com> Date: Tue, 17 Jan 2023 20:51:53 -0500 Subject: [PATCH] Fixes relating to translation formats with %index$s Offset the index as needed and fix OOB indexes like in `%0$s` (the notchian client does not handle oob indexes correctly but that just means my code is better :sunglasses:) --- .../land/chipmunk/chipmunkbot/chat/ComponentUtilities.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/main/java/land/chipmunk/chipmunkbot/chat/ComponentUtilities.java b/src/main/java/land/chipmunk/chipmunkbot/chat/ComponentUtilities.java index bd0042a..d746295 100644 --- a/src/main/java/land/chipmunk/chipmunkbot/chat/ComponentUtilities.java +++ b/src/main/java/land/chipmunk/chipmunkbot/chat/ComponentUtilities.java @@ -70,7 +70,7 @@ public class ComponentUtilities { public static String stringifyPartially (TranslatableComponent message) { String format = getOrReturnKey(language, message.key()); - // totallynotskidded™️ from HBot + // totallynotskidded™️ from HBot (and changed a bit) Matcher matcher = ARG_PATTERN.matcher(format); StringBuffer sb = new StringBuffer(); @@ -80,8 +80,8 @@ public class ComponentUtilities { matcher.appendReplacement(sb, "%"); } else { String idxStr = matcher.group(1); - int idx = idxStr == null ? i++ : Integer.parseInt(idxStr); - if (idx < message.args().size()) { + int idx = (idxStr == null ? i++ : Integer.parseInt(idxStr)) - 1; + if (idx >= 0 && idx < message.args().size()) { matcher.appendReplacement(sb, Matcher.quoteReplacement( stringify(message.args().get(idx)) )); } else { matcher.appendReplacement(sb, "");