diff options
author | nea <nea@nea.moe> | 2023-05-03 00:52:37 +0200 |
---|---|---|
committer | nea <nea@nea.moe> | 2023-05-03 00:52:49 +0200 |
commit | 3be33bb522f468b812bb59b7f2edc8d1ca352661 (patch) | |
tree | 1292a52cb661ab71584b1ae248204e18b869afe1 /src/main/java/moe/nea/notenoughupdates/mixins/MixinMessageHandler.java | |
parent | a8ab8f3d6326211f6e07694c64ebd8b6ba195988 (diff) | |
download | firmament-3be33bb522f468b812bb59b7f2edc8d1ca352661.tar.gz firmament-3be33bb522f468b812bb59b7f2edc8d1ca352661.tar.bz2 firmament-3be33bb522f468b812bb59b7f2edc8d1ca352661.zip |
Modernize and 1.19.4ify
Diffstat (limited to 'src/main/java/moe/nea/notenoughupdates/mixins/MixinMessageHandler.java')
-rw-r--r-- | src/main/java/moe/nea/notenoughupdates/mixins/MixinMessageHandler.java | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/src/main/java/moe/nea/notenoughupdates/mixins/MixinMessageHandler.java b/src/main/java/moe/nea/notenoughupdates/mixins/MixinMessageHandler.java new file mode 100644 index 0000000..5d3e70f --- /dev/null +++ b/src/main/java/moe/nea/notenoughupdates/mixins/MixinMessageHandler.java @@ -0,0 +1,34 @@ +package moe.nea.notenoughupdates.mixins; + +import com.mojang.authlib.GameProfile; +import moe.nea.notenoughupdates.events.ServerChatLineReceivedEvent; +import net.minecraft.client.network.message.MessageHandler; +import net.minecraft.network.message.MessageType; +import net.minecraft.network.message.SignedMessage; +import net.minecraft.text.Text; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Inject; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; + +@Mixin(MessageHandler.class) +public class MixinMessageHandler { + @Inject(method = "onChatMessage", cancellable = true, at = @At("HEAD")) + public void onOnChatMessage(SignedMessage message, GameProfile sender, MessageType.Parameters params, CallbackInfo ci) { + var decoratedText = params.applyChatDecoration(message.unsignedContent() != null ? message.unsignedContent() : message.getContent()); + var event = new ServerChatLineReceivedEvent(decoratedText); + if (ServerChatLineReceivedEvent.Companion.publish(event).getCancelled()) { + ci.cancel(); + } + } + + @Inject(method = "onGameMessage", at = @At("HEAD"), cancellable = true) + public void onOnGameMessage(Text message, boolean overlay, CallbackInfo ci) { + if (!overlay) { + var event = new ServerChatLineReceivedEvent(message); + if (ServerChatLineReceivedEvent.Companion.publish(event).getCancelled()) { + ci.cancel(); + } + } + } +} |