fix: hopefully patch chinese chat crash (idk)
refactor: rename `addPlural`
This commit is contained in:
@@ -1 +1 @@
|
||||
2475
|
||||
2482
|
||||
@@ -244,13 +244,13 @@ public class InfoCommand extends Command {
|
||||
Component.translatable(
|
||||
"%s %s, %s %s, %s %s, %s %s",
|
||||
Component.text(days),
|
||||
Component.text(StringUtilities.addPluralS(days, "day")),
|
||||
Component.text(StringUtilities.addPlural(days, "day")),
|
||||
Component.text(hours),
|
||||
Component.text(StringUtilities.addPluralS(hours, "hour")),
|
||||
Component.text(StringUtilities.addPlural(hours, "hour")),
|
||||
Component.text(minutes),
|
||||
Component.text(StringUtilities.addPluralS(minutes, "minute")),
|
||||
Component.text(StringUtilities.addPlural(minutes, "minute")),
|
||||
Component.text(seconds),
|
||||
Component.text(StringUtilities.addPluralS(seconds, "second"))
|
||||
Component.text(StringUtilities.addPlural(seconds, "second"))
|
||||
).color(NamedTextColor.GREEN)
|
||||
).color(bot.colorPalette.defaultColor);
|
||||
}
|
||||
|
||||
@@ -296,7 +296,7 @@ public class ChatPlugin extends Bot.Listener {
|
||||
if (!bot.loggedIn) return;
|
||||
|
||||
bot.session.send(new ServerboundChatPacket(
|
||||
message,
|
||||
StringUtilities.truncateToFitUtf8ByteLength(message, 256),
|
||||
Instant.now().toEpochMilli(),
|
||||
0L,
|
||||
null,
|
||||
|
||||
@@ -5,14 +5,8 @@ public class IllegalCharactersUtilities {
|
||||
final StringBuilder replaced = new StringBuilder();
|
||||
|
||||
for (char character : string.toCharArray()) {
|
||||
if (
|
||||
character == '§' ||
|
||||
character == '\u007f' ||
|
||||
|
||||
// check if character is a control code, also space is the first character after
|
||||
// the control characters so this is why we can do `character < ' '`
|
||||
character < ' '
|
||||
) continue;
|
||||
// ripped STRAIGHT from minecraft code
|
||||
if (character == 167 || character < ' ' || character == 127) continue;
|
||||
|
||||
replaced.append(character);
|
||||
}
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
package me.chayapak1.chomens_bot.util;
|
||||
|
||||
import io.netty.buffer.ByteBufUtil;
|
||||
|
||||
import java.nio.ByteBuffer;
|
||||
import java.nio.CharBuffer;
|
||||
import java.nio.charset.Charset;
|
||||
@@ -29,6 +31,12 @@ public class StringUtilities {
|
||||
return removedCommand.toString();
|
||||
}
|
||||
|
||||
public static String substringUtfLimit (String string, int limit) {
|
||||
final int max = ByteBufUtil.utf8MaxBytes(limit);
|
||||
final byte[] bytes = string.getBytes(StandardCharsets.UTF_8);
|
||||
return new String(Arrays.copyOfRange(bytes, 0, max), StandardCharsets.UTF_8);
|
||||
}
|
||||
|
||||
// https://stackoverflow.com/a/35148974/18518424
|
||||
public static String truncateToFitUtf8ByteLength (String s, int maxBytes) {
|
||||
if (s == null) {
|
||||
@@ -72,7 +80,7 @@ public class StringUtilities {
|
||||
return false;
|
||||
}
|
||||
|
||||
public static String addPluralS (long amount, String unit) {
|
||||
public static String addPlural (long amount, String unit) {
|
||||
return amount > 1 ? unit + "s" : unit;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user