From 6b8f979b8f7654394ae0f295e19ddf94207955c5 Mon Sep 17 00:00:00 2001 From: RaphiMC <50594595+RaphiMC@users.noreply.github.com> Date: Thu, 4 Apr 2024 00:14:06 +0200 Subject: [PATCH] Handle errors properly in <=1.20 custom payload handling --- .../network/MixinCustomPayloadS2CPacket.java | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/src/main/java/de/florianmichael/viafabricplus/injection/mixin/fixes/minecraft/network/MixinCustomPayloadS2CPacket.java b/src/main/java/de/florianmichael/viafabricplus/injection/mixin/fixes/minecraft/network/MixinCustomPayloadS2CPacket.java index 1ed55282..801d8c58 100644 --- a/src/main/java/de/florianmichael/viafabricplus/injection/mixin/fixes/minecraft/network/MixinCustomPayloadS2CPacket.java +++ b/src/main/java/de/florianmichael/viafabricplus/injection/mixin/fixes/minecraft/network/MixinCustomPayloadS2CPacket.java @@ -67,11 +67,15 @@ public abstract class MixinCustomPayloadS2CPacket { return null; } if (ProtocolTranslator.getTargetVersion().olderThanOrEqualTo(ProtocolVersion.v1_20)) { - // Skip remaining bytes after reading the payload + // Skip remaining bytes after reading the payload and return null if the payload fails to read return (PacketByteBuf.PacketReader) packetByteBuf -> { - final CustomPayload result = reader.apply(packetByteBuf); - packetByteBuf.skipBytes(packetByteBuf.readableBytes()); - return result; + try { + final CustomPayload result = reader.apply(packetByteBuf); + packetByteBuf.skipBytes(packetByteBuf.readableBytes()); + return result; + } catch (Exception e) { + return null; + } }; } else { return reader;