diff --git a/src/main/java/land/chipmunk/chipmunkmod/Configuration.java b/src/main/java/land/chipmunk/chipmunkmod/Configuration.java index f7f2021..e33fb4e 100644 --- a/src/main/java/land/chipmunk/chipmunkmod/Configuration.java +++ b/src/main/java/land/chipmunk/chipmunkmod/Configuration.java @@ -25,7 +25,7 @@ public class Configuration { public BotInfo hbot = new BotInfo("#", null); public BotInfo sbot = new BotInfo(":", null); public BotInfo chipmunk = new BotInfo("'", null); - public ChomeNSBotInfo chomens = new ChomeNSBotInfo("*", null, null); + public ChomeNSBotInfo chomens = new ChomeNSBotInfo("*", null, null, null); public BotInfo kittycorp = new BotInfo("^", null); public TestBotInfo testbot = new TestBotInfo("-", null); } @@ -34,11 +34,13 @@ public class Configuration { public String prefix; public String key; public String authKey; + public String formatKey; - public ChomeNSBotInfo (String prefix, String key, String authKey) { + public ChomeNSBotInfo (String prefix, String key, String authKey, String formatKey) { this.prefix = prefix; this.key = key; this.authKey = authKey; + this.formatKey = formatKey; } } diff --git a/src/main/java/land/chipmunk/chipmunkmod/modules/CustomChat.java b/src/main/java/land/chipmunk/chipmunkmod/modules/CustomChat.java index 6a59ae8..a180237 100644 --- a/src/main/java/land/chipmunk/chipmunkmod/modules/CustomChat.java +++ b/src/main/java/land/chipmunk/chipmunkmod/modules/CustomChat.java @@ -1,5 +1,6 @@ package land.chipmunk.chipmunkmod.modules; +import com.google.common.hash.Hashing; import com.google.gson.JsonElement; import land.chipmunk.chipmunkmod.ChipmunkMod; @@ -14,6 +15,7 @@ import net.minecraft.client.network.ClientPlayNetworkHandler; import net.minecraft.client.network.ClientPlayerEntity; import net.minecraft.text.Text; +import java.nio.charset.StandardCharsets; import java.util.regex.Matcher; import java.util.regex.Pattern; @@ -73,6 +75,17 @@ public class CustomChat { final Component deserialized = serializer.deserialize(message); final String messageWithColor = GsonComponentSerializer.gson().serialize(deserialized).replace("MESSAGE", randomized); + final long time = System.currentTimeMillis() / 10_000; + + final String key = ChipmunkMod.CONFIG.bots.chomens.formatKey; + + final String hash = key != null ? + Hashing.sha256() + .hashString(key + key + time + time, StandardCharsets.UTF_8) + .toString() + .substring(0, 8) : + ""; + try { // final MutablePlayerListEntry entry = Players.INSTANCE.getEntry(client.getNetworkHandler().getProfile().getId()); @@ -86,9 +99,10 @@ public class CustomChat { // .replace("\"PREFIX\"", prefix) // .replace("\"DISPLAYNAME\"", displayName) .replace("USERNAME", username) + .replace("HASH", hash) .replace("{\"text\":\"MESSAGE\"}", messageWithColor) .replace("\"extra\":[\"MESSAGE\"],\"color\":", "\"extra\":[" + messageWithColor + "],\"color\":") - .replace("MESSAGE", sanitizedMessage.replaceAll("&.", "")) // TODO: make this not use regex + .replace("MESSAGE", sanitizedMessage.replaceAll("&.", "")) .replace(randomized, "MESSAGE"); // ohio ohio CommandCore.INSTANCE.run((KaboomCheck.INSTANCE.isKaboom ? "minecraft:tellraw @a " : "tellraw @a ") + sanitizedFormat); diff --git a/src/main/resources/default_config.json b/src/main/resources/default_config.json index 35bf4af..3ce37ff 100644 --- a/src/main/resources/default_config.json +++ b/src/main/resources/default_config.json @@ -14,7 +14,7 @@ "hbot": { "prefix": "#", "key": null }, "sbot": { "prefix": ":", "key": null }, "chipmunk": { "prefix": "'", "key": null }, - "chomens": { "prefix": "*", "key": null, "authKey": null }, + "chomens": { "prefix": "*", "key": null, "authKey": null, "formatKey": null }, "kittycorp": { "prefix": "^", "key": null }, "testbot": { "prefix": "-", "webhookUrl": null } },