Handle errors properly in <=1.20 custom payload handling

This commit is contained in:
RaphiMC 2024-04-04 00:14:06 +02:00
parent d1ad86c8d4
commit 6b8f979b8f
No known key found for this signature in database
GPG Key ID: 0F6BB0657A03AC94

View File

@ -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<? extends CustomPayload>) 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;