diff --git a/src/main/java/land/chipmunk/chipmunkmod/mixin/ChatHudMixin.java b/src/main/java/land/chipmunk/chipmunkmod/mixin/ChatHudMixin.java deleted file mode 100644 index 1d83869..0000000 --- a/src/main/java/land/chipmunk/chipmunkmod/mixin/ChatHudMixin.java +++ /dev/null @@ -1,45 +0,0 @@ -package land.chipmunk.chipmunkmod.mixin; - -import land.chipmunk.chipmunkmod.listeners.Listener; -import land.chipmunk.chipmunkmod.listeners.ListenerManager; -import land.chipmunk.chipmunkmod.modules.ChomeNSBotCommandSuggestions; -import land.chipmunk.chipmunkmod.modules.RainbowName; -import net.kyori.adventure.text.TextComponent; -import net.minecraft.client.gui.hud.MessageIndicator; -import net.minecraft.network.message.MessageSignatureData; -import net.minecraft.text.Text; -import net.minecraft.text.TranslatableTextContent; -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(net.minecraft.client.gui.hud.ChatHud.class) -public class ChatHudMixin { - @Inject(at = @At("HEAD"), method = "addMessage(Lnet/minecraft/text/Text;Lnet/minecraft/network/message/MessageSignatureData;ILnet/minecraft/client/gui/hud/MessageIndicator;Z)V", cancellable = true) - public void addMessage(Text message, MessageSignatureData signature, int ticks, MessageIndicator indicator, boolean refresh, CallbackInfo ci) { - if (RainbowName.INSTANCE.enabled) { - if (message.getString().contains("Your nickname is now ") || message.getString().contains("Nickname changed.")) { - ci.cancel(); - return; - } - } - - try { - if (((TranslatableTextContent) message.getContent()).getKey().equals("advMode.setCommand.success")) { - ci.cancel(); - return; - } - } catch (ClassCastException ignored) {} - - for (Listener listener : ListenerManager.listeners) { - listener.chatMessageReceived(message); - } - - try { - if (((TextComponent) message.asComponent().children().get(0)).content().equals(ChomeNSBotCommandSuggestions.ID)) { - ci.cancel(); - } - } catch (Exception ignored) {} - } -} diff --git a/src/main/java/land/chipmunk/chipmunkmod/mixin/ClientPlayNetworkHandlerMixin.java b/src/main/java/land/chipmunk/chipmunkmod/mixin/ClientPlayNetworkHandlerMixin.java index d36ec6c..020de43 100644 --- a/src/main/java/land/chipmunk/chipmunkmod/mixin/ClientPlayNetworkHandlerMixin.java +++ b/src/main/java/land/chipmunk/chipmunkmod/mixin/ClientPlayNetworkHandlerMixin.java @@ -3,7 +3,10 @@ package land.chipmunk.chipmunkmod.mixin; import com.mojang.authlib.GameProfile; import land.chipmunk.chipmunkmod.ChipmunkMod; import land.chipmunk.chipmunkmod.command.CommandManager; +import land.chipmunk.chipmunkmod.listeners.Listener; +import land.chipmunk.chipmunkmod.listeners.ListenerManager; import land.chipmunk.chipmunkmod.modules.*; +import net.kyori.adventure.text.TextComponent; import net.minecraft.client.MinecraftClient; import net.minecraft.client.gui.screen.Screen; import net.minecraft.client.network.ClientDynamicRegistryType; @@ -12,9 +15,12 @@ import net.minecraft.client.util.telemetry.WorldSession; import net.minecraft.command.CommandRegistryAccess; import net.minecraft.network.ClientConnection; import net.minecraft.network.packet.s2c.play.GameJoinS2CPacket; +import net.minecraft.network.packet.s2c.play.GameMessageS2CPacket; import net.minecraft.network.packet.s2c.play.PlayerRemoveS2CPacket; import net.minecraft.registry.CombinedDynamicRegistries; import net.minecraft.resource.featuretoggle.FeatureSet; +import net.minecraft.text.Text; +import net.minecraft.text.TranslatableTextContent; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.Shadow; import org.spongepowered.asm.mixin.injection.At; @@ -46,4 +52,38 @@ public class ClientPlayNetworkHandlerMixin { @Inject(method = "onPlayerRemove", at = @At("HEAD"), cancellable = true) private void onPlayerRemove (PlayerRemoveS2CPacket packet, CallbackInfo ci) { ci.cancel(); } + + + @Inject(method = "onGameMessage", at = @At("HEAD"), cancellable = true) + private void onGameMessage (GameMessageS2CPacket packet, CallbackInfo ci) { + final Text message = packet.content(); + + try { + if (RainbowName.INSTANCE.enabled) { + if (message.getString().contains("Your nickname is now ") || message.getString().contains("Nickname changed.")) { + ci.cancel(); + return; + } + } + + try { + if (((TranslatableTextContent) message.getContent()).getKey().equals("advMode.setCommand.success")) { + ci.cancel(); + return; + } + } catch (ClassCastException ignored) {} + + for (Listener listener : ListenerManager.listeners) { + listener.chatMessageReceived(message); + } + + try { + if (((TextComponent) message.asComponent().children().get(0)).content().equals(ChomeNSBotCommandSuggestions.ID)) { + ci.cancel(); + } + } catch (Exception ignored) {} + } catch (Exception e) { + e.printStackTrace(); + } + } } diff --git a/src/main/java/land/chipmunk/chipmunkmod/modules/ChomeNSBotCommandSuggestions.java b/src/main/java/land/chipmunk/chipmunkmod/modules/ChomeNSBotCommandSuggestions.java index 9f12d1f..32a28b2 100644 --- a/src/main/java/land/chipmunk/chipmunkmod/modules/ChomeNSBotCommandSuggestions.java +++ b/src/main/java/land/chipmunk/chipmunkmod/modules/ChomeNSBotCommandSuggestions.java @@ -74,8 +74,6 @@ public class ChomeNSBotCommandSuggestions extends Listener { ) ) .toList(); - } catch (Exception ignored) { - ignored.printStackTrace(); - } + } catch (Exception ignored) {} } } diff --git a/src/main/resources/chipmunkmod.mixins.json b/src/main/resources/chipmunkmod.mixins.json index 920438c..063bc82 100644 --- a/src/main/resources/chipmunkmod.mixins.json +++ b/src/main/resources/chipmunkmod.mixins.json @@ -4,7 +4,6 @@ "package": "land.chipmunk.chipmunkmod.mixin", "compatibilityLevel": "JAVA_17", "client": [ - "ChatHudMixin", "ChatInputSuggestorMixin", "ChatScreenMixin", "ClientConnectionMixin",