summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAizistral2026-11-19 03:43:13 +0100
committerAizistral2026-11-19 03:43:13 +0100
commit5c13013eaf2ba9942b3265ee1215c8bb045b9458 (patch)
tree8e522ee9b19b6a790ba3a63c2afc238ee1456b5e
parente4dd37b5d8961a0286ccacbd1b0f6b47441f9b61 (diff)
Fix server ping crash once and for all1.21-Unified
-rw-r--r--src/main/java/com/aizistral/nochatreports/common/core/ServerStatusCache.java7
-rw-r--r--src/main/java/com/aizistral/nochatreports/common/mixins/client/MixinServerStatusPinger$1.java53
-rw-r--r--src/main/java/com/aizistral/nochatreports/common/mixins/common/MixinJsonByteBufCodec.java48
3 files changed, 67 insertions, 41 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..7563f2c 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,53 @@ 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,
+ Runnable runnableA,
+ Runnable runnableB,
+ InetSocketAddress socketAddress,
+ ServerAddress serverAddress,
+ EventLoopGroupHolder holder,
+ 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 4bb95d2..a0e625d 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,38 +31,46 @@ 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) {
- ServerStatusCache.setPreventsReports(false);
- JsonElement element = info.getReturnValue();
+ try {
+ ServerStatusCache.setPreventsReports(false);
+ JsonElement element = info.getReturnValue();
- if (!element.isJsonObject())
- return;
+ if (!element.isJsonObject())
+ 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) {