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 😎)
This commit is contained in:
Chipmunk 2023-01-17 20:51:53 -05:00
parent ada80cf431
commit d0ea9a159d

View file

@ -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, "");