Simplify custom payload handling (#12347)
This commit is contained in:
@@ -1,21 +1,26 @@
|
||||
--- a/net/minecraft/network/protocol/common/custom/DiscardedPayload.java
|
||||
+++ b/net/minecraft/network/protocol/common/custom/DiscardedPayload.java
|
||||
@@ -4,13 +_,14 @@
|
||||
@@ -4,13 +_,19 @@
|
||||
import net.minecraft.network.codec.StreamCodec;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
|
||||
-public record DiscardedPayload(ResourceLocation id) implements CustomPacketPayload {
|
||||
+public record DiscardedPayload(ResourceLocation id, io.netty.buffer.ByteBuf data) implements CustomPacketPayload { // CraftBukkit - store data
|
||||
+public record DiscardedPayload(ResourceLocation id, byte[] data) implements CustomPacketPayload { // Paper - store data
|
||||
public static <T extends FriendlyByteBuf> StreamCodec<T, DiscardedPayload> codec(ResourceLocation id, int maxSize) {
|
||||
- return CustomPacketPayload.codec((value, output) -> {}, buffer -> {
|
||||
+ return CustomPacketPayload.codec((value, output) -> {
|
||||
+ output.writeBytes(value.data); // CraftBukkit - serialize
|
||||
+ // Paper start
|
||||
+ // Always write data
|
||||
+ output.writeBytes(value.data);
|
||||
+ }, buffer -> {
|
||||
int i = buffer.readableBytes();
|
||||
if (i >= 0 && i <= maxSize) {
|
||||
- buffer.skipBytes(i);
|
||||
- return new DiscardedPayload(id);
|
||||
+ return new DiscardedPayload(id, buffer.readBytes(i)); // CraftBukkit
|
||||
+ final byte[] data = new byte[i];
|
||||
+ buffer.readBytes(data);
|
||||
+ return new DiscardedPayload(id, data);
|
||||
+ // Paper end
|
||||
} else {
|
||||
throw new IllegalArgumentException("Payload may not be larger than " + maxSize + " bytes");
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user