Skip to content

Commit

Permalink
Tweak #tryCondenseMessage to curb potential errors
Browse files Browse the repository at this point in the history
  • Loading branch information
mrbuilder1961 committed Jun 24, 2024
1 parent 3259f96 commit bc5b0cd
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
1 change: 1 addition & 0 deletions changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -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!
Expand Down
10 changes: 8 additions & 2 deletions src/main/java/obro1961/chatpatches/util/ChatUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,8 @@ public static MutableText buildMessage(Style rootStyle, Text first, Text second,
* @implNote
* <ol>
* <li>Don't modify when {@code refreshing} is true, as that signifies
* re-rendering chat messages, so simply return {@code m}.</li>
* re-rendering chat messages; nor when the chat log is restoring,
* so simply return {@code m}.</li>
* <li>Declare relevant variables, most notably the {@code timestamp}
* and {@code content} components.</li>
* <li>Reconstruct the player message if it should be reformatted
Expand Down Expand Up @@ -292,9 +293,14 @@ public static Text tryCondenseMessage(Text incoming, int index) {
final List<ChatHudLine> messages = chat.chatpatches$getMessages();
final List<ChatHudLine.Visible> 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<Text> comparingParts = comparingLine.content().getSiblings();
List<Text> incomingParts = new ArrayList<>( incoming.getSiblings() ); // prevents UOEs (1.20.3+ only)
List<Text> incomingParts = new ArrayList<>( incoming.getSiblings() ); // prevents UOEs for 1.20.3+


// IF the comparing and incoming message bodies are case-insensitively equal,
Expand Down

0 comments on commit bc5b0cd

Please sign in to comment.