From 2823095542479568ec6d8d1624596e884bea0582 Mon Sep 17 00:00:00 2001 From: HacktheTime Date: Sat, 14 Oct 2023 17:00:53 +0200 Subject: more changes (fixes) --- .../java/de/hype/bbsentials/fabric/FabricChat.java | 39 ++++++++++++++++++++-- 1 file changed, 36 insertions(+), 3 deletions(-) (limited to 'fabric/src/main/java') diff --git a/fabric/src/main/java/de/hype/bbsentials/fabric/FabricChat.java b/fabric/src/main/java/de/hype/bbsentials/fabric/FabricChat.java index 0244181..d4fefd3 100644 --- a/fabric/src/main/java/de/hype/bbsentials/fabric/FabricChat.java +++ b/fabric/src/main/java/de/hype/bbsentials/fabric/FabricChat.java @@ -9,28 +9,61 @@ import net.minecraft.client.MinecraftClient; import net.minecraft.text.Text; public class FabricChat implements MCChat { + public Chat chat = new Chat(); + public FabricChat() { init(); } - public Chat chat = new Chat(); + public void init() { // Register a callback for a custom message type ClientReceiveMessageEvents.CHAT.register((message, signedMessage, sender, params, receptionTimestamp) -> { - chat.onEvent(new Message(Text.Serializer.toJson(message),message.getString())); + chat.onEvent(new Message(Text.Serializer.toJson(message), message.getString())); + }); + ClientReceiveMessageEvents.MODIFY_GAME.register((message, actionbar) -> { + if (!actionbar) { + return prepareOnEvent(message, actionbar); + } + return message; }); - ClientReceiveMessageEvents.MODIFY_GAME.register((message, overlay) -> (Text.Serializer.fromJson(chat.onEvent(new Message(Text.Serializer.toJson(message),message.getString())).getJson()))); ClientSendMessageEvents.CHAT.register(message -> { if (message.startsWith("/")) { System.out.println("Sent command: " + message); } }); } + + public Text prepareOnEvent(Text text, boolean actionbar) { + String json = Text.Serializer.toJson(text); + Message message = new Message(json, text.getString(), actionbar); + Message returned = chat.onEvent(message); + Text toReturn = Text.Serializer.fromJson(returned.getJson()); + return toReturn; + } + public void sendClientSideMessage(Message message) { MinecraftClient client = MinecraftClient.getInstance(); if (client.player != null) { client.player.sendMessage(Text.Serializer.fromJson(message.getJson())); } } + + public void sendClientSideMessage(Message message, boolean actionbar) { + if (actionbar) { + showActionBar(message); + } + else { + sendClientSideMessage(message); + } + } + + public void showActionBar(Message message) { + MinecraftClient client = MinecraftClient.getInstance(); + if (client.player != null) { + client.player.sendMessage(Text.Serializer.fromJson(message.getJson()), true); + } + } + public void sendChatMessage(String message) { MinecraftClient.getInstance().getNetworkHandler().sendChatMessage(message); } -- cgit