diff options
author | HacktheTime <l4bg0jb7@duck.com> | 2023-10-14 17:00:53 +0200 |
---|---|---|
committer | HacktheTime <l4bg0jb7@duck.com> | 2023-10-14 17:00:53 +0200 |
commit | 2823095542479568ec6d8d1624596e884bea0582 (patch) | |
tree | 099f2ebe75556061ba49ae948b21f83c6a35381c /fabric/src | |
parent | 77fb80356b42260a95610aa5971d2b03d8d30e1d (diff) | |
download | BBsentials-2823095542479568ec6d8d1624596e884bea0582.tar.gz BBsentials-2823095542479568ec6d8d1624596e884bea0582.tar.bz2 BBsentials-2823095542479568ec6d8d1624596e884bea0582.zip |
more changes (fixes)
Diffstat (limited to 'fabric/src')
-rw-r--r-- | fabric/src/main/java/de/hype/bbsentials/fabric/FabricChat.java | 39 |
1 files changed, 36 insertions, 3 deletions
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); } |