aboutsummaryrefslogtreecommitdiff
path: root/fabric/src/main
diff options
context:
space:
mode:
Diffstat (limited to 'fabric/src/main')
-rw-r--r--fabric/src/main/java/de/hype/bbsentials/fabric/FabricChat.java39
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);
}