refactor: remove imposter format in chomens (the HASH thing)

This commit is contained in:
Chayapak Supasakul 2025-04-12 15:15:06 +07:00
parent 79589edc44
commit ccf9600cf1
Signed by: ChomeNS
SSH key fingerprint: SHA256:0YoxhdyXsgbc0nfeB2N6FYE60mxMU7DS4uCUMaw2mvA
4 changed files with 24 additions and 39 deletions

View file

@ -30,7 +30,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 BotInfo chomens = new BotInfo("*", null);
public BotInfo fnfboyfriend = new BotInfo("~", null);
public BotInfo qilk = new BotInfo(">", null);
public BotInfo nbot = new BotInfo("?", null);
@ -38,22 +38,6 @@ public class Configuration {
public TestBotInfo testbot = new TestBotInfo("-", null);
}
@ConfigSerializable
public static class ChomeNSBotInfo {
public String prefix;
public @Nullable String key;
public @Nullable String formatKey;
public ChomeNSBotInfo() {
}
public ChomeNSBotInfo(String prefix, @Nullable String key, @Nullable String formatKey) {
this.prefix = prefix;
this.key = key;
this.formatKey = formatKey;
}
}
@ConfigSerializable
public static class TestBotInfo {
public String prefix;

View file

@ -0,0 +1,21 @@
package land.chipmunk.chipmunkmod.config.migrations;
import land.chipmunk.chipmunkmod.config.migration.ConfigMigration;
import org.spongepowered.configurate.transformation.ConfigurationTransformation;
import org.spongepowered.configurate.transformation.TransformAction;
import static org.spongepowered.configurate.NodePath.path;
public class MigrationV3 implements ConfigMigration {
@Override
public int version() {
return 3;
}
@Override
public ConfigurationTransformation create() {
return ConfigurationTransformation.builder()
.addAction(path("bots", "chomens", "formatKey"), TransformAction.remove())
.build();
}
}

View file

@ -1,6 +1,5 @@
package land.chipmunk.chipmunkmod.modules.custom_chat;
import com.google.common.hash.Hashing;
import land.chipmunk.chipmunkmod.ChipmunkMod;
import land.chipmunk.chipmunkmod.modules.Chat;
@ -17,7 +16,6 @@ import net.minecraft.client.MinecraftClient;
import net.minecraft.client.network.ClientPlayNetworkHandler;
import net.minecraft.client.network.ClientPlayerEntity;
import java.nio.charset.StandardCharsets;
import java.util.Map;
import java.util.Timer;
import java.util.TimerTask;
@ -66,8 +64,6 @@ public class CustomChat {
private Timer timer;
private int total = 0;
public CustomChat (MinecraftClient client) {
this.client = client;
}
@ -79,8 +75,6 @@ public class CustomChat {
}
};
resetTotal();
timer = new Timer();
timer.schedule(task, 0, 50);
}
@ -90,14 +84,9 @@ public class CustomChat {
if (networkHandler != null) return;
resetTotal();
cleanup();
}
public void resetTotal() {
total = 0;
}
private void cleanup () {
if (timer == null) return;
@ -116,18 +105,9 @@ public class CustomChat {
final Component styledMessage = SERIALIZER.deserialize(message);
final String username = MinecraftClient.getInstance().getSession().getUsername();
final String key = ChipmunkMod.CONFIG.bots.chomens.formatKey;
final String hash = key != null ?
Hashing.sha256()
.hashString(key + total, StandardCharsets.UTF_8)
.toString()
.substring(0, 8) :
"";
total++;
final CustomChatContext context = new CustomChatContext(player.getUuidAsString(), styledMessage,
Map.of("MESSAGE", message, "USERNAME", username, "HASH", hash));
Map.of("MESSAGE", message, "USERNAME", username));
final Component renderedFormat = RENDERER.render(ChipmunkMod.CONFIG.customChat.format, context)
.compact();
final String json = GSON.serialize(renderedFormat);

View file

@ -68,7 +68,7 @@ public class BotValidationUtilities {
}
public static int chomens (String command) throws RuntimeException {
final Configuration.ChomeNSBotInfo info = ChipmunkMod.CONFIG.bots.chomens;
final Configuration.BotInfo info = ChipmunkMod.CONFIG.bots.chomens;
final MinecraftClient client = MinecraftClient.getInstance();