From 3d511788a3ae8a899c884f57c826dd759b83ec04 Mon Sep 17 00:00:00 2001 From: ChomeNS <95471003+ChomeNS@users.noreply.github.com> Date: Sun, 7 May 2023 07:35:20 +0700 Subject: [PATCH] fix MESSAGE exploit !!! --- .../chipmunkmod/modules/CustomChat.java | 21 ++++++++++++------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/src/main/java/land/chipmunk/chipmunkmod/modules/CustomChat.java b/src/main/java/land/chipmunk/chipmunkmod/modules/CustomChat.java index 9731ffc..1983853 100644 --- a/src/main/java/land/chipmunk/chipmunkmod/modules/CustomChat.java +++ b/src/main/java/land/chipmunk/chipmunkmod/modules/CustomChat.java @@ -56,16 +56,21 @@ public class CustomChat { // final String displayName = GsonComponentSerializer.gson().serialize(Component.join(JoinConfiguration.separator(Component.empty()), displayNameComponent.children().get(1))); // TODO: make this code not ohio code.,., - final String sanitizedFormat = format + String sanitizedFormat = format // .replace("\"PREFIX\"", prefix) // .replace("\"DISPLAYNAME\"", displayName) - .replace("USERNAME", username) - - // these 2 lines are toooooo ohio code - .replace("{\"text\":\"MESSAGE\"}", messageWithColor) - .replace("\"extra\":[\"MESSAGE\"],\"color\":", "\"extra\":[" + messageWithColor + "],\"color\":") - - .replace("MESSAGE", sanitizedMessage.replaceAll("&.", "")); // TODO: make this not use regex + .replace("USERNAME", username); + // these 4 lines are toooooo ohio code + if ( + sanitizedFormat.contains("{\"text\":\"MESSAGE\"}") || + sanitizedFormat.contains("\"extra\":[\"MESSAGE\"],\"color\":") + ) { + sanitizedFormat = sanitizedFormat + .replace("{\"text\":\"MESSAGE\"}", messageWithColor) + .replace("\"extra\":[\"MESSAGE\"],\"color\":", "\"extra\":[" + messageWithColor + "],\"color\":"); + } else { + sanitizedFormat = sanitizedFormat.replace("MESSAGE", sanitizedMessage.replaceAll("&.", "")); // TODO: make this not use regex + } CommandCore.INSTANCE.run("minecraft:tellraw @a " + sanitizedFormat); } catch (Exception e) {