Skip to content

Commit

Permalink
Fix: Reading of custom payloads (#128)
Browse files Browse the repository at this point in the history
  • Loading branch information
onebeastchris authored Jul 23, 2024
1 parent b219b96 commit 5c760a5
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 12 deletions.
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -11,15 +12,16 @@ public record FormPayload(byte[] data) implements CustomPacketPayload {
public static final CustomPacketPayload.Type<FormPayload> 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<FormPayload> type() {
return TYPE;
}
}
}
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -11,15 +12,16 @@ public record PacketPayload(byte[] data) implements CustomPacketPayload {
public static final CustomPacketPayload.Type<PacketPayload> 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<PacketPayload> type() {
return TYPE;
}
}
}
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -11,15 +12,16 @@ public record SkinPayload(byte[] data) implements CustomPacketPayload {
public static final CustomPacketPayload.Type<SkinPayload> 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<SkinPayload> type() {
return TYPE;
}
}
}
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -11,15 +12,16 @@ public record TransferPayload(byte[] data) implements CustomPacketPayload {
public static final CustomPacketPayload.Type<TransferPayload> 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<TransferPayload> type() {
return TYPE;
}
}
}

0 comments on commit 5c760a5

Please sign in to comment.