mirror of
https://github.com/PaperMC/Paper.git
synced 2024-12-26 22:40:21 +01:00
net.minecraft.network.protocol.common(.custom)
This commit is contained in:
parent
1a214aed6a
commit
902965e66a
3 changed files with 24 additions and 34 deletions
|
@ -0,0 +1,13 @@
|
|||
--- a/net/minecraft/network/protocol/common/ServerboundCustomPayloadPacket.java
|
||||
+++ b/net/minecraft/network/protocol/common/ServerboundCustomPayloadPacket.java
|
||||
@@ -14,9 +_,7 @@
|
||||
private static final int MAX_PAYLOAD_SIZE = 32767;
|
||||
public static final StreamCodec<FriendlyByteBuf, ServerboundCustomPayloadPacket> STREAM_CODEC = CustomPacketPayload.<FriendlyByteBuf>codec(
|
||||
id -> DiscardedPayload.codec(id, 32767),
|
||||
- Util.make(Lists.newArrayList(new CustomPacketPayload.TypeAndCodec<>(BrandPayload.TYPE, BrandPayload.STREAM_CODEC)), list -> {})
|
||||
- )
|
||||
- .map(ServerboundCustomPayloadPacket::new, ServerboundCustomPayloadPacket::payload);
|
||||
+ java.util.Collections.emptyList()).map(ServerboundCustomPayloadPacket::new, ServerboundCustomPayloadPacket::payload); // CraftBukkit - treat all packets the same
|
||||
|
||||
@Override
|
||||
public PacketType<ServerboundCustomPayloadPacket> type() {
|
|
@ -1,24 +1,21 @@
|
|||
--- a/net/minecraft/network/protocol/common/custom/DiscardedPayload.java
|
||||
+++ b/net/minecraft/network/protocol/common/custom/DiscardedPayload.java
|
||||
@@ -4,16 +4,18 @@
|
||||
@@ -4,13 +_,15 @@
|
||||
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 static <T extends FriendlyByteBuf> StreamCodec<T, DiscardedPayload> codec(ResourceLocation id, int maxBytes) {
|
||||
return CustomPacketPayload.codec((discardedpayload, packetdataserializer) -> {
|
||||
+ packetdataserializer.writeBytes(discardedpayload.data); // CraftBukkit - serialize
|
||||
}, (packetdataserializer) -> {
|
||||
int j = packetdataserializer.readableBytes();
|
||||
|
||||
if (j >= 0 && j <= maxBytes) {
|
||||
- packetdataserializer.skipBytes(j);
|
||||
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
|
||||
+ }, buffer -> {
|
||||
int i = buffer.readableBytes();
|
||||
if (i >= 0 && i <= maxSize) {
|
||||
buffer.skipBytes(i);
|
||||
- return new DiscardedPayload(id);
|
||||
+ // CraftBukkit start
|
||||
+ return new DiscardedPayload(id, packetdataserializer.readBytes(j));
|
||||
+ // CraftBukkit end
|
||||
+ return new DiscardedPayload(id, buffer.readBytes(i)); // CraftBukkit
|
||||
} else {
|
||||
throw new IllegalArgumentException("Payload may not be larger than " + maxBytes + " bytes");
|
||||
throw new IllegalArgumentException("Payload may not be larger than " + maxSize + " bytes");
|
||||
}
|
|
@ -1,20 +0,0 @@
|
|||
--- a/net/minecraft/network/protocol/common/ServerboundCustomPayloadPacket.java
|
||||
+++ b/net/minecraft/network/protocol/common/ServerboundCustomPayloadPacket.java
|
||||
@@ -2,7 +2,6 @@
|
||||
|
||||
import com.google.common.collect.Lists;
|
||||
import java.util.List;
|
||||
-import net.minecraft.Util;
|
||||
import net.minecraft.network.FriendlyByteBuf;
|
||||
import net.minecraft.network.codec.StreamCodec;
|
||||
import net.minecraft.network.protocol.Packet;
|
||||
@@ -16,8 +15,7 @@
|
||||
private static final int MAX_PAYLOAD_SIZE = 32767;
|
||||
public static final StreamCodec<FriendlyByteBuf, ServerboundCustomPayloadPacket> STREAM_CODEC = CustomPacketPayload.codec((minecraftkey) -> {
|
||||
return DiscardedPayload.codec(minecraftkey, 32767);
|
||||
- }, (List) Util.make(Lists.newArrayList(new CustomPacketPayload.TypeAndCodec[]{new CustomPacketPayload.TypeAndCodec<>(BrandPayload.TYPE, BrandPayload.STREAM_CODEC)}), (arraylist) -> {
|
||||
- })).map(ServerboundCustomPayloadPacket::new, ServerboundCustomPayloadPacket::payload);
|
||||
+ }, java.util.Collections.emptyList()).map(ServerboundCustomPayloadPacket::new, ServerboundCustomPayloadPacket::payload); // CraftBukkit - treat all packets the same
|
||||
|
||||
@Override
|
||||
public PacketType<ServerboundCustomPayloadPacket> type() {
|
Loading…
Reference in a new issue