better version of the imposter format
This commit is contained in:
parent
c2170ddfcd
commit
e0c7804aa7
2 changed files with 43 additions and 3 deletions
|
@ -63,6 +63,7 @@ public class ClientPlayNetworkHandlerMixin {
|
||||||
RainbowName.INSTANCE.init();
|
RainbowName.INSTANCE.init();
|
||||||
ChomeNSBotCommandSuggestions.INSTANCE.init();
|
ChomeNSBotCommandSuggestions.INSTANCE.init();
|
||||||
ChomeNSAuth.INSTANCE.init();
|
ChomeNSAuth.INSTANCE.init();
|
||||||
|
CustomChat.INSTANCE.init();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Inject(method = "onPlayerRemove", at = @At("HEAD"), cancellable = true)
|
@Inject(method = "onPlayerRemove", at = @At("HEAD"), cancellable = true)
|
||||||
|
|
|
@ -16,6 +16,8 @@ import net.minecraft.client.network.ClientPlayerEntity;
|
||||||
import net.minecraft.text.Text;
|
import net.minecraft.text.Text;
|
||||||
|
|
||||||
import java.nio.charset.StandardCharsets;
|
import java.nio.charset.StandardCharsets;
|
||||||
|
import java.util.Timer;
|
||||||
|
import java.util.TimerTask;
|
||||||
import java.util.regex.Matcher;
|
import java.util.regex.Matcher;
|
||||||
import java.util.regex.Pattern;
|
import java.util.regex.Pattern;
|
||||||
|
|
||||||
|
@ -30,12 +32,49 @@ public class CustomChat {
|
||||||
|
|
||||||
public String format;
|
public String format;
|
||||||
|
|
||||||
|
private Timer timer;
|
||||||
|
|
||||||
|
private int total = 0;
|
||||||
|
|
||||||
public CustomChat (MinecraftClient client) {
|
public CustomChat (MinecraftClient client) {
|
||||||
this.client = client;
|
this.client = client;
|
||||||
|
|
||||||
reloadFormat();
|
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 () {
|
public void reloadFormat () {
|
||||||
final JsonElement formatString = ChipmunkMod.CONFIG.customChat.format;
|
final JsonElement formatString = ChipmunkMod.CONFIG.customChat.format;
|
||||||
|
|
||||||
|
@ -75,17 +114,17 @@ public class CustomChat {
|
||||||
final Component deserialized = serializer.deserialize(message);
|
final Component deserialized = serializer.deserialize(message);
|
||||||
final String messageWithColor = GsonComponentSerializer.gson().serialize(deserialized).replace("MESSAGE", randomized);
|
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 key = ChipmunkMod.CONFIG.bots.chomens.formatKey;
|
||||||
|
|
||||||
final String hash = key != null ?
|
final String hash = key != null ?
|
||||||
Hashing.sha256()
|
Hashing.sha256()
|
||||||
.hashString(key + key + time + time, StandardCharsets.UTF_8)
|
.hashString(key + total, StandardCharsets.UTF_8)
|
||||||
.toString()
|
.toString()
|
||||||
.substring(0, 8) :
|
.substring(0, 8) :
|
||||||
"";
|
"";
|
||||||
|
|
||||||
|
total++;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
// final MutablePlayerListEntry entry = Players.INSTANCE.getEntry(client.getNetworkHandler().getProfile().getId());
|
// final MutablePlayerListEntry entry = Players.INSTANCE.getEntry(client.getNetworkHandler().getProfile().getId());
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue