From c6cb3c0ee2f475a98d38110ea451b4444b4917f0 Mon Sep 17 00:00:00 2001 From: RacoonDog <32882447+RacoonDog@users.noreply.github.com> Date: Sun, 24 Sep 2023 09:11:31 -0400 Subject: [PATCH] chat stuff (#251) --- .../netty/viaversion/ViaFabricPlusViaDecoder.java | 3 ++- .../de/florianmichael/viafabricplus/util/ChatUtil.java | 7 ++++++- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/src/main/java/de/florianmichael/viafabricplus/protocolhack/netty/viaversion/ViaFabricPlusViaDecoder.java b/src/main/java/de/florianmichael/viafabricplus/protocolhack/netty/viaversion/ViaFabricPlusViaDecoder.java index 76c3b12a..3b601b22 100644 --- a/src/main/java/de/florianmichael/viafabricplus/protocolhack/netty/viaversion/ViaFabricPlusViaDecoder.java +++ b/src/main/java/de/florianmichael/viafabricplus/protocolhack/netty/viaversion/ViaFabricPlusViaDecoder.java @@ -22,6 +22,7 @@ import de.florianmichael.viafabricplus.ViaFabricPlus; import de.florianmichael.viafabricplus.base.settings.groups.GeneralSettings; import de.florianmichael.viafabricplus.util.ChatUtil; import io.netty.channel.ChannelHandlerContext; +import net.minecraft.text.Text; import net.minecraft.util.Formatting; import net.raphimc.vialoader.netty.ViaDecoder; @@ -41,7 +42,7 @@ public class ViaFabricPlusViaDecoder extends ViaDecoder { } catch (Throwable t) { ViaFabricPlus.LOGGER.error("Error occurred while decoding packet in ViaDecoder", t); if (mode == 1) { - ChatUtil.sendPrefixedMessage(Formatting.RED + "An error occurred while decoding a packet! See more details in the logs!"); + ChatUtil.sendPrefixedMessage(Text.literal("An error occurred while decoding a packet! See more details in the logs!").formatted(Formatting.RED)); } } return; diff --git a/src/main/java/de/florianmichael/viafabricplus/util/ChatUtil.java b/src/main/java/de/florianmichael/viafabricplus/util/ChatUtil.java index f4d24a9e..ed6472e7 100644 --- a/src/main/java/de/florianmichael/viafabricplus/util/ChatUtil.java +++ b/src/main/java/de/florianmichael/viafabricplus/util/ChatUtil.java @@ -23,16 +23,21 @@ import net.minecraft.util.Formatting; public class ChatUtil { public final static String PREFIX = Formatting.WHITE + "[" + Formatting.GOLD + "ViaFabricPlus" + Formatting.WHITE + "]"; + public final static Text PREFIX_TEXT = Text.literal("[").formatted(Formatting.WHITE).append(Text.literal("ViaFabricPlus").formatted(Formatting.GOLD)).append("]"); public static Text prefixText(final String message) { return prefixText(Text.literal(message)); } public static Text prefixText(final Text message) { - return Text.literal("").append(PREFIX).append(" " + message.getString()); + return Text.empty().append(PREFIX_TEXT).append(" ").append(message); } public static void sendPrefixedMessage(final String message) { MinecraftClient.getInstance().inGameHud.getChatHud().addMessage(prefixText(message)); } + + public static void sendPrefixedMessage(final Text message) { + MinecraftClient.getInstance().inGameHud.getChatHud().addMessage(prefixText(message)); + } }