From 5c760a5c1e7bc5d2a6c9d657682fbdc51f6df732 Mon Sep 17 00:00:00 2001 From: chris Date: Tue, 23 Jul 2024 20:05:28 +0200 Subject: [PATCH] Fix: Reading of custom payloads (#128) --- .../floodgate/pluginmessage/payloads/FormPayload.java | 8 +++++--- .../floodgate/pluginmessage/payloads/PacketPayload.java | 8 +++++--- .../floodgate/pluginmessage/payloads/SkinPayload.java | 8 +++++--- .../floodgate/pluginmessage/payloads/TransferPayload.java | 8 +++++--- 4 files changed, 20 insertions(+), 12 deletions(-) diff --git a/src/main/java/org/geysermc/floodgate/pluginmessage/payloads/FormPayload.java b/src/main/java/org/geysermc/floodgate/pluginmessage/payloads/FormPayload.java index 6ab4add..475d138 100644 --- a/src/main/java/org/geysermc/floodgate/pluginmessage/payloads/FormPayload.java +++ b/src/main/java/org/geysermc/floodgate/pluginmessage/payloads/FormPayload.java @@ -1,5 +1,6 @@ package org.geysermc.floodgate.pluginmessage.payloads; +import io.netty.buffer.ByteBufUtil; import net.minecraft.network.FriendlyByteBuf; import net.minecraft.network.codec.StreamCodec; import net.minecraft.network.protocol.common.custom.CustomPacketPayload; @@ -11,15 +12,16 @@ public record FormPayload(byte[] data) implements CustomPacketPayload { public static final CustomPacketPayload.Type TYPE = new Type<>(ResourceLocation.parse("floodgate:form")); private FormPayload(FriendlyByteBuf friendlyByteBuf) { - this(friendlyByteBuf.readByteArray()); + this(ByteBufUtil.getBytes(friendlyByteBuf)); + friendlyByteBuf.readerIndex(friendlyByteBuf.readerIndex() + this.data.length); } private void write(FriendlyByteBuf friendlyByteBuf) { - friendlyByteBuf.writeByteArray(this.data); + friendlyByteBuf.writeBytes(this.data); } @Override public CustomPacketPayload.@NonNull Type type() { return TYPE; } -} \ No newline at end of file +} diff --git a/src/main/java/org/geysermc/floodgate/pluginmessage/payloads/PacketPayload.java b/src/main/java/org/geysermc/floodgate/pluginmessage/payloads/PacketPayload.java index 08bc2c6..b00021b 100644 --- a/src/main/java/org/geysermc/floodgate/pluginmessage/payloads/PacketPayload.java +++ b/src/main/java/org/geysermc/floodgate/pluginmessage/payloads/PacketPayload.java @@ -1,5 +1,6 @@ package org.geysermc.floodgate.pluginmessage.payloads; +import io.netty.buffer.ByteBufUtil; import net.minecraft.network.FriendlyByteBuf; import net.minecraft.network.codec.StreamCodec; import net.minecraft.network.protocol.common.custom.CustomPacketPayload; @@ -11,15 +12,16 @@ public record PacketPayload(byte[] data) implements CustomPacketPayload { public static final CustomPacketPayload.Type TYPE = new Type<>(ResourceLocation.parse("floodgate:packet")); private PacketPayload(FriendlyByteBuf friendlyByteBuf) { - this(friendlyByteBuf.readByteArray()); + this(ByteBufUtil.getBytes(friendlyByteBuf)); + friendlyByteBuf.readerIndex(friendlyByteBuf.readerIndex() + this.data.length); } private void write(FriendlyByteBuf friendlyByteBuf) { - friendlyByteBuf.writeByteArray(this.data); + friendlyByteBuf.writeBytes(this.data); } @Override public CustomPacketPayload.@NonNull Type type() { return TYPE; } -} \ No newline at end of file +} diff --git a/src/main/java/org/geysermc/floodgate/pluginmessage/payloads/SkinPayload.java b/src/main/java/org/geysermc/floodgate/pluginmessage/payloads/SkinPayload.java index 900f00c..a1e6eee 100644 --- a/src/main/java/org/geysermc/floodgate/pluginmessage/payloads/SkinPayload.java +++ b/src/main/java/org/geysermc/floodgate/pluginmessage/payloads/SkinPayload.java @@ -1,5 +1,6 @@ package org.geysermc.floodgate.pluginmessage.payloads; +import io.netty.buffer.ByteBufUtil; import net.minecraft.network.FriendlyByteBuf; import net.minecraft.network.codec.StreamCodec; import net.minecraft.network.protocol.common.custom.CustomPacketPayload; @@ -11,15 +12,16 @@ public record SkinPayload(byte[] data) implements CustomPacketPayload { public static final CustomPacketPayload.Type TYPE = new Type<>(ResourceLocation.parse("floodgate:skin")); private SkinPayload(FriendlyByteBuf friendlyByteBuf) { - this(friendlyByteBuf.readByteArray()); + this(ByteBufUtil.getBytes(friendlyByteBuf)); + friendlyByteBuf.readerIndex(friendlyByteBuf.readerIndex() + this.data.length); } private void write(FriendlyByteBuf friendlyByteBuf) { - friendlyByteBuf.writeByteArray(this.data); + friendlyByteBuf.writeBytes(this.data); } @Override public CustomPacketPayload.@NonNull Type type() { return TYPE; } -} \ No newline at end of file +} diff --git a/src/main/java/org/geysermc/floodgate/pluginmessage/payloads/TransferPayload.java b/src/main/java/org/geysermc/floodgate/pluginmessage/payloads/TransferPayload.java index 5c16b79..6396327 100644 --- a/src/main/java/org/geysermc/floodgate/pluginmessage/payloads/TransferPayload.java +++ b/src/main/java/org/geysermc/floodgate/pluginmessage/payloads/TransferPayload.java @@ -1,5 +1,6 @@ package org.geysermc.floodgate.pluginmessage.payloads; +import io.netty.buffer.ByteBufUtil; import net.minecraft.network.FriendlyByteBuf; import net.minecraft.network.codec.StreamCodec; import net.minecraft.network.protocol.common.custom.CustomPacketPayload; @@ -11,15 +12,16 @@ public record TransferPayload(byte[] data) implements CustomPacketPayload { public static final CustomPacketPayload.Type TYPE = new Type<>(ResourceLocation.parse("floodgate:transfer")); private TransferPayload(FriendlyByteBuf friendlyByteBuf) { - this(friendlyByteBuf.readByteArray()); + this(ByteBufUtil.getBytes(friendlyByteBuf)); + friendlyByteBuf.readerIndex(friendlyByteBuf.readerIndex() + this.data.length); } private void write(FriendlyByteBuf friendlyByteBuf) { - friendlyByteBuf.writeByteArray(this.data); + friendlyByteBuf.writeBytes(this.data); } @Override public CustomPacketPayload.@NonNull Type type() { return TYPE; } -} \ No newline at end of file +}