From ac77e7603f5a810f89141e38059915591e813e33 Mon Sep 17 00:00:00 2001 From: Evan McCarthy Date: Sun, 10 Jul 2022 22:15:59 -0500 Subject: use correct decoration for system messages --- .../nochatreports/mixins/MixinServerGamePacketListenerImpl.java | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) (limited to 'src/main/java') diff --git a/src/main/java/com/aizistral/nochatreports/mixins/MixinServerGamePacketListenerImpl.java b/src/main/java/com/aizistral/nochatreports/mixins/MixinServerGamePacketListenerImpl.java index 6a87b48..297982b 100644 --- a/src/main/java/com/aizistral/nochatreports/mixins/MixinServerGamePacketListenerImpl.java +++ b/src/main/java/com/aizistral/nochatreports/mixins/MixinServerGamePacketListenerImpl.java @@ -1,16 +1,13 @@ package com.aizistral.nochatreports.mixins; -import com.aizistral.nochatreports.NoChatReports; import com.aizistral.nochatreports.core.NoReportsConfig; import net.minecraft.core.Registry; -import net.minecraft.network.chat.ChatType; import net.minecraft.network.chat.ChatTypeDecoration; import net.minecraft.network.chat.Component; import net.minecraft.network.protocol.Packet; import net.minecraft.network.protocol.game.ClientboundPlayerChatPacket; import net.minecraft.network.protocol.game.ClientboundSystemChatPacket; -import net.minecraft.resources.ResourceKey; import net.minecraft.server.level.ServerPlayer; import net.minecraft.server.network.ServerGamePacketListenerImpl; import net.minecraft.server.network.ServerPlayerConnection; @@ -19,12 +16,13 @@ import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.Shadow; import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.Inject; -import org.spongepowered.asm.mixin.injection.Redirect; import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; @Mixin(ServerGamePacketListenerImpl.class) public abstract class MixinServerGamePacketListenerImpl implements ServerPlayerConnection { + @Shadow public ServerPlayer player; + /** * @reason Convert player message to system message if mod is configured respectively. * This allows to circumvent signature check on client, as it only checks player messages. @@ -37,7 +35,8 @@ public abstract class MixinServerGamePacketListenerImpl implements ServerPlayerC if (NoReportsConfig.convertToGameMessage()) { if (packet instanceof ClientboundPlayerChatPacket chat) { Component component = chat.unsignedContent().orElse(chat.signedContent()); - component = ChatTypeDecoration.withSender("chat.type.text").decorate(component, chat.sender()); + ChatTypeDecoration decoration = player.level.registryAccess().registryOrThrow(Registry.CHAT_TYPE_REGISTRY).byId(chat.typeId()).chat(); + component = decoration.decorate(component, chat.sender()); packet = new ClientboundSystemChatPacket(component, false); info.cancel(); -- cgit v1.2.3