diff options
| author | Aizistral | 2026-08-18 09:19:28 +0200 |
|---|---|---|
| committer | Aizistral | 2026-08-18 09:19:28 +0200 |
| commit | 65d2f3969fcb73df6f568cea6c9f0ac809567b5c (patch) | |
| tree | cd0db028ee10968994aa163b408d659b9915dd4a /src/main/java/com/aizistral | |
| parent | 3bd0d546e9eb363317bbf0191672722f52c2461e (diff) | |
Fix server ping crash once and for all
Fixes #556
Diffstat (limited to 'src/main/java/com/aizistral')
3 files changed, 57 insertions, 40 deletions
diff --git a/src/main/java/com/aizistral/nochatreports/common/core/ServerStatusCache.java b/src/main/java/com/aizistral/nochatreports/common/core/ServerStatusCache.java index 675c9a8..9d199ff 100644 --- a/src/main/java/com/aizistral/nochatreports/common/core/ServerStatusCache.java +++ b/src/main/java/com/aizistral/nochatreports/common/core/ServerStatusCache.java @@ -5,14 +5,15 @@ import net.fabricmc.api.Environment; //@Environment(EnvType.CLIENT) public class ServerStatusCache { - private static ThreadLocal<Boolean> preventsReports = new ThreadLocal<>(); + private static final ThreadLocal<Boolean> PREVENTS_REPORTS = new ThreadLocal<>(); public static boolean doesPreventReports() { - return preventsReports.get(); + Boolean value = PREVENTS_REPORTS.get(); + return value != null && value.booleanValue(); } public static void setPreventsReports(boolean doesPreventReports) { - preventsReports.set(doesPreventReports); + PREVENTS_REPORTS.set(Boolean.valueOf(doesPreventReports)); } } diff --git a/src/main/java/com/aizistral/nochatreports/common/mixins/client/MixinServerStatusPinger$1.java b/src/main/java/com/aizistral/nochatreports/common/mixins/client/MixinServerStatusPinger$1.java index fac9b95..1f08ac4 100644 --- a/src/main/java/com/aizistral/nochatreports/common/mixins/client/MixinServerStatusPinger$1.java +++ b/src/main/java/com/aizistral/nochatreports/common/mixins/client/MixinServerStatusPinger$1.java @@ -38,36 +38,44 @@ public abstract class MixinServerStatusPinger$1 { private ServerDataExtension nochatreports$serverData; @Inject(method = "<init>", at = @At("RETURN")) - private void captureServerData(ServerStatusPinger serverStatusPinger, Connection connection, ServerData serverData, Runnable runnable, Runnable runnable2, InetSocketAddress inetSocketAddress, ServerAddress serverAddress, EventLoopGroupHolder eventLoopGroupHolder, CallbackInfo ci){ - this.nochatreports$serverData = (ServerDataExtension) serverData; + private void captureServerData(ServerStatusPinger pinger, Connection connection, ServerData data, CallbackInfo info) { + try { + this.nochatreports$serverData = (ServerDataExtension) data; + } catch (Throwable ex) { + NCRCore.LOGGER.error("Failed to capture server data in MixinServerStatusPinger$1!", ex); + } } @Inject(method = "handleStatusResponse(Lnet/minecraft/network/protocol/status/ClientboundStatusResponsePacket;)V", at = @At(value = "INVOKE", target = "Lnet/minecraft/network/protocol/status/ServerStatus;" + "description()Lnet/minecraft/network/chat/Component;")) private void getNoChatReports(ClientboundStatusResponsePacket packet, CallbackInfo info) { - ServerStatus status = packet.status(); - boolean preventsReports = ServerStatusCache.doesPreventReports(); + try { + ServerStatus status = packet.status(); + boolean preventsReports = ServerStatusCache.doesPreventReports(); - if (status.version().isPresent()) { - ServerStatus.Version version = status.version().get(); + if (status.version().isPresent()) { + ServerStatus.Version version = status.version().get(); - if (version.protocol() < 759 && version.protocol() > 0) { - preventsReports = true; + if (version.protocol() < 759 && version.protocol() > 0) { + preventsReports = true; + } } - } - if (this.nochatreports$serverData == null) { - NCRCore.LOGGER.error("Failed to capture ServerData instance in MixinServerStatusPinger$1!"); - NCRCore.LOGGER.catching(new IllegalStateException()); - return; - } + if (this.nochatreports$serverData == null) { + NCRCore.LOGGER.error("Failed to capture ServerData instance in MixinServerStatusPinger$1!"); + NCRCore.LOGGER.catching(new IllegalStateException()); + return; + } - this.nochatreports$serverData.setPreventsChatReports(preventsReports); + this.nochatreports$serverData.setPreventsChatReports(preventsReports); - if (NCRConfig.getCommon().enableDebugLog()) { - NCRCore.LOGGER.info("Received status response packet from server, preventsChatReports: {}", - preventsReports); + if (NCRConfig.getCommon().enableDebugLog()) { + NCRCore.LOGGER.info("Received status response packet from server, preventsChatReports: {}", + preventsReports); + } + } catch (Throwable ex) { + NCRCore.LOGGER.error("Failed to handle status response in MixinServerStatusPinger$1!", ex); } } diff --git a/src/main/java/com/aizistral/nochatreports/common/mixins/common/MixinJsonByteBufCodec.java b/src/main/java/com/aizistral/nochatreports/common/mixins/common/MixinJsonByteBufCodec.java index e63502d..9dc2e28 100644 --- a/src/main/java/com/aizistral/nochatreports/common/mixins/common/MixinJsonByteBufCodec.java +++ b/src/main/java/com/aizistral/nochatreports/common/mixins/common/MixinJsonByteBufCodec.java @@ -31,37 +31,45 @@ public class MixinJsonByteBufCodec { @Inject(method = "encode(Lio/netty/buffer/ByteBuf;Lcom/google/gson/JsonElement;)V", at = @At("HEAD"), cancellable = true) private void onEncode(ByteBuf buf, JsonElement element, CallbackInfo info) { - if (!NCRConfig.getCommon().addQueryData() || !this.isServerStatusElement(element)) - return; + try { + if (!NCRConfig.getCommon().addQueryData() || !this.isServerStatusElement(element)) + return; - info.cancel(); + info.cancel(); - if (NCRConfig.getCommon().enableDebugLog()) { - NCRCore.LOGGER.info("Adding chat report prevention status to ServerStatus packet."); - } + if (NCRConfig.getCommon().enableDebugLog()) { + NCRCore.LOGGER.info("Adding chat report prevention status to ServerStatus packet."); + } - JsonObject object = element.getAsJsonObject(); - object.addProperty("preventsChatReports", true); + JsonObject object = element.getAsJsonObject(); + object.addProperty("preventsChatReports", true); - String string = GSON.toJson(object); - Utf8String.write(buf, string, 32767); + String string = GSON.toJson(object); + Utf8String.write(buf, string, 32767); + } catch (Throwable ex) { + NCRCore.LOGGER.error("Failed to process server status encoding!", ex); + } } @Inject(method = "decode(Lio/netty/buffer/ByteBuf;)Lcom/google/gson/JsonElement;", at = @At("RETURN"), cancellable = true) private void onDecode(ByteBuf buf, CallbackInfoReturnable<JsonElement> info) { - JsonElement element = info.getReturnValue(); + try { + JsonElement element = info.getReturnValue(); - if (!this.isServerStatusElement(element)) - return; + if (!this.isServerStatusElement(element)) + return; - JsonObject object = element.getAsJsonObject(); - boolean preventsReports = object.has("preventsChatReports") && object.get("preventsChatReports").getAsBoolean(); + JsonObject object = element.getAsJsonObject(); + boolean preventsReports = object.has("preventsChatReports") && object.get("preventsChatReports").getAsBoolean(); - if (NCRConfig.getCommon().enableDebugLog()) { - NCRCore.LOGGER.info("Received chat report prevention status from ServerStatus packet: " + preventsReports); - } + if (NCRConfig.getCommon().enableDebugLog()) { + NCRCore.LOGGER.info("Received chat report prevention status from ServerStatus packet: " + preventsReports); + } - ServerStatusCache.setPreventsReports(preventsReports); + ServerStatusCache.setPreventsReports(preventsReports); + } catch (Throwable ex) { + NCRCore.LOGGER.error("Failed to process server status decoding!", ex); + } } private boolean isServerStatusElement(JsonElement element) { |
