Skip to content

Commit

Permalink
Fix single quotes in status breaking formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
mattboy9921 committed Jan 8, 2022
1 parent 576e46d commit 7e80665
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/main/java/net/mattlabs/crewchat/messaging/Messages.java
Original file line number Diff line number Diff line change
Expand Up @@ -1407,7 +1407,7 @@ public Component chatMessage(String prefix, String playerName, String time, Stri
return Component.text()
.append(MessageUtil.reparse(MiniMessage.get().parse("<click:suggest_command:/msg " + playerName + " >" +
"<hover:show_text:'<white>" + time + "\n" +
MessageUtil.sanitizeMessage(WordUtils.capitalize(this.status)) + ": " + status + "<reset>\n" +
MessageUtil.sanitizeMessage(WordUtils.capitalize(this.status)) + ": " + MessageUtil.escapeSingleQuotes(status) + "<reset>\n" +
(isParty ? WordUtils.capitalize(MessageUtil.sanitizeMessage(party)) : MessageUtil.sanitizeMessage(WordUtils.capitalize(this.channel))) + ": " + "<" + textColor.asHexString() + ">" + activeChannel + "'>" +
(showChannelName ? "<gray>[</gray><" + textColor.asHexString() + ">" + activeChannel + "</color:" + textColor.asHexString() + "><gray>]</gray> " : "") +
chatMessageHeader + "<reset><" + textColor.asHexString() + ">",
Expand All @@ -1426,7 +1426,7 @@ public Component discordMessage(String discordHeader, String prefix, String play
// [Discord] %prefix%%playerName%: %message%
return Component.text()
.append(MessageUtil.reparse(MiniMessage.get().parse("<hover:show_text:'<white>" + time + "\n" +
MessageUtil.sanitizeMessage(WordUtils.capitalize(this.status)) + ": " + status + "\n" +
MessageUtil.sanitizeMessage(WordUtils.capitalize(this.status)) + ": " + MessageUtil.escapeSingleQuotes(status) + "\n" +
MessageUtil.sanitizeMessage(WordUtils.capitalize(this.channel)) + ": " + "<" + textColor.asHexString() + ">" + activeChannel + "'>" +
discordMessageHeader + "</hover>",
"discord", discordHeader,
Expand Down
5 changes: 5 additions & 0 deletions src/main/java/net/mattlabs/crewchat/util/MessageUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,11 @@ public static ArrayList<Player> getMentionedPlayers(String message, ArrayList<Pl
return mentionedPlayers;
}

// Parses strings for unescaped single quotes (') and escapes them
public static String escapeSingleQuotes(String message) {
return message.replaceAll("/(?<!\\\\)'/", "\\'");
}

// Removes any legacy codes/MiniMessage tags
public static String sanitizeMessage(String message) {
message = MiniMessage.get().serialize(LegacyComponentSerializer.legacy('&').deserialize(message));
Expand Down

0 comments on commit 7e80665

Please sign in to comment.