From bc5b0cd5b726de1d15912c8f645d273d086feeee Mon Sep 17 00:00:00 2001 From: OBro1961 Date: Mon, 24 Jun 2024 18:08:39 -0500 Subject: [PATCH] Tweak #tryCondenseMessage to curb potential errors --- changelog.md | 1 + src/main/java/obro1961/chatpatches/util/ChatUtils.java | 10 ++++++++-- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/changelog.md b/changelog.md index 9a27ee1..85e1e93 100644 --- a/changelog.md +++ b/changelog.md @@ -3,6 +3,7 @@ ## Chat Patches `210.6.5.1` for Minecraft 1.21 on Fabric, Quilt - Fix incompatibility with 1.20.5-6 (we were THIS close) ([#177](https://github.com/mrbuilder1961/ChatPatches/issues/177)) - Implement chat log codecification from the WIP branch ([#178](https://www.github.com/mrbuilder1961/ChatPatches/issues/178)) +- Tweaked a part of `ChatUtils#tryCondenseMessage` to hopefully prevent some messages from throwing annoying errors ## Chat Patches `210.6.5` for Minecraft 1.20.5, 1.20.6, 1.21 on Fabric, Quilt - Ported to Minecraft 1.21! diff --git a/src/main/java/obro1961/chatpatches/util/ChatUtils.java b/src/main/java/obro1961/chatpatches/util/ChatUtils.java index c51191c..5ec5edb 100644 --- a/src/main/java/obro1961/chatpatches/util/ChatUtils.java +++ b/src/main/java/obro1961/chatpatches/util/ChatUtils.java @@ -126,7 +126,8 @@ public static MutableText buildMessage(Style rootStyle, Text first, Text second, * @implNote *
    *
  1. Don't modify when {@code refreshing} is true, as that signifies - * re-rendering chat messages, so simply return {@code m}.
  2. + * re-rendering chat messages; nor when the chat log is restoring, + * so simply return {@code m}. *
  3. Declare relevant variables, most notably the {@code timestamp} * and {@code content} components.
  4. *
  5. Reconstruct the player message if it should be reformatted @@ -292,9 +293,14 @@ public static Text tryCondenseMessage(Text incoming, int index) { final List messages = chat.chatpatches$getMessages(); final List visibleMessages = chat.chatpatches$getVisibleMessages(); + // just in case the incoming message is a literal string text w no sibs, + // we can reformat it as to not throw any annoying errors down the line + if(incoming.getContent() instanceof PlainTextContent && incoming.getSiblings().isEmpty()) + incoming = buildMessage(null, null, incoming, null); + ChatHudLine comparingLine = messages.get(index); // message being compared List comparingParts = comparingLine.content().getSiblings(); - List incomingParts = new ArrayList<>( incoming.getSiblings() ); // prevents UOEs (1.20.3+ only) + List incomingParts = new ArrayList<>( incoming.getSiblings() ); // prevents UOEs for 1.20.3+ // IF the comparing and incoming message bodies are case-insensitively equal,