diff --git a/src/main/java/land/chipmunk/chipmunkmod/mixin/ClientPlayNetworkHandlerMixin.java b/src/main/java/land/chipmunk/chipmunkmod/mixin/ClientPlayNetworkHandlerMixin.java index 1da9e9f..b62cfd9 100644 --- a/src/main/java/land/chipmunk/chipmunkmod/mixin/ClientPlayNetworkHandlerMixin.java +++ b/src/main/java/land/chipmunk/chipmunkmod/mixin/ClientPlayNetworkHandlerMixin.java @@ -63,6 +63,7 @@ public class ClientPlayNetworkHandlerMixin { RainbowName.INSTANCE.init(); ChomeNSBotCommandSuggestions.INSTANCE.init(); ChomeNSAuth.INSTANCE.init(); + CustomChat.INSTANCE.init(); } @Inject(method = "onPlayerRemove", at = @At("HEAD"), cancellable = true) diff --git a/src/main/java/land/chipmunk/chipmunkmod/modules/CustomChat.java b/src/main/java/land/chipmunk/chipmunkmod/modules/CustomChat.java index a180237..d96bb08 100644 --- a/src/main/java/land/chipmunk/chipmunkmod/modules/CustomChat.java +++ b/src/main/java/land/chipmunk/chipmunkmod/modules/CustomChat.java @@ -16,6 +16,8 @@ import net.minecraft.client.network.ClientPlayerEntity; import net.minecraft.text.Text; import java.nio.charset.StandardCharsets; +import java.util.Timer; +import java.util.TimerTask; import java.util.regex.Matcher; import java.util.regex.Pattern; @@ -30,12 +32,49 @@ public class CustomChat { public String format; + private Timer timer; + + private int total = 0; + public CustomChat (MinecraftClient client) { this.client = client; reloadFormat(); } + public void init () { + final TimerTask task = new TimerTask() { + public void run () { + tick(); + } + }; + + if (timer != null) reset(); + + timer = new Timer(); + timer.schedule(task, 0, 50); + } + + private void tick () { + final ClientPlayNetworkHandler networkHandler = client.getNetworkHandler(); + + if (networkHandler != null) return; + + reset(); + cleanup(); + } + + private void reset () { + total = 0; + } + + private void cleanup () { + if (timer == null) return; + + timer.cancel(); + timer.purge(); + } + public void reloadFormat () { final JsonElement formatString = ChipmunkMod.CONFIG.customChat.format; @@ -75,17 +114,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) + .hashString(key + total, StandardCharsets.UTF_8) .toString() .substring(0, 8) : ""; + total++; + try { // final MutablePlayerListEntry entry = Players.INSTANCE.getEntry(client.getNetworkHandler().getProfile().getId());