From 4ab5a9285103317f26ab27a91403870a360f55be Mon Sep 17 00:00:00 2001 From: beanbeanjuice Date: Sat, 31 Aug 2024 03:42:42 -0400 Subject: [PATCH] Added Escaped Username Placeholder --- README.md | 1 + .../com/beanbeanjuice/simpleproxychat/chat/ChatHandler.java | 5 +++++ .../beanbeanjuice/simpleproxychat/utility/helper/Helper.java | 4 ++++ 3 files changed, 10 insertions(+) diff --git a/README.md b/README.md index c791fb4..1eee4d6 100644 --- a/README.md +++ b/README.md @@ -335,6 +335,7 @@ file-version: 9 * `%from%` - The server the player just disconnected from. Uses the alias if one is specified. * `%original_from%` - Same as `%from%`, but does not use the alias. * `%player%` - The player's Minecraft username. +* `%escaped_player%` - The escaped player's Minecraft username. (Adds '\\' before the '_' to prevent italics.) * `%sender%` - The person sending the private message. **Private Messaging Only** * `%receiver%` - The person receiving the private message. **Private Messaging Only** * `%user%` - The player's Discord username. diff --git a/projects/main-app/src/main/java/com/beanbeanjuice/simpleproxychat/chat/ChatHandler.java b/projects/main-app/src/main/java/com/beanbeanjuice/simpleproxychat/chat/ChatHandler.java index 2df02fc..9fc808a 100644 --- a/projects/main-app/src/main/java/com/beanbeanjuice/simpleproxychat/chat/ChatHandler.java +++ b/projects/main-app/src/main/java/com/beanbeanjuice/simpleproxychat/chat/ChatHandler.java @@ -120,6 +120,7 @@ public void runProxyChatMessage(ChatMessageData chatMessageData) { replacements.add(Tuple.of("to", aliasedServerName)); replacements.add(Tuple.of("original_to", serverName)); replacements.add(Tuple.of("player", playerName)); + replacements.add(Tuple.of("escaped_player", Helper.escapeString(playerName))); replacements.add(Tuple.of("epoch", String.valueOf(epochHelper.getEpochSecond()))); replacements.add(Tuple.of("time", getTimeString())); replacements.add(Tuple.of("plugin-prefix", config.get(ConfigKey.PLUGIN_PREFIX).asString())); @@ -144,6 +145,7 @@ public void runProxyChatMessage(ChatMessageData chatMessageData) { chat(chatMessageData, minecraftMessage, discordMessage, discordEmbedTitle, discordEmbedMessage); } + public void runProxyLeaveMessage(String playerName, UUID playerUUID, String serverName, BiConsumer minecraftLogger) { String configString = config.get(ConfigKey.MINECRAFT_LEAVE).asString(); @@ -153,6 +155,7 @@ public void runProxyLeaveMessage(String playerName, UUID playerUUID, String serv List> replacements = new ArrayList<>(); replacements.add(Tuple.of("player", playerName)); + replacements.add(Tuple.of("escaped_player", Helper.escapeString(playerName))); replacements.add(Tuple.of("server", aliasedServerName)); replacements.add(Tuple.of("original_server", serverName)); replacements.add(Tuple.of("to", aliasedServerName)); @@ -191,6 +194,7 @@ public void runProxyJoinMessage(String playerName, UUID playerUUID, String serve List> replacements = new ArrayList<>(); replacements.add(Tuple.of("player", playerName)); + replacements.add(Tuple.of("escaped_player", Helper.escapeString(playerName))); replacements.add(Tuple.of("server", Helper.convertAlias(config, serverName))); replacements.add(Tuple.of("to", Helper.convertAlias(config, serverName))); replacements.add(Tuple.of("server", aliasedServerName)); @@ -239,6 +243,7 @@ public void runProxySwitchMessage(String from, String to, String playerName, UUI replacements.add(Tuple.of("server", aliasedTo)); replacements.add(Tuple.of("original_server", to)); replacements.add(Tuple.of("player", playerName)); + replacements.add(Tuple.of("escaped_player", Helper.escapeString(playerName))); replacements.add(Tuple.of("epoch", String.valueOf(epochHelper.getEpochSecond()))); replacements.add(Tuple.of("time", getTimeString())); replacements.add(Tuple.of("plugin-prefix", config.get(ConfigKey.PLUGIN_PREFIX).asString())); diff --git a/projects/main-app/src/main/java/com/beanbeanjuice/simpleproxychat/utility/helper/Helper.java b/projects/main-app/src/main/java/com/beanbeanjuice/simpleproxychat/utility/helper/Helper.java index 3e8a23d..76bbaa3 100644 --- a/projects/main-app/src/main/java/com/beanbeanjuice/simpleproxychat/utility/helper/Helper.java +++ b/projects/main-app/src/main/java/com/beanbeanjuice/simpleproxychat/utility/helper/Helper.java @@ -142,4 +142,8 @@ public static String replaceKeys(String string, Tuple... entries return string; } + public static String escapeString(String string) { + return string.replaceAll("_", "\\_"); + } + }