mirror of
https://code.chipmunk.land/ChomeNS/chipmunkmod.git
synced 2025-11-13 18:46:15 +00:00
fix: .customchat format not working
refactor: remove useless timer in CustomChat (not even sure why it's there)
This commit is contained in:
parent
0b31a366cb
commit
69909de327
3 changed files with 9 additions and 35 deletions
|
|
@ -3,8 +3,10 @@ package land.chipmunk.chipmunkmod.commands;
|
|||
import com.mojang.brigadier.Command;
|
||||
import com.mojang.brigadier.CommandDispatcher;
|
||||
import com.mojang.brigadier.context.CommandContext;
|
||||
import land.chipmunk.chipmunkmod.ChipmunkMod;
|
||||
import land.chipmunk.chipmunkmod.modules.custom_chat.CustomChat;
|
||||
import net.fabricmc.fabric.api.client.command.v2.FabricClientCommandSource;
|
||||
import net.kyori.adventure.text.serializer.gson.GsonComponentSerializer;
|
||||
import net.minecraft.text.Text;
|
||||
|
||||
import static com.mojang.brigadier.arguments.BoolArgumentType.bool;
|
||||
|
|
@ -15,6 +17,8 @@ import static land.chipmunk.chipmunkmod.command.CommandManager.argument;
|
|||
import static land.chipmunk.chipmunkmod.command.CommandManager.literal;
|
||||
|
||||
public class CustomChatCommand {
|
||||
private static final GsonComponentSerializer GSON = GsonComponentSerializer.gson();
|
||||
|
||||
public static void register (final CommandDispatcher<FabricClientCommandSource> dispatcher) {
|
||||
dispatcher.register(
|
||||
literal("customchat")
|
||||
|
|
@ -47,7 +51,7 @@ public class CustomChatCommand {
|
|||
public static int setFormat (final CommandContext<FabricClientCommandSource> context) {
|
||||
final FabricClientCommandSource source = context.getSource();
|
||||
final String format = getString(context, "format");
|
||||
CustomChat.INSTANCE.format = format;
|
||||
CustomChat.INSTANCE.format = GSON.deserializeOr(format, ChipmunkMod.CONFIG.customChat.format);
|
||||
source.sendFeedback(Text.literal("Set the custom chat format to: " + format));
|
||||
|
||||
return Command.SINGLE_SUCCESS;
|
||||
|
|
|
|||
|
|
@ -50,7 +50,6 @@ public class ClientPlayNetworkHandlerMixin {
|
|||
SongPlayer.INSTANCE.coreReady();
|
||||
RainbowName.INSTANCE.init();
|
||||
ChomeNSBotCommandSuggestions.INSTANCE.init();
|
||||
CustomChat.INSTANCE.init();
|
||||
}
|
||||
|
||||
@Inject(method = "onCommandTree", at = @At("TAIL"))
|
||||
|
|
|
|||
|
|
@ -12,16 +12,14 @@ import net.kyori.adventure.text.format.TextDecoration;
|
|||
import net.kyori.adventure.text.serializer.gson.GsonComponentSerializer;
|
||||
import net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer;
|
||||
import net.minecraft.client.MinecraftClient;
|
||||
import net.minecraft.client.network.ClientPlayNetworkHandler;
|
||||
import net.minecraft.client.network.ClientPlayerEntity;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.Timer;
|
||||
import java.util.TimerTask;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
public class CustomChat {
|
||||
public static final CustomChat INSTANCE = new CustomChat(MinecraftClient.getInstance());
|
||||
|
||||
private static final GsonComponentSerializer GSON = GsonComponentSerializer.gson();
|
||||
private static final CustomChatComponentRenderer RENDERER = new CustomChatComponentRenderer();
|
||||
private static final LegacyComponentSerializer SERIALIZER = LegacyComponentSerializer
|
||||
|
|
@ -52,43 +50,16 @@ public class CustomChat {
|
|||
.useUnusualXRepeatedCharacterHexFormat() // &x&1&2&3&4&5&6abc
|
||||
|
||||
.build();
|
||||
|
||||
private final MinecraftClient client;
|
||||
public boolean enabled = true;
|
||||
|
||||
public String format;
|
||||
|
||||
private Timer timer;
|
||||
public Component format = ChipmunkMod.CONFIG.customChat.format;
|
||||
|
||||
public CustomChat (final MinecraftClient client) {
|
||||
this.client = client;
|
||||
}
|
||||
|
||||
public void init () {
|
||||
final TimerTask task = new TimerTask() {
|
||||
public void run () {
|
||||
tick();
|
||||
}
|
||||
};
|
||||
|
||||
timer = new Timer();
|
||||
timer.schedule(task, 0, 50);
|
||||
}
|
||||
|
||||
private void tick () {
|
||||
final ClientPlayNetworkHandler networkHandler = client.getNetworkHandler();
|
||||
|
||||
if (networkHandler != null) return;
|
||||
|
||||
cleanup();
|
||||
}
|
||||
|
||||
private void cleanup () {
|
||||
if (timer == null) return;
|
||||
|
||||
timer.cancel();
|
||||
timer.purge();
|
||||
}
|
||||
|
||||
public void chat (final String message) {
|
||||
final ClientPlayerEntity player = client.player;
|
||||
if (player == null) return;
|
||||
|
|
@ -103,7 +74,7 @@ public class CustomChat {
|
|||
|
||||
final CustomChatContext context = new CustomChatContext(player.getUuidAsString(), styledMessage,
|
||||
Map.of("MESSAGE", message, "USERNAME", username));
|
||||
final Component renderedFormat = RENDERER.render(ChipmunkMod.CONFIG.customChat.format, context)
|
||||
final Component renderedFormat = RENDERER.render(format, context)
|
||||
.compact();
|
||||
final String json = GSON.serialize(renderedFormat);
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue