better version of the imposter format

This commit is contained in:
Chayapak 2023-09-24 08:52:37 +07:00
parent c2170ddfcd
commit e0c7804aa7
2 changed files with 43 additions and 3 deletions

View file

@ -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)

View file

@ -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());