From 0f36233dea17565d767eb94e5a2506a0f271789d Mon Sep 17 00:00:00 2001 From: Aizistral Date: Fri, 8 Nov 2024 19:14:03 +0100 Subject: [PATCH] Fix network protocol error thing Fixes #492, fixes #493, fixes #495 --- .../common/mixins/client/MixinChatComponent.java | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/src/main/java/com/aizistral/nochatreports/common/mixins/client/MixinChatComponent.java b/src/main/java/com/aizistral/nochatreports/common/mixins/client/MixinChatComponent.java index 42ed761c..a525d95d 100644 --- a/src/main/java/com/aizistral/nochatreports/common/mixins/client/MixinChatComponent.java +++ b/src/main/java/com/aizistral/nochatreports/common/mixins/client/MixinChatComponent.java @@ -43,16 +43,22 @@ private String onAddRecentChat(String message) { at = @At(value = "INVOKE", target = "Lnet/minecraft/client/gui/components/ChatComponent;" + "logChatMessage(Lnet/minecraft/client/GuiMessage;)V", ordinal = 0, shift = Shift.BEFORE)) private GuiMessage modifyGUIMessage(GuiMessage msg) { + if (!NCRConfig.getEncryption().isEnabledAndValid()) + return msg; + else if (this.minecraft.level == null) { + NCRCore.LOGGER.warn("Chat message cannot be decrypted since level didn't load in yet!"); + return msg; + } + if (NCRConfig.getCommon().enableDebugLog()) { NCRCore.LOGGER.info("Adding chat message, structure: " + Component.Serializer.toJson(msg.content(), RegistryAccess.EMPTY)); } - assert minecraft.level != null; - var decrypted = EncryptionUtil.tryDecrypt(minecraft.level.registryAccess(), msg.content()); + var decrypted = EncryptionUtil.tryDecrypt(this.minecraft.level.registryAccess(), msg.content()); decrypted.ifPresentOrElse(component -> { - this.lastMessageOriginal = EncryptionUtil.recreate(minecraft.level.registryAccess(), msg.content()); + this.lastMessageOriginal = EncryptionUtil.recreate(this.minecraft.level.registryAccess(), msg.content()); this.lastMessageEncrypted = true; }, () -> this.lastMessageEncrypted = false);