aboutsummaryrefslogtreecommitdiff
path: root/src/main/kotlin/moe/nea/firmament/events/registration
diff options
context:
space:
mode:
authornea <nea@nea.moe>2023-09-04 20:22:51 +0200
committernea <nea@nea.moe>2023-09-04 20:22:51 +0200
commitd202ef5439a180efecc27ab4695b1a12febb041f (patch)
tree959ac68db802d562dee2d92aecbb3741dbcce3b6 /src/main/kotlin/moe/nea/firmament/events/registration
parentee5591684dc6bcdea6c44a62806d537bbb7e0cee (diff)
downloadfirmament-d202ef5439a180efecc27ab4695b1a12febb041f.tar.gz
firmament-d202ef5439a180efecc27ab4695b1a12febb041f.tar.bz2
firmament-d202ef5439a180efecc27ab4695b1a12febb041f.zip
Make chat events use fabric events
[no changelog]
Diffstat (limited to 'src/main/kotlin/moe/nea/firmament/events/registration')
-rw-r--r--src/main/kotlin/moe/nea/firmament/events/registration/ChatEvents.kt42
1 files changed, 42 insertions, 0 deletions
diff --git a/src/main/kotlin/moe/nea/firmament/events/registration/ChatEvents.kt b/src/main/kotlin/moe/nea/firmament/events/registration/ChatEvents.kt
new file mode 100644
index 0000000..90a665a
--- /dev/null
+++ b/src/main/kotlin/moe/nea/firmament/events/registration/ChatEvents.kt
@@ -0,0 +1,42 @@
+/*
+ * SPDX-FileCopyrightText: 2023 Linnea Gräf <nea@nea.moe>
+ *
+ * SPDX-License-Identifier: GPL-3.0-or-later
+ */
+
+package moe.nea.firmament.events.registration
+
+import moe.nea.firmament.events.AllowChatEvent
+import moe.nea.firmament.events.ModifyChatEvent
+import moe.nea.firmament.events.ProcessChatEvent
+import net.fabricmc.fabric.api.client.message.v1.ClientReceiveMessageEvents
+import net.minecraft.text.Text
+
+private var lastReceivedMessage: Text? = null
+
+fun registerFirmamentChatEvents() {
+ ClientReceiveMessageEvents.ALLOW_CHAT.register(ClientReceiveMessageEvents.AllowChat { message, signedMessage, sender, params, receptionTimestamp ->
+ lastReceivedMessage = message
+ !ProcessChatEvent.publish(ProcessChatEvent(message, false)).cancelled
+ && !AllowChatEvent.publish(AllowChatEvent(message)).cancelled
+ })
+ ClientReceiveMessageEvents.ALLOW_GAME.register(ClientReceiveMessageEvents.AllowGame { message, overlay ->
+ lastReceivedMessage = message
+ overlay || (!ProcessChatEvent.publish(ProcessChatEvent(message, false)).cancelled &&
+ !AllowChatEvent.publish(AllowChatEvent(message)).cancelled)
+ })
+ ClientReceiveMessageEvents.MODIFY_GAME.register(ClientReceiveMessageEvents.ModifyGame { message, overlay ->
+ if (overlay) message
+ else ModifyChatEvent.publish(ModifyChatEvent(message)).replaceWith
+ })
+ ClientReceiveMessageEvents.GAME_CANCELED.register(ClientReceiveMessageEvents.GameCanceled { message, overlay ->
+ if (!overlay && lastReceivedMessage !== message) {
+ ProcessChatEvent.publish(ProcessChatEvent(message, true))
+ }
+ })
+ ClientReceiveMessageEvents.CHAT_CANCELED.register(ClientReceiveMessageEvents.ChatCanceled { message, signedMessage, sender, params, receptionTimestamp ->
+ if (lastReceivedMessage !== message) {
+ ProcessChatEvent.publish(ProcessChatEvent(message, true))
+ }
+ })
+}