From 27ebb9d2d8b61463d04117abd987e0a84f347c4c Mon Sep 17 00:00:00 2001 From: filoghost Date: Sun, 19 Mar 2023 16:44:40 +0100 Subject: [PATCH] Avoid extending internal NMS classes --- .../v1_10_R1/EntityLivingSpawnNMSPacket.java | 2 +- .../nms/v1_10_R1/EntityMetadataNMSPacket.java | 2 +- .../nms/v1_10_R1/EntityMountNMSPacket.java | 2 +- .../nms/v1_10_R1/EntitySpawnNMSPacket.java | 2 +- .../nms/v1_10_R1/EntityTeleportNMSPacket.java | 2 +- .../nms/v1_10_R1/PacketByteBuffer.java | 60 ++++++++++++++++--- .../nms/v1_10_R1/VersionNMSPacket.java | 12 ---- .../v1_11_R1/EntityLivingSpawnNMSPacket.java | 2 +- .../nms/v1_11_R1/EntityMetadataNMSPacket.java | 2 +- .../nms/v1_11_R1/EntityMountNMSPacket.java | 2 +- .../nms/v1_11_R1/EntitySpawnNMSPacket.java | 2 +- .../nms/v1_11_R1/EntityTeleportNMSPacket.java | 2 +- .../nms/v1_11_R1/PacketByteBuffer.java | 60 ++++++++++++++++--- .../nms/v1_11_R1/VersionNMSPacket.java | 12 ---- .../v1_12_R1/EntityLivingSpawnNMSPacket.java | 2 +- .../nms/v1_12_R1/EntityMetadataNMSPacket.java | 2 +- .../nms/v1_12_R1/EntityMountNMSPacket.java | 2 +- .../nms/v1_12_R1/EntitySpawnNMSPacket.java | 2 +- .../nms/v1_12_R1/EntityTeleportNMSPacket.java | 2 +- .../nms/v1_12_R1/PacketByteBuffer.java | 60 ++++++++++++++++--- .../nms/v1_12_R1/VersionNMSPacket.java | 12 ---- .../v1_13_R2/EntityLivingSpawnNMSPacket.java | 2 +- .../nms/v1_13_R2/EntityMetadataNMSPacket.java | 2 +- .../nms/v1_13_R2/EntityMountNMSPacket.java | 2 +- .../nms/v1_13_R2/EntitySpawnNMSPacket.java | 2 +- .../nms/v1_13_R2/EntityTeleportNMSPacket.java | 2 +- .../nms/v1_13_R2/PacketByteBuffer.java | 60 ++++++++++++++++--- .../nms/v1_13_R2/VersionNMSPacket.java | 12 ---- .../v1_14_R1/EntityLivingSpawnNMSPacket.java | 2 +- .../nms/v1_14_R1/EntityMetadataNMSPacket.java | 2 +- .../nms/v1_14_R1/EntityMountNMSPacket.java | 2 +- .../nms/v1_14_R1/EntitySpawnNMSPacket.java | 2 +- .../nms/v1_14_R1/EntityTeleportNMSPacket.java | 2 +- .../nms/v1_14_R1/PacketByteBuffer.java | 60 ++++++++++++++++--- .../nms/v1_14_R1/VersionNMSPacket.java | 12 ---- .../v1_15_R1/EntityLivingSpawnNMSPacket.java | 2 +- .../nms/v1_15_R1/EntityMetadataNMSPacket.java | 2 +- .../nms/v1_15_R1/EntityMountNMSPacket.java | 2 +- .../nms/v1_15_R1/EntitySpawnNMSPacket.java | 2 +- .../nms/v1_15_R1/EntityTeleportNMSPacket.java | 2 +- .../nms/v1_15_R1/PacketByteBuffer.java | 52 +++++++++++++--- .../nms/v1_15_R1/VersionNMSPacket.java | 12 ---- .../v1_16_R1/EntityLivingSpawnNMSPacket.java | 2 +- .../nms/v1_16_R1/EntityMetadataNMSPacket.java | 2 +- .../nms/v1_16_R1/EntityMountNMSPacket.java | 2 +- .../nms/v1_16_R1/EntitySpawnNMSPacket.java | 2 +- .../nms/v1_16_R1/EntityTeleportNMSPacket.java | 2 +- .../nms/v1_16_R1/PacketByteBuffer.java | 53 +++++++++++++--- .../nms/v1_16_R1/VersionNMSPacket.java | 12 ---- .../v1_16_R2/EntityLivingSpawnNMSPacket.java | 2 +- .../nms/v1_16_R2/EntityMetadataNMSPacket.java | 2 +- .../nms/v1_16_R2/EntityMountNMSPacket.java | 2 +- .../nms/v1_16_R2/EntitySpawnNMSPacket.java | 2 +- .../nms/v1_16_R2/EntityTeleportNMSPacket.java | 2 +- .../nms/v1_16_R2/PacketByteBuffer.java | 52 +++++++++++++--- .../nms/v1_16_R2/VersionNMSPacket.java | 12 ---- .../v1_16_R3/EntityLivingSpawnNMSPacket.java | 2 +- .../nms/v1_16_R3/EntityMetadataNMSPacket.java | 2 +- .../nms/v1_16_R3/EntityMountNMSPacket.java | 2 +- .../nms/v1_16_R3/EntitySpawnNMSPacket.java | 2 +- .../nms/v1_16_R3/EntityTeleportNMSPacket.java | 2 +- .../nms/v1_16_R3/PacketByteBuffer.java | 52 +++++++++++++--- .../nms/v1_16_R3/VersionNMSPacket.java | 12 ---- .../nms/v1_17_R1/EntityDestroyNMSPacket.java | 2 +- .../v1_17_R1/EntityListDestroyNMSPacket.java | 4 +- .../v1_17_R1/EntityLivingSpawnNMSPacket.java | 2 +- .../nms/v1_17_R1/EntityMetadataNMSPacket.java | 2 +- .../nms/v1_17_R1/EntityMountNMSPacket.java | 2 +- .../nms/v1_17_R1/EntitySpawnNMSPacket.java | 2 +- .../nms/v1_17_R1/EntityTeleportNMSPacket.java | 2 +- .../nms/v1_17_R1/PacketByteBuffer.java | 44 +++++++++++--- .../nms/v1_18_R1/EntityDestroyNMSPacket.java | 4 +- .../v1_18_R1/EntityLivingSpawnNMSPacket.java | 2 +- .../nms/v1_18_R1/EntityMetadataNMSPacket.java | 2 +- .../nms/v1_18_R1/EntityMountNMSPacket.java | 2 +- .../nms/v1_18_R1/EntitySpawnNMSPacket.java | 2 +- .../nms/v1_18_R1/EntityTeleportNMSPacket.java | 2 +- .../nms/v1_18_R1/PacketByteBuffer.java | 44 +++++++++++--- .../nms/v1_18_R2/EntityDestroyNMSPacket.java | 4 +- .../v1_18_R2/EntityLivingSpawnNMSPacket.java | 2 +- .../nms/v1_18_R2/EntityMetadataNMSPacket.java | 2 +- .../nms/v1_18_R2/EntityMountNMSPacket.java | 2 +- .../nms/v1_18_R2/EntitySpawnNMSPacket.java | 2 +- .../nms/v1_18_R2/EntityTeleportNMSPacket.java | 2 +- .../nms/v1_18_R2/PacketByteBuffer.java | 44 +++++++++++--- .../nms/v1_19_R1/EntityDestroyNMSPacket.java | 4 +- .../nms/v1_19_R1/EntityMetadataNMSPacket.java | 2 +- .../nms/v1_19_R1/EntityMountNMSPacket.java | 2 +- .../nms/v1_19_R1/EntitySpawnNMSPacket.java | 2 +- .../nms/v1_19_R1/EntityTeleportNMSPacket.java | 2 +- .../nms/v1_19_R1/PacketByteBuffer.java | 44 +++++++++++--- .../nms/v1_19_R2/EntityDestroyNMSPacket.java | 4 +- .../nms/v1_19_R2/EntityMetadataNMSPacket.java | 2 +- .../nms/v1_19_R2/EntityMountNMSPacket.java | 2 +- .../nms/v1_19_R2/EntitySpawnNMSPacket.java | 2 +- .../nms/v1_19_R2/EntityTeleportNMSPacket.java | 2 +- .../nms/v1_19_R2/PacketByteBuffer.java | 44 +++++++++++--- .../v1_8_R3/EntityLivingSpawnNMSPacket.java | 2 +- .../nms/v1_8_R3/EntityMetadataNMSPacket.java | 2 +- .../nms/v1_8_R3/EntityMountNMSPacket.java | 2 +- .../nms/v1_8_R3/EntitySpawnNMSPacket.java | 2 +- .../nms/v1_8_R3/EntityTeleportNMSPacket.java | 2 +- .../nms/v1_8_R3/PacketByteBuffer.java | 59 +++++++++++++++--- .../nms/v1_8_R3/VersionNMSPacket.java | 12 ---- .../v1_9_R2/EntityLivingSpawnNMSPacket.java | 2 +- .../nms/v1_9_R2/EntityMetadataNMSPacket.java | 2 +- .../nms/v1_9_R2/EntityMountNMSPacket.java | 2 +- .../nms/v1_9_R2/EntitySpawnNMSPacket.java | 2 +- .../nms/v1_9_R2/EntityTeleportNMSPacket.java | 2 +- .../nms/v1_9_R2/PacketByteBuffer.java | 60 ++++++++++++++++--- .../nms/v1_9_R2/VersionNMSPacket.java | 12 ---- 111 files changed, 824 insertions(+), 334 deletions(-) diff --git a/nms/v1_10_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_10_R1/EntityLivingSpawnNMSPacket.java b/nms/v1_10_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_10_R1/EntityLivingSpawnNMSPacket.java index bc8c3245..bb8dc169 100644 --- a/nms/v1_10_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_10_R1/EntityLivingSpawnNMSPacket.java +++ b/nms/v1_10_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_10_R1/EntityLivingSpawnNMSPacket.java @@ -62,7 +62,7 @@ class EntityLivingSpawnNMSPacket extends VersionNMSPacket { // Entries are deserialized and saved into a field which is not used during the re-serialization, set as empty packetByteBuffer.writeDataWatcherEntriesEnd(); - Packet rawPacket = writeData(new PacketPlayOutSpawnEntityLiving(), packetByteBuffer); + Packet rawPacket = packetByteBuffer.writeDataTo(new PacketPlayOutSpawnEntityLiving()); return new Builder(rawPacket, PacketByteBuffer.get()); } diff --git a/nms/v1_10_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_10_R1/EntityMetadataNMSPacket.java b/nms/v1_10_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_10_R1/EntityMetadataNMSPacket.java index 0fc615c7..b8fdb9d0 100644 --- a/nms/v1_10_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_10_R1/EntityMetadataNMSPacket.java +++ b/nms/v1_10_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_10_R1/EntityMetadataNMSPacket.java @@ -14,7 +14,7 @@ class EntityMetadataNMSPacket extends VersionNMSPacket { private final Packet rawPacket; private EntityMetadataNMSPacket(PacketByteBuffer packetByteBuffer) { - this.rawPacket = writeData(new PacketPlayOutEntityMetadata(), packetByteBuffer); + this.rawPacket = packetByteBuffer.writeDataTo(new PacketPlayOutEntityMetadata()); } @Override diff --git a/nms/v1_10_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_10_R1/EntityMountNMSPacket.java b/nms/v1_10_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_10_R1/EntityMountNMSPacket.java index f8a1a64d..c5eb0c37 100644 --- a/nms/v1_10_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_10_R1/EntityMountNMSPacket.java +++ b/nms/v1_10_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_10_R1/EntityMountNMSPacket.java @@ -19,7 +19,7 @@ class EntityMountNMSPacket extends VersionNMSPacket { packetByteBuffer.writeVarInt(vehicleEntityID.getNumericID()); packetByteBuffer.writeVarIntArray(passengerEntityID.getNumericID()); - this.rawPacket = writeData(new PacketPlayOutMount(), packetByteBuffer); + this.rawPacket = packetByteBuffer.writeDataTo(new PacketPlayOutMount()); } @Override diff --git a/nms/v1_10_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_10_R1/EntitySpawnNMSPacket.java b/nms/v1_10_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_10_R1/EntitySpawnNMSPacket.java index 06cc962f..e1ea9f21 100644 --- a/nms/v1_10_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_10_R1/EntitySpawnNMSPacket.java +++ b/nms/v1_10_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_10_R1/EntitySpawnNMSPacket.java @@ -42,7 +42,7 @@ class EntitySpawnNMSPacket extends VersionNMSPacket { packetByteBuffer.writeShort(0); packetByteBuffer.writeShort(0); - this.rawPacket = writeData(new PacketPlayOutSpawnEntity(), packetByteBuffer); + this.rawPacket = packetByteBuffer.writeDataTo(new PacketPlayOutSpawnEntity()); } @Override diff --git a/nms/v1_10_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_10_R1/EntityTeleportNMSPacket.java b/nms/v1_10_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_10_R1/EntityTeleportNMSPacket.java index 414d1448..4232f235 100644 --- a/nms/v1_10_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_10_R1/EntityTeleportNMSPacket.java +++ b/nms/v1_10_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_10_R1/EntityTeleportNMSPacket.java @@ -31,7 +31,7 @@ class EntityTeleportNMSPacket extends VersionNMSPacket { // On ground packetByteBuffer.writeBoolean(false); - this.rawPacket = writeData(new PacketPlayOutEntityTeleport(), packetByteBuffer); + this.rawPacket = packetByteBuffer.writeDataTo(new PacketPlayOutEntityTeleport()); } @Override diff --git a/nms/v1_10_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_10_R1/PacketByteBuffer.java b/nms/v1_10_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_10_R1/PacketByteBuffer.java index ef075d89..246681ab 100644 --- a/nms/v1_10_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_10_R1/PacketByteBuffer.java +++ b/nms/v1_10_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_10_R1/PacketByteBuffer.java @@ -6,25 +6,57 @@ package me.filoghost.holographicdisplays.nms.v1_10_R1; import io.netty.buffer.Unpooled; +import net.minecraft.server.v1_10_R1.Packet; import net.minecraft.server.v1_10_R1.PacketDataSerializer; +import java.io.IOException; import java.util.UUID; -class PacketByteBuffer extends PacketDataSerializer { +class PacketByteBuffer { private static final PacketByteBuffer INSTANCE = new PacketByteBuffer(); + private final PacketDataSerializer serializer; + static PacketByteBuffer get() { INSTANCE.clear(); return INSTANCE; } private PacketByteBuffer() { - super(Unpooled.buffer()); + this.serializer = new PacketDataSerializer(Unpooled.buffer()); + } + + int readableBytes() { + return serializer.readableBytes(); + } + + void readBytes(byte[] bytes) { + serializer.readBytes(bytes); + } + + void writeBoolean(boolean flag) { + serializer.writeBoolean(flag); + } + + void writeByte(int i) { + serializer.writeByte(i); + } + + void writeShort(int i) { + serializer.writeShort(i); + } + + void writeInt(int i) { + serializer.writeInt(i); + } + + void writeDouble(double d) { + serializer.writeDouble(d); } void writeVarInt(int i) { - super.d(i); + serializer.d(i); } void writeVarIntArray(int i1) { @@ -33,17 +65,31 @@ class PacketByteBuffer extends PacketDataSerializer { } void writeUUID(UUID uuid) { - super.a(uuid); + serializer.a(uuid); } void writeDataWatcherEntry(DataWatcherKey key, T value) { - writeByte(key.getIndex()); + serializer.writeByte(key.getIndex()); writeVarInt(key.getSerializerTypeID()); - key.getSerializer().a(this, value); + key.getSerializer().a(serializer, value); } void writeDataWatcherEntriesEnd() { - writeByte(0xFF); + serializer.writeByte(0xFF); + } + + void clear() { + serializer.clear(); + } + + > T writeDataTo(T packet) { + try { + packet.a(serializer); + return packet; + } catch (IOException e) { + // Never thrown by the implementations + throw new RuntimeException(e); + } } } diff --git a/nms/v1_10_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_10_R1/VersionNMSPacket.java b/nms/v1_10_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_10_R1/VersionNMSPacket.java index 61cc37da..b5e0dc72 100644 --- a/nms/v1_10_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_10_R1/VersionNMSPacket.java +++ b/nms/v1_10_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_10_R1/VersionNMSPacket.java @@ -10,8 +10,6 @@ import net.minecraft.server.v1_10_R1.Packet; import org.bukkit.craftbukkit.v1_10_R1.entity.CraftPlayer; import org.bukkit.entity.Player; -import java.io.IOException; - abstract class VersionNMSPacket implements PacketGroup { @Override @@ -21,14 +19,4 @@ abstract class VersionNMSPacket implements PacketGroup { abstract Packet getRawPacket(); - protected static > T writeData(T packet, PacketByteBuffer packetByteBuffer) { - try { - packet.a(packetByteBuffer); - return packet; - } catch (IOException e) { - // Never thrown by the implementations - throw new RuntimeException(e); - } - } - } diff --git a/nms/v1_11_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_11_R1/EntityLivingSpawnNMSPacket.java b/nms/v1_11_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_11_R1/EntityLivingSpawnNMSPacket.java index 1431333d..90ccc2a9 100644 --- a/nms/v1_11_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_11_R1/EntityLivingSpawnNMSPacket.java +++ b/nms/v1_11_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_11_R1/EntityLivingSpawnNMSPacket.java @@ -62,7 +62,7 @@ class EntityLivingSpawnNMSPacket extends VersionNMSPacket { // Entries are deserialized and saved into a field which is not used during the re-serialization, set as empty packetByteBuffer.writeDataWatcherEntriesEnd(); - Packet rawPacket = writeData(new PacketPlayOutSpawnEntityLiving(), packetByteBuffer); + Packet rawPacket = packetByteBuffer.writeDataTo(new PacketPlayOutSpawnEntityLiving()); return new Builder(rawPacket, PacketByteBuffer.get()); } diff --git a/nms/v1_11_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_11_R1/EntityMetadataNMSPacket.java b/nms/v1_11_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_11_R1/EntityMetadataNMSPacket.java index 407fb268..66df3b76 100644 --- a/nms/v1_11_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_11_R1/EntityMetadataNMSPacket.java +++ b/nms/v1_11_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_11_R1/EntityMetadataNMSPacket.java @@ -14,7 +14,7 @@ class EntityMetadataNMSPacket extends VersionNMSPacket { private final Packet rawPacket; private EntityMetadataNMSPacket(PacketByteBuffer packetByteBuffer) { - this.rawPacket = writeData(new PacketPlayOutEntityMetadata(), packetByteBuffer); + this.rawPacket = packetByteBuffer.writeDataTo(new PacketPlayOutEntityMetadata()); } @Override diff --git a/nms/v1_11_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_11_R1/EntityMountNMSPacket.java b/nms/v1_11_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_11_R1/EntityMountNMSPacket.java index 978a4334..3216f22b 100644 --- a/nms/v1_11_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_11_R1/EntityMountNMSPacket.java +++ b/nms/v1_11_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_11_R1/EntityMountNMSPacket.java @@ -19,7 +19,7 @@ class EntityMountNMSPacket extends VersionNMSPacket { packetByteBuffer.writeVarInt(vehicleEntityID.getNumericID()); packetByteBuffer.writeVarIntArray(passengerEntityID.getNumericID()); - this.rawPacket = writeData(new PacketPlayOutMount(), packetByteBuffer); + this.rawPacket = packetByteBuffer.writeDataTo(new PacketPlayOutMount()); } @Override diff --git a/nms/v1_11_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_11_R1/EntitySpawnNMSPacket.java b/nms/v1_11_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_11_R1/EntitySpawnNMSPacket.java index 08cc27f1..1944568b 100644 --- a/nms/v1_11_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_11_R1/EntitySpawnNMSPacket.java +++ b/nms/v1_11_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_11_R1/EntitySpawnNMSPacket.java @@ -42,7 +42,7 @@ class EntitySpawnNMSPacket extends VersionNMSPacket { packetByteBuffer.writeShort(0); packetByteBuffer.writeShort(0); - this.rawPacket = writeData(new PacketPlayOutSpawnEntity(), packetByteBuffer); + this.rawPacket = packetByteBuffer.writeDataTo(new PacketPlayOutSpawnEntity()); } @Override diff --git a/nms/v1_11_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_11_R1/EntityTeleportNMSPacket.java b/nms/v1_11_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_11_R1/EntityTeleportNMSPacket.java index e0aa6697..147637cf 100644 --- a/nms/v1_11_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_11_R1/EntityTeleportNMSPacket.java +++ b/nms/v1_11_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_11_R1/EntityTeleportNMSPacket.java @@ -31,7 +31,7 @@ class EntityTeleportNMSPacket extends VersionNMSPacket { // On ground packetByteBuffer.writeBoolean(false); - this.rawPacket = writeData(new PacketPlayOutEntityTeleport(), packetByteBuffer); + this.rawPacket = packetByteBuffer.writeDataTo(new PacketPlayOutEntityTeleport()); } @Override diff --git a/nms/v1_11_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_11_R1/PacketByteBuffer.java b/nms/v1_11_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_11_R1/PacketByteBuffer.java index cba1470a..3a6aa0eb 100644 --- a/nms/v1_11_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_11_R1/PacketByteBuffer.java +++ b/nms/v1_11_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_11_R1/PacketByteBuffer.java @@ -6,25 +6,57 @@ package me.filoghost.holographicdisplays.nms.v1_11_R1; import io.netty.buffer.Unpooled; +import net.minecraft.server.v1_11_R1.Packet; import net.minecraft.server.v1_11_R1.PacketDataSerializer; +import java.io.IOException; import java.util.UUID; -class PacketByteBuffer extends PacketDataSerializer { +class PacketByteBuffer { private static final PacketByteBuffer INSTANCE = new PacketByteBuffer(); + private final PacketDataSerializer serializer; + static PacketByteBuffer get() { INSTANCE.clear(); return INSTANCE; } private PacketByteBuffer() { - super(Unpooled.buffer()); + this.serializer = new PacketDataSerializer(Unpooled.buffer()); + } + + int readableBytes() { + return serializer.readableBytes(); + } + + void readBytes(byte[] bytes) { + serializer.readBytes(bytes); + } + + void writeBoolean(boolean flag) { + serializer.writeBoolean(flag); + } + + void writeByte(int i) { + serializer.writeByte(i); + } + + void writeShort(int i) { + serializer.writeShort(i); + } + + void writeInt(int i) { + serializer.writeInt(i); + } + + void writeDouble(double d) { + serializer.writeDouble(d); } void writeVarInt(int i) { - super.d(i); + serializer.d(i); } void writeVarIntArray(int i1) { @@ -33,17 +65,31 @@ class PacketByteBuffer extends PacketDataSerializer { } void writeUUID(UUID uuid) { - super.a(uuid); + serializer.a(uuid); } void writeDataWatcherEntry(DataWatcherKey key, T value) { - writeByte(key.getIndex()); + serializer.writeByte(key.getIndex()); writeVarInt(key.getSerializerTypeID()); - key.getSerializer().a(this, value); + key.getSerializer().a(serializer, value); } void writeDataWatcherEntriesEnd() { - writeByte(0xFF); + serializer.writeByte(0xFF); + } + + void clear() { + serializer.clear(); + } + + > T writeDataTo(T packet) { + try { + packet.a(serializer); + return packet; + } catch (IOException e) { + // Never thrown by the implementations + throw new RuntimeException(e); + } } } diff --git a/nms/v1_11_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_11_R1/VersionNMSPacket.java b/nms/v1_11_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_11_R1/VersionNMSPacket.java index 82e26c56..7ab80296 100644 --- a/nms/v1_11_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_11_R1/VersionNMSPacket.java +++ b/nms/v1_11_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_11_R1/VersionNMSPacket.java @@ -10,8 +10,6 @@ import net.minecraft.server.v1_11_R1.Packet; import org.bukkit.craftbukkit.v1_11_R1.entity.CraftPlayer; import org.bukkit.entity.Player; -import java.io.IOException; - abstract class VersionNMSPacket implements PacketGroup { @Override @@ -21,14 +19,4 @@ abstract class VersionNMSPacket implements PacketGroup { abstract Packet getRawPacket(); - protected static > T writeData(T packet, PacketByteBuffer packetByteBuffer) { - try { - packet.a(packetByteBuffer); - return packet; - } catch (IOException e) { - // Never thrown by the implementations - throw new RuntimeException(e); - } - } - } diff --git a/nms/v1_12_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_12_R1/EntityLivingSpawnNMSPacket.java b/nms/v1_12_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_12_R1/EntityLivingSpawnNMSPacket.java index 9f452c19..ad8a41a4 100644 --- a/nms/v1_12_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_12_R1/EntityLivingSpawnNMSPacket.java +++ b/nms/v1_12_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_12_R1/EntityLivingSpawnNMSPacket.java @@ -62,7 +62,7 @@ class EntityLivingSpawnNMSPacket extends VersionNMSPacket { // Entries are deserialized and saved into a field which is not used during the re-serialization, set as empty packetByteBuffer.writeDataWatcherEntriesEnd(); - Packet rawPacket = writeData(new PacketPlayOutSpawnEntityLiving(), packetByteBuffer); + Packet rawPacket = packetByteBuffer.writeDataTo(new PacketPlayOutSpawnEntityLiving()); return new Builder(rawPacket, PacketByteBuffer.get()); } diff --git a/nms/v1_12_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_12_R1/EntityMetadataNMSPacket.java b/nms/v1_12_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_12_R1/EntityMetadataNMSPacket.java index 9e9f2c3e..679976eb 100644 --- a/nms/v1_12_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_12_R1/EntityMetadataNMSPacket.java +++ b/nms/v1_12_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_12_R1/EntityMetadataNMSPacket.java @@ -14,7 +14,7 @@ class EntityMetadataNMSPacket extends VersionNMSPacket { private final Packet rawPacket; private EntityMetadataNMSPacket(PacketByteBuffer packetByteBuffer) { - this.rawPacket = writeData(new PacketPlayOutEntityMetadata(), packetByteBuffer); + this.rawPacket = packetByteBuffer.writeDataTo(new PacketPlayOutEntityMetadata()); } @Override diff --git a/nms/v1_12_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_12_R1/EntityMountNMSPacket.java b/nms/v1_12_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_12_R1/EntityMountNMSPacket.java index c80a35ae..4f5c759f 100644 --- a/nms/v1_12_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_12_R1/EntityMountNMSPacket.java +++ b/nms/v1_12_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_12_R1/EntityMountNMSPacket.java @@ -19,7 +19,7 @@ class EntityMountNMSPacket extends VersionNMSPacket { packetByteBuffer.writeVarInt(vehicleEntityID.getNumericID()); packetByteBuffer.writeVarIntArray(passengerEntityID.getNumericID()); - this.rawPacket = writeData(new PacketPlayOutMount(), packetByteBuffer); + this.rawPacket = packetByteBuffer.writeDataTo(new PacketPlayOutMount()); } @Override diff --git a/nms/v1_12_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_12_R1/EntitySpawnNMSPacket.java b/nms/v1_12_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_12_R1/EntitySpawnNMSPacket.java index 12550e7b..0a1dc238 100644 --- a/nms/v1_12_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_12_R1/EntitySpawnNMSPacket.java +++ b/nms/v1_12_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_12_R1/EntitySpawnNMSPacket.java @@ -42,7 +42,7 @@ class EntitySpawnNMSPacket extends VersionNMSPacket { packetByteBuffer.writeShort(0); packetByteBuffer.writeShort(0); - this.rawPacket = writeData(new PacketPlayOutSpawnEntity(), packetByteBuffer); + this.rawPacket = packetByteBuffer.writeDataTo(new PacketPlayOutSpawnEntity()); } @Override diff --git a/nms/v1_12_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_12_R1/EntityTeleportNMSPacket.java b/nms/v1_12_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_12_R1/EntityTeleportNMSPacket.java index b19eb9b8..a75ee3b3 100644 --- a/nms/v1_12_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_12_R1/EntityTeleportNMSPacket.java +++ b/nms/v1_12_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_12_R1/EntityTeleportNMSPacket.java @@ -31,7 +31,7 @@ class EntityTeleportNMSPacket extends VersionNMSPacket { // On ground packetByteBuffer.writeBoolean(false); - this.rawPacket = writeData(new PacketPlayOutEntityTeleport(), packetByteBuffer); + this.rawPacket = packetByteBuffer.writeDataTo(new PacketPlayOutEntityTeleport()); } @Override diff --git a/nms/v1_12_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_12_R1/PacketByteBuffer.java b/nms/v1_12_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_12_R1/PacketByteBuffer.java index 49d58e1d..0eb7eb0d 100644 --- a/nms/v1_12_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_12_R1/PacketByteBuffer.java +++ b/nms/v1_12_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_12_R1/PacketByteBuffer.java @@ -6,25 +6,57 @@ package me.filoghost.holographicdisplays.nms.v1_12_R1; import io.netty.buffer.Unpooled; +import net.minecraft.server.v1_12_R1.Packet; import net.minecraft.server.v1_12_R1.PacketDataSerializer; +import java.io.IOException; import java.util.UUID; -class PacketByteBuffer extends PacketDataSerializer { +class PacketByteBuffer { private static final PacketByteBuffer INSTANCE = new PacketByteBuffer(); + private final PacketDataSerializer serializer; + static PacketByteBuffer get() { INSTANCE.clear(); return INSTANCE; } private PacketByteBuffer() { - super(Unpooled.buffer()); + this.serializer = new PacketDataSerializer(Unpooled.buffer()); + } + + int readableBytes() { + return serializer.readableBytes(); + } + + void readBytes(byte[] bytes) { + serializer.readBytes(bytes); + } + + void writeBoolean(boolean flag) { + serializer.writeBoolean(flag); + } + + void writeByte(int i) { + serializer.writeByte(i); + } + + void writeShort(int i) { + serializer.writeShort(i); + } + + void writeInt(int i) { + serializer.writeInt(i); + } + + void writeDouble(double d) { + serializer.writeDouble(d); } void writeVarInt(int i) { - super.d(i); + serializer.d(i); } void writeVarIntArray(int i1) { @@ -33,17 +65,31 @@ class PacketByteBuffer extends PacketDataSerializer { } void writeUUID(UUID uuid) { - super.a(uuid); + serializer.a(uuid); } void writeDataWatcherEntry(DataWatcherKey key, T value) { - writeByte(key.getIndex()); + serializer.writeByte(key.getIndex()); writeVarInt(key.getSerializerTypeID()); - key.getSerializer().a(this, value); + key.getSerializer().a(serializer, value); } void writeDataWatcherEntriesEnd() { - writeByte(0xFF); + serializer.writeByte(0xFF); + } + + void clear() { + serializer.clear(); + } + + > T writeDataTo(T packet) { + try { + packet.a(serializer); + return packet; + } catch (IOException e) { + // Never thrown by the implementations + throw new RuntimeException(e); + } } } diff --git a/nms/v1_12_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_12_R1/VersionNMSPacket.java b/nms/v1_12_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_12_R1/VersionNMSPacket.java index b28e05d5..b338294d 100644 --- a/nms/v1_12_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_12_R1/VersionNMSPacket.java +++ b/nms/v1_12_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_12_R1/VersionNMSPacket.java @@ -10,8 +10,6 @@ import net.minecraft.server.v1_12_R1.Packet; import org.bukkit.craftbukkit.v1_12_R1.entity.CraftPlayer; import org.bukkit.entity.Player; -import java.io.IOException; - abstract class VersionNMSPacket implements PacketGroup { @Override @@ -21,14 +19,4 @@ abstract class VersionNMSPacket implements PacketGroup { abstract Packet getRawPacket(); - protected static > T writeData(T packet, PacketByteBuffer packetByteBuffer) { - try { - packet.a(packetByteBuffer); - return packet; - } catch (IOException e) { - // Never thrown by the implementations - throw new RuntimeException(e); - } - } - } diff --git a/nms/v1_13_r2/src/main/java/me/filoghost/holographicdisplays/nms/v1_13_R2/EntityLivingSpawnNMSPacket.java b/nms/v1_13_r2/src/main/java/me/filoghost/holographicdisplays/nms/v1_13_R2/EntityLivingSpawnNMSPacket.java index 50818675..bcfa6fa1 100644 --- a/nms/v1_13_r2/src/main/java/me/filoghost/holographicdisplays/nms/v1_13_R2/EntityLivingSpawnNMSPacket.java +++ b/nms/v1_13_r2/src/main/java/me/filoghost/holographicdisplays/nms/v1_13_R2/EntityLivingSpawnNMSPacket.java @@ -62,7 +62,7 @@ class EntityLivingSpawnNMSPacket extends VersionNMSPacket { // Entries are deserialized and saved into a field which is not used during the re-serialization, set as empty packetByteBuffer.writeDataWatcherEntriesEnd(); - Packet rawPacket = writeData(new PacketPlayOutSpawnEntityLiving(), packetByteBuffer); + Packet rawPacket = packetByteBuffer.writeDataTo(new PacketPlayOutSpawnEntityLiving()); return new Builder(rawPacket, PacketByteBuffer.get()); } diff --git a/nms/v1_13_r2/src/main/java/me/filoghost/holographicdisplays/nms/v1_13_R2/EntityMetadataNMSPacket.java b/nms/v1_13_r2/src/main/java/me/filoghost/holographicdisplays/nms/v1_13_R2/EntityMetadataNMSPacket.java index 7e4ea325..863c445d 100644 --- a/nms/v1_13_r2/src/main/java/me/filoghost/holographicdisplays/nms/v1_13_R2/EntityMetadataNMSPacket.java +++ b/nms/v1_13_r2/src/main/java/me/filoghost/holographicdisplays/nms/v1_13_R2/EntityMetadataNMSPacket.java @@ -14,7 +14,7 @@ class EntityMetadataNMSPacket extends VersionNMSPacket { private final Packet rawPacket; private EntityMetadataNMSPacket(PacketByteBuffer packetByteBuffer) { - this.rawPacket = writeData(new PacketPlayOutEntityMetadata(), packetByteBuffer); + this.rawPacket = packetByteBuffer.writeDataTo(new PacketPlayOutEntityMetadata()); } @Override diff --git a/nms/v1_13_r2/src/main/java/me/filoghost/holographicdisplays/nms/v1_13_R2/EntityMountNMSPacket.java b/nms/v1_13_r2/src/main/java/me/filoghost/holographicdisplays/nms/v1_13_R2/EntityMountNMSPacket.java index d499dc3e..beaa0902 100644 --- a/nms/v1_13_r2/src/main/java/me/filoghost/holographicdisplays/nms/v1_13_R2/EntityMountNMSPacket.java +++ b/nms/v1_13_r2/src/main/java/me/filoghost/holographicdisplays/nms/v1_13_R2/EntityMountNMSPacket.java @@ -19,7 +19,7 @@ class EntityMountNMSPacket extends VersionNMSPacket { packetByteBuffer.writeVarInt(vehicleEntityID.getNumericID()); packetByteBuffer.writeVarIntArray(passengerEntityID.getNumericID()); - this.rawPacket = writeData(new PacketPlayOutMount(), packetByteBuffer); + this.rawPacket = packetByteBuffer.writeDataTo(new PacketPlayOutMount()); } @Override diff --git a/nms/v1_13_r2/src/main/java/me/filoghost/holographicdisplays/nms/v1_13_R2/EntitySpawnNMSPacket.java b/nms/v1_13_r2/src/main/java/me/filoghost/holographicdisplays/nms/v1_13_R2/EntitySpawnNMSPacket.java index dd176637..9dd157c4 100644 --- a/nms/v1_13_r2/src/main/java/me/filoghost/holographicdisplays/nms/v1_13_R2/EntitySpawnNMSPacket.java +++ b/nms/v1_13_r2/src/main/java/me/filoghost/holographicdisplays/nms/v1_13_R2/EntitySpawnNMSPacket.java @@ -42,7 +42,7 @@ class EntitySpawnNMSPacket extends VersionNMSPacket { packetByteBuffer.writeShort(0); packetByteBuffer.writeShort(0); - this.rawPacket = writeData(new PacketPlayOutSpawnEntity(), packetByteBuffer); + this.rawPacket = packetByteBuffer.writeDataTo(new PacketPlayOutSpawnEntity()); } @Override diff --git a/nms/v1_13_r2/src/main/java/me/filoghost/holographicdisplays/nms/v1_13_R2/EntityTeleportNMSPacket.java b/nms/v1_13_r2/src/main/java/me/filoghost/holographicdisplays/nms/v1_13_R2/EntityTeleportNMSPacket.java index 709bbb95..46882d62 100644 --- a/nms/v1_13_r2/src/main/java/me/filoghost/holographicdisplays/nms/v1_13_R2/EntityTeleportNMSPacket.java +++ b/nms/v1_13_r2/src/main/java/me/filoghost/holographicdisplays/nms/v1_13_R2/EntityTeleportNMSPacket.java @@ -31,7 +31,7 @@ class EntityTeleportNMSPacket extends VersionNMSPacket { // On ground packetByteBuffer.writeBoolean(false); - this.rawPacket = writeData(new PacketPlayOutEntityTeleport(), packetByteBuffer); + this.rawPacket = packetByteBuffer.writeDataTo(new PacketPlayOutEntityTeleport()); } @Override diff --git a/nms/v1_13_r2/src/main/java/me/filoghost/holographicdisplays/nms/v1_13_R2/PacketByteBuffer.java b/nms/v1_13_r2/src/main/java/me/filoghost/holographicdisplays/nms/v1_13_R2/PacketByteBuffer.java index f329d91d..b80d88eb 100644 --- a/nms/v1_13_r2/src/main/java/me/filoghost/holographicdisplays/nms/v1_13_R2/PacketByteBuffer.java +++ b/nms/v1_13_r2/src/main/java/me/filoghost/holographicdisplays/nms/v1_13_R2/PacketByteBuffer.java @@ -6,25 +6,57 @@ package me.filoghost.holographicdisplays.nms.v1_13_R2; import io.netty.buffer.Unpooled; +import net.minecraft.server.v1_13_R2.Packet; import net.minecraft.server.v1_13_R2.PacketDataSerializer; +import java.io.IOException; import java.util.UUID; -class PacketByteBuffer extends PacketDataSerializer { +class PacketByteBuffer { private static final PacketByteBuffer INSTANCE = new PacketByteBuffer(); + private final PacketDataSerializer serializer; + static PacketByteBuffer get() { INSTANCE.clear(); return INSTANCE; } private PacketByteBuffer() { - super(Unpooled.buffer()); + this.serializer = new PacketDataSerializer(Unpooled.buffer()); + } + + int readableBytes() { + return serializer.readableBytes(); + } + + void readBytes(byte[] bytes) { + serializer.readBytes(bytes); + } + + void writeBoolean(boolean flag) { + serializer.writeBoolean(flag); + } + + void writeByte(int i) { + serializer.writeByte(i); + } + + void writeShort(int i) { + serializer.writeShort(i); + } + + void writeInt(int i) { + serializer.writeInt(i); + } + + void writeDouble(double d) { + serializer.writeDouble(d); } void writeVarInt(int i) { - super.d(i); + serializer.d(i); } void writeVarIntArray(int i1) { @@ -33,17 +65,31 @@ class PacketByteBuffer extends PacketDataSerializer { } void writeUUID(UUID uuid) { - super.a(uuid); + serializer.a(uuid); } void writeDataWatcherEntry(DataWatcherKey key, T value) { - writeByte(key.getIndex()); + serializer.writeByte(key.getIndex()); writeVarInt(key.getSerializerTypeID()); - key.getSerializer().a(this, value); + key.getSerializer().a(serializer, value); } void writeDataWatcherEntriesEnd() { - writeByte(0xFF); + serializer.writeByte(0xFF); + } + + void clear() { + serializer.clear(); + } + + > T writeDataTo(T packet) { + try { + packet.a(serializer); + return packet; + } catch (IOException e) { + // Never thrown by the implementations + throw new RuntimeException(e); + } } } diff --git a/nms/v1_13_r2/src/main/java/me/filoghost/holographicdisplays/nms/v1_13_R2/VersionNMSPacket.java b/nms/v1_13_r2/src/main/java/me/filoghost/holographicdisplays/nms/v1_13_R2/VersionNMSPacket.java index 1bf6c22f..d6ef9f45 100644 --- a/nms/v1_13_r2/src/main/java/me/filoghost/holographicdisplays/nms/v1_13_R2/VersionNMSPacket.java +++ b/nms/v1_13_r2/src/main/java/me/filoghost/holographicdisplays/nms/v1_13_R2/VersionNMSPacket.java @@ -10,8 +10,6 @@ import net.minecraft.server.v1_13_R2.Packet; import org.bukkit.craftbukkit.v1_13_R2.entity.CraftPlayer; import org.bukkit.entity.Player; -import java.io.IOException; - abstract class VersionNMSPacket implements PacketGroup { @Override @@ -21,14 +19,4 @@ abstract class VersionNMSPacket implements PacketGroup { abstract Packet getRawPacket(); - protected static > T writeData(T packet, PacketByteBuffer packetByteBuffer) { - try { - packet.a(packetByteBuffer); - return packet; - } catch (IOException e) { - // Never thrown by the implementations - throw new RuntimeException(e); - } - } - } diff --git a/nms/v1_14_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_14_R1/EntityLivingSpawnNMSPacket.java b/nms/v1_14_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_14_R1/EntityLivingSpawnNMSPacket.java index 3bea182b..2b23d03f 100644 --- a/nms/v1_14_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_14_R1/EntityLivingSpawnNMSPacket.java +++ b/nms/v1_14_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_14_R1/EntityLivingSpawnNMSPacket.java @@ -62,7 +62,7 @@ class EntityLivingSpawnNMSPacket extends VersionNMSPacket { // Entries are deserialized and saved into a field which is not used during the re-serialization, set as empty packetByteBuffer.writeDataWatcherEntriesEnd(); - Packet rawPacket = writeData(new PacketPlayOutSpawnEntityLiving(), packetByteBuffer); + Packet rawPacket = packetByteBuffer.writeDataTo(new PacketPlayOutSpawnEntityLiving()); return new Builder(rawPacket, PacketByteBuffer.get()); } diff --git a/nms/v1_14_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_14_R1/EntityMetadataNMSPacket.java b/nms/v1_14_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_14_R1/EntityMetadataNMSPacket.java index b2cba4a5..8dc4a1cb 100644 --- a/nms/v1_14_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_14_R1/EntityMetadataNMSPacket.java +++ b/nms/v1_14_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_14_R1/EntityMetadataNMSPacket.java @@ -14,7 +14,7 @@ class EntityMetadataNMSPacket extends VersionNMSPacket { private final Packet rawPacket; private EntityMetadataNMSPacket(PacketByteBuffer packetByteBuffer) { - this.rawPacket = writeData(new PacketPlayOutEntityMetadata(), packetByteBuffer); + this.rawPacket = packetByteBuffer.writeDataTo(new PacketPlayOutEntityMetadata()); } @Override diff --git a/nms/v1_14_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_14_R1/EntityMountNMSPacket.java b/nms/v1_14_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_14_R1/EntityMountNMSPacket.java index 06945717..8d5becbb 100644 --- a/nms/v1_14_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_14_R1/EntityMountNMSPacket.java +++ b/nms/v1_14_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_14_R1/EntityMountNMSPacket.java @@ -19,7 +19,7 @@ class EntityMountNMSPacket extends VersionNMSPacket { packetByteBuffer.writeVarInt(vehicleEntityID.getNumericID()); packetByteBuffer.writeVarIntArray(passengerEntityID.getNumericID()); - this.rawPacket = writeData(new PacketPlayOutMount(), packetByteBuffer); + this.rawPacket = packetByteBuffer.writeDataTo(new PacketPlayOutMount()); } @Override diff --git a/nms/v1_14_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_14_R1/EntitySpawnNMSPacket.java b/nms/v1_14_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_14_R1/EntitySpawnNMSPacket.java index 77779a6d..f4d647a5 100644 --- a/nms/v1_14_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_14_R1/EntitySpawnNMSPacket.java +++ b/nms/v1_14_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_14_R1/EntitySpawnNMSPacket.java @@ -42,7 +42,7 @@ class EntitySpawnNMSPacket extends VersionNMSPacket { packetByteBuffer.writeShort(0); packetByteBuffer.writeShort(0); - this.rawPacket = writeData(new PacketPlayOutSpawnEntity(), packetByteBuffer); + this.rawPacket = packetByteBuffer.writeDataTo(new PacketPlayOutSpawnEntity()); } @Override diff --git a/nms/v1_14_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_14_R1/EntityTeleportNMSPacket.java b/nms/v1_14_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_14_R1/EntityTeleportNMSPacket.java index 8c00000b..72eb1c79 100644 --- a/nms/v1_14_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_14_R1/EntityTeleportNMSPacket.java +++ b/nms/v1_14_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_14_R1/EntityTeleportNMSPacket.java @@ -31,7 +31,7 @@ class EntityTeleportNMSPacket extends VersionNMSPacket { // On ground packetByteBuffer.writeBoolean(false); - this.rawPacket = writeData(new PacketPlayOutEntityTeleport(), packetByteBuffer); + this.rawPacket = packetByteBuffer.writeDataTo(new PacketPlayOutEntityTeleport()); } @Override diff --git a/nms/v1_14_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_14_R1/PacketByteBuffer.java b/nms/v1_14_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_14_R1/PacketByteBuffer.java index afe77c94..348473cb 100644 --- a/nms/v1_14_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_14_R1/PacketByteBuffer.java +++ b/nms/v1_14_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_14_R1/PacketByteBuffer.java @@ -6,25 +6,57 @@ package me.filoghost.holographicdisplays.nms.v1_14_R1; import io.netty.buffer.Unpooled; +import net.minecraft.server.v1_14_R1.Packet; import net.minecraft.server.v1_14_R1.PacketDataSerializer; +import java.io.IOException; import java.util.UUID; -class PacketByteBuffer extends PacketDataSerializer { +class PacketByteBuffer { private static final PacketByteBuffer INSTANCE = new PacketByteBuffer(); + private final PacketDataSerializer serializer; + static PacketByteBuffer get() { INSTANCE.clear(); return INSTANCE; } private PacketByteBuffer() { - super(Unpooled.buffer()); + this.serializer = new PacketDataSerializer(Unpooled.buffer()); + } + + int readableBytes() { + return serializer.readableBytes(); + } + + void readBytes(byte[] bytes) { + serializer.readBytes(bytes); + } + + void writeBoolean(boolean flag) { + serializer.writeBoolean(flag); + } + + void writeByte(int i) { + serializer.writeByte(i); + } + + void writeShort(int i) { + serializer.writeShort(i); + } + + void writeInt(int i) { + serializer.writeInt(i); + } + + void writeDouble(double d) { + serializer.writeDouble(d); } void writeVarInt(int i) { - super.d(i); + serializer.d(i); } void writeVarIntArray(int i1) { @@ -33,17 +65,31 @@ class PacketByteBuffer extends PacketDataSerializer { } void writeUUID(UUID uuid) { - super.a(uuid); + serializer.a(uuid); } void writeDataWatcherEntry(DataWatcherKey key, T value) { - writeByte(key.getIndex()); + serializer.writeByte(key.getIndex()); writeVarInt(key.getSerializerTypeID()); - key.getSerializer().a(this, value); + key.getSerializer().a(serializer, value); } void writeDataWatcherEntriesEnd() { - writeByte(0xFF); + serializer.writeByte(0xFF); + } + + void clear() { + serializer.clear(); + } + + > T writeDataTo(T packet) { + try { + packet.a(serializer); + return packet; + } catch (IOException e) { + // Never thrown by the implementations + throw new RuntimeException(e); + } } } diff --git a/nms/v1_14_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_14_R1/VersionNMSPacket.java b/nms/v1_14_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_14_R1/VersionNMSPacket.java index 4bdcf967..39bcb117 100644 --- a/nms/v1_14_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_14_R1/VersionNMSPacket.java +++ b/nms/v1_14_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_14_R1/VersionNMSPacket.java @@ -10,8 +10,6 @@ import net.minecraft.server.v1_14_R1.Packet; import org.bukkit.craftbukkit.v1_14_R1.entity.CraftPlayer; import org.bukkit.entity.Player; -import java.io.IOException; - abstract class VersionNMSPacket implements PacketGroup { @Override @@ -21,14 +19,4 @@ abstract class VersionNMSPacket implements PacketGroup { abstract Packet getRawPacket(); - protected static > T writeData(T packet, PacketByteBuffer packetByteBuffer) { - try { - packet.a(packetByteBuffer); - return packet; - } catch (IOException e) { - // Never thrown by the implementations - throw new RuntimeException(e); - } - } - } diff --git a/nms/v1_15_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_15_R1/EntityLivingSpawnNMSPacket.java b/nms/v1_15_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_15_R1/EntityLivingSpawnNMSPacket.java index 284b8082..f6acc755 100644 --- a/nms/v1_15_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_15_R1/EntityLivingSpawnNMSPacket.java +++ b/nms/v1_15_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_15_R1/EntityLivingSpawnNMSPacket.java @@ -38,7 +38,7 @@ class EntityLivingSpawnNMSPacket extends VersionNMSPacket { packetByteBuffer.writeShort(0); packetByteBuffer.writeShort(0); - this.rawPacket = writeData(new PacketPlayOutSpawnEntityLiving(), packetByteBuffer); + this.rawPacket = packetByteBuffer.writeDataTo(new PacketPlayOutSpawnEntityLiving()); } @Override diff --git a/nms/v1_15_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_15_R1/EntityMetadataNMSPacket.java b/nms/v1_15_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_15_R1/EntityMetadataNMSPacket.java index 13c30abe..2d861ca5 100644 --- a/nms/v1_15_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_15_R1/EntityMetadataNMSPacket.java +++ b/nms/v1_15_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_15_R1/EntityMetadataNMSPacket.java @@ -14,7 +14,7 @@ class EntityMetadataNMSPacket extends VersionNMSPacket { private final Packet rawPacket; private EntityMetadataNMSPacket(PacketByteBuffer packetByteBuffer) { - this.rawPacket = writeData(new PacketPlayOutEntityMetadata(), packetByteBuffer); + this.rawPacket = packetByteBuffer.writeDataTo(new PacketPlayOutEntityMetadata()); } @Override diff --git a/nms/v1_15_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_15_R1/EntityMountNMSPacket.java b/nms/v1_15_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_15_R1/EntityMountNMSPacket.java index 4465dba9..62e0977d 100644 --- a/nms/v1_15_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_15_R1/EntityMountNMSPacket.java +++ b/nms/v1_15_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_15_R1/EntityMountNMSPacket.java @@ -19,7 +19,7 @@ class EntityMountNMSPacket extends VersionNMSPacket { packetByteBuffer.writeVarInt(vehicleEntityID.getNumericID()); packetByteBuffer.writeVarIntArray(passengerEntityID.getNumericID()); - this.rawPacket = writeData(new PacketPlayOutMount(), packetByteBuffer); + this.rawPacket = packetByteBuffer.writeDataTo(new PacketPlayOutMount()); } @Override diff --git a/nms/v1_15_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_15_R1/EntitySpawnNMSPacket.java b/nms/v1_15_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_15_R1/EntitySpawnNMSPacket.java index c22ff511..68aaf0bd 100644 --- a/nms/v1_15_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_15_R1/EntitySpawnNMSPacket.java +++ b/nms/v1_15_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_15_R1/EntitySpawnNMSPacket.java @@ -42,7 +42,7 @@ class EntitySpawnNMSPacket extends VersionNMSPacket { packetByteBuffer.writeShort(0); packetByteBuffer.writeShort(0); - this.rawPacket = writeData(new PacketPlayOutSpawnEntity(), packetByteBuffer); + this.rawPacket = packetByteBuffer.writeDataTo(new PacketPlayOutSpawnEntity()); } @Override diff --git a/nms/v1_15_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_15_R1/EntityTeleportNMSPacket.java b/nms/v1_15_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_15_R1/EntityTeleportNMSPacket.java index 5a34375a..fa079816 100644 --- a/nms/v1_15_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_15_R1/EntityTeleportNMSPacket.java +++ b/nms/v1_15_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_15_R1/EntityTeleportNMSPacket.java @@ -31,7 +31,7 @@ class EntityTeleportNMSPacket extends VersionNMSPacket { // On ground packetByteBuffer.writeBoolean(false); - this.rawPacket = writeData(new PacketPlayOutEntityTeleport(), packetByteBuffer); + this.rawPacket = packetByteBuffer.writeDataTo(new PacketPlayOutEntityTeleport()); } @Override diff --git a/nms/v1_15_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_15_R1/PacketByteBuffer.java b/nms/v1_15_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_15_R1/PacketByteBuffer.java index dc147a1a..a49ff050 100644 --- a/nms/v1_15_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_15_R1/PacketByteBuffer.java +++ b/nms/v1_15_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_15_R1/PacketByteBuffer.java @@ -6,25 +6,49 @@ package me.filoghost.holographicdisplays.nms.v1_15_R1; import io.netty.buffer.Unpooled; +import net.minecraft.server.v1_15_R1.Packet; import net.minecraft.server.v1_15_R1.PacketDataSerializer; +import java.io.IOException; import java.util.UUID; -class PacketByteBuffer extends PacketDataSerializer { +class PacketByteBuffer { private static final PacketByteBuffer INSTANCE = new PacketByteBuffer(); + private final PacketDataSerializer serializer; + static PacketByteBuffer get() { INSTANCE.clear(); return INSTANCE; } private PacketByteBuffer() { - super(Unpooled.buffer()); + this.serializer = new PacketDataSerializer(Unpooled.buffer()); + } + + void writeBoolean(boolean flag) { + serializer.writeBoolean(flag); + } + + void writeByte(int i) { + serializer.writeByte(i); + } + + void writeShort(int i) { + serializer.writeShort(i); + } + + void writeInt(int i) { + serializer.writeInt(i); + } + + void writeDouble(double d) { + serializer.writeDouble(d); } void writeVarInt(int i) { - super.d(i); + serializer.d(i); } void writeVarIntArray(int i1) { @@ -33,17 +57,31 @@ class PacketByteBuffer extends PacketDataSerializer { } void writeUUID(UUID uuid) { - super.a(uuid); + serializer.a(uuid); } void writeDataWatcherEntry(DataWatcherKey key, T value) { - writeByte(key.getIndex()); + serializer.writeByte(key.getIndex()); writeVarInt(key.getSerializerTypeID()); - key.getSerializer().a(this, value); + key.getSerializer().a(serializer, value); } void writeDataWatcherEntriesEnd() { - writeByte(0xFF); + serializer.writeByte(0xFF); + } + + void clear() { + serializer.clear(); + } + + > T writeDataTo(T packet) { + try { + packet.a(serializer); + return packet; + } catch (IOException e) { + // Never thrown by the implementations + throw new RuntimeException(e); + } } } diff --git a/nms/v1_15_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_15_R1/VersionNMSPacket.java b/nms/v1_15_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_15_R1/VersionNMSPacket.java index fc4f2c49..f83169ce 100644 --- a/nms/v1_15_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_15_R1/VersionNMSPacket.java +++ b/nms/v1_15_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_15_R1/VersionNMSPacket.java @@ -10,8 +10,6 @@ import net.minecraft.server.v1_15_R1.Packet; import org.bukkit.craftbukkit.v1_15_R1.entity.CraftPlayer; import org.bukkit.entity.Player; -import java.io.IOException; - abstract class VersionNMSPacket implements PacketGroup { @Override @@ -21,14 +19,4 @@ abstract class VersionNMSPacket implements PacketGroup { abstract Packet getRawPacket(); - protected static > T writeData(T packet, PacketByteBuffer packetByteBuffer) { - try { - packet.a(packetByteBuffer); - return packet; - } catch (IOException e) { - // Never thrown by the implementations - throw new RuntimeException(e); - } - } - } diff --git a/nms/v1_16_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_16_R1/EntityLivingSpawnNMSPacket.java b/nms/v1_16_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_16_R1/EntityLivingSpawnNMSPacket.java index 0e9d7b97..b573fa76 100644 --- a/nms/v1_16_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_16_R1/EntityLivingSpawnNMSPacket.java +++ b/nms/v1_16_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_16_R1/EntityLivingSpawnNMSPacket.java @@ -38,7 +38,7 @@ class EntityLivingSpawnNMSPacket extends VersionNMSPacket { packetByteBuffer.writeShort(0); packetByteBuffer.writeShort(0); - this.rawPacket = writeData(new PacketPlayOutSpawnEntityLiving(), packetByteBuffer); + this.rawPacket = packetByteBuffer.writeDataTo(new PacketPlayOutSpawnEntityLiving()); } @Override diff --git a/nms/v1_16_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_16_R1/EntityMetadataNMSPacket.java b/nms/v1_16_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_16_R1/EntityMetadataNMSPacket.java index d5fe21ad..fae9f8c2 100644 --- a/nms/v1_16_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_16_R1/EntityMetadataNMSPacket.java +++ b/nms/v1_16_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_16_R1/EntityMetadataNMSPacket.java @@ -14,7 +14,7 @@ class EntityMetadataNMSPacket extends VersionNMSPacket { private final Packet rawPacket; private EntityMetadataNMSPacket(PacketByteBuffer packetByteBuffer) { - this.rawPacket = writeData(new PacketPlayOutEntityMetadata(), packetByteBuffer); + this.rawPacket = packetByteBuffer.writeDataTo(new PacketPlayOutEntityMetadata()); } @Override diff --git a/nms/v1_16_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_16_R1/EntityMountNMSPacket.java b/nms/v1_16_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_16_R1/EntityMountNMSPacket.java index 0514feb2..9a002b43 100644 --- a/nms/v1_16_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_16_R1/EntityMountNMSPacket.java +++ b/nms/v1_16_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_16_R1/EntityMountNMSPacket.java @@ -19,7 +19,7 @@ class EntityMountNMSPacket extends VersionNMSPacket { packetByteBuffer.writeVarInt(vehicleEntityID.getNumericID()); packetByteBuffer.writeVarIntArray(passengerEntityID.getNumericID()); - this.rawPacket = writeData(new PacketPlayOutMount(), packetByteBuffer); + this.rawPacket = packetByteBuffer.writeDataTo(new PacketPlayOutMount()); } @Override diff --git a/nms/v1_16_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_16_R1/EntitySpawnNMSPacket.java b/nms/v1_16_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_16_R1/EntitySpawnNMSPacket.java index 9d658bd9..9ce17cd4 100644 --- a/nms/v1_16_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_16_R1/EntitySpawnNMSPacket.java +++ b/nms/v1_16_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_16_R1/EntitySpawnNMSPacket.java @@ -42,7 +42,7 @@ class EntitySpawnNMSPacket extends VersionNMSPacket { packetByteBuffer.writeShort(0); packetByteBuffer.writeShort(0); - this.rawPacket = writeData(new PacketPlayOutSpawnEntity(), packetByteBuffer); + this.rawPacket = packetByteBuffer.writeDataTo(new PacketPlayOutSpawnEntity()); } @Override diff --git a/nms/v1_16_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_16_R1/EntityTeleportNMSPacket.java b/nms/v1_16_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_16_R1/EntityTeleportNMSPacket.java index 0dd2f379..cd2f4b45 100644 --- a/nms/v1_16_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_16_R1/EntityTeleportNMSPacket.java +++ b/nms/v1_16_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_16_R1/EntityTeleportNMSPacket.java @@ -31,7 +31,7 @@ class EntityTeleportNMSPacket extends VersionNMSPacket { // On ground packetByteBuffer.writeBoolean(false); - this.rawPacket = writeData(new PacketPlayOutEntityTeleport(), packetByteBuffer); + this.rawPacket = packetByteBuffer.writeDataTo(new PacketPlayOutEntityTeleport()); } @Override diff --git a/nms/v1_16_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_16_R1/PacketByteBuffer.java b/nms/v1_16_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_16_R1/PacketByteBuffer.java index ccb0b460..d8fec3c9 100644 --- a/nms/v1_16_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_16_R1/PacketByteBuffer.java +++ b/nms/v1_16_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_16_R1/PacketByteBuffer.java @@ -6,25 +6,50 @@ package me.filoghost.holographicdisplays.nms.v1_16_R1; import io.netty.buffer.Unpooled; +import net.minecraft.server.v1_16_R1.Packet; import net.minecraft.server.v1_16_R1.PacketDataSerializer; +import java.io.IOException; import java.util.UUID; -class PacketByteBuffer extends PacketDataSerializer { +class PacketByteBuffer { private static final PacketByteBuffer INSTANCE = new PacketByteBuffer(); + private final PacketDataSerializer serializer; + static PacketByteBuffer get() { INSTANCE.clear(); return INSTANCE; } private PacketByteBuffer() { - super(Unpooled.buffer()); + this.serializer = new PacketDataSerializer(Unpooled.buffer()); + } + + void writeBoolean(boolean flag) { + serializer.writeBoolean(flag); + } + + + void writeByte(int i) { + serializer.writeByte(i); + } + + void writeShort(int i) { + serializer.writeShort(i); + } + + void writeInt(int i) { + serializer.writeInt(i); + } + + void writeDouble(double d) { + serializer.writeDouble(d); } void writeVarInt(int i) { - super.d(i); + serializer.d(i); } void writeVarIntArray(int i1) { @@ -33,17 +58,31 @@ class PacketByteBuffer extends PacketDataSerializer { } void writeUUID(UUID uuid) { - super.a(uuid); + serializer.a(uuid); } void writeDataWatcherEntry(DataWatcherKey key, T value) { - writeByte(key.getIndex()); + serializer.writeByte(key.getIndex()); writeVarInt(key.getSerializerTypeID()); - key.getSerializer().a(this, value); + key.getSerializer().a(serializer, value); } void writeDataWatcherEntriesEnd() { - writeByte(0xFF); + serializer.writeByte(0xFF); + } + + void clear() { + serializer.clear(); + } + + > T writeDataTo(T packet) { + try { + packet.a(serializer); + return packet; + } catch (IOException e) { + // Never thrown by the implementations + throw new RuntimeException(e); + } } } diff --git a/nms/v1_16_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_16_R1/VersionNMSPacket.java b/nms/v1_16_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_16_R1/VersionNMSPacket.java index 89a3ab14..17e0acf3 100644 --- a/nms/v1_16_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_16_R1/VersionNMSPacket.java +++ b/nms/v1_16_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_16_R1/VersionNMSPacket.java @@ -10,8 +10,6 @@ import net.minecraft.server.v1_16_R1.Packet; import org.bukkit.craftbukkit.v1_16_R1.entity.CraftPlayer; import org.bukkit.entity.Player; -import java.io.IOException; - abstract class VersionNMSPacket implements PacketGroup { @Override @@ -21,14 +19,4 @@ abstract class VersionNMSPacket implements PacketGroup { abstract Packet getRawPacket(); - protected static > T writeData(T packet, PacketByteBuffer packetByteBuffer) { - try { - packet.a(packetByteBuffer); - return packet; - } catch (IOException e) { - // Never thrown by the implementations - throw new RuntimeException(e); - } - } - } diff --git a/nms/v1_16_r2/src/main/java/me/filoghost/holographicdisplays/nms/v1_16_R2/EntityLivingSpawnNMSPacket.java b/nms/v1_16_r2/src/main/java/me/filoghost/holographicdisplays/nms/v1_16_R2/EntityLivingSpawnNMSPacket.java index 9e1244c0..b956b408 100644 --- a/nms/v1_16_r2/src/main/java/me/filoghost/holographicdisplays/nms/v1_16_R2/EntityLivingSpawnNMSPacket.java +++ b/nms/v1_16_r2/src/main/java/me/filoghost/holographicdisplays/nms/v1_16_R2/EntityLivingSpawnNMSPacket.java @@ -38,7 +38,7 @@ class EntityLivingSpawnNMSPacket extends VersionNMSPacket { packetByteBuffer.writeShort(0); packetByteBuffer.writeShort(0); - this.rawPacket = writeData(new PacketPlayOutSpawnEntityLiving(), packetByteBuffer); + this.rawPacket = packetByteBuffer.writeDataTo(new PacketPlayOutSpawnEntityLiving()); } @Override diff --git a/nms/v1_16_r2/src/main/java/me/filoghost/holographicdisplays/nms/v1_16_R2/EntityMetadataNMSPacket.java b/nms/v1_16_r2/src/main/java/me/filoghost/holographicdisplays/nms/v1_16_R2/EntityMetadataNMSPacket.java index 50fce18d..51fcc553 100644 --- a/nms/v1_16_r2/src/main/java/me/filoghost/holographicdisplays/nms/v1_16_R2/EntityMetadataNMSPacket.java +++ b/nms/v1_16_r2/src/main/java/me/filoghost/holographicdisplays/nms/v1_16_R2/EntityMetadataNMSPacket.java @@ -14,7 +14,7 @@ class EntityMetadataNMSPacket extends VersionNMSPacket { private final Packet rawPacket; private EntityMetadataNMSPacket(PacketByteBuffer packetByteBuffer) { - this.rawPacket = writeData(new PacketPlayOutEntityMetadata(), packetByteBuffer); + this.rawPacket = packetByteBuffer.writeDataTo(new PacketPlayOutEntityMetadata()); } @Override diff --git a/nms/v1_16_r2/src/main/java/me/filoghost/holographicdisplays/nms/v1_16_R2/EntityMountNMSPacket.java b/nms/v1_16_r2/src/main/java/me/filoghost/holographicdisplays/nms/v1_16_R2/EntityMountNMSPacket.java index dbbfcba3..3eb1de64 100644 --- a/nms/v1_16_r2/src/main/java/me/filoghost/holographicdisplays/nms/v1_16_R2/EntityMountNMSPacket.java +++ b/nms/v1_16_r2/src/main/java/me/filoghost/holographicdisplays/nms/v1_16_R2/EntityMountNMSPacket.java @@ -19,7 +19,7 @@ class EntityMountNMSPacket extends VersionNMSPacket { packetByteBuffer.writeVarInt(vehicleEntityID.getNumericID()); packetByteBuffer.writeVarIntArray(passengerEntityID.getNumericID()); - this.rawPacket = writeData(new PacketPlayOutMount(), packetByteBuffer); + this.rawPacket = packetByteBuffer.writeDataTo(new PacketPlayOutMount()); } @Override diff --git a/nms/v1_16_r2/src/main/java/me/filoghost/holographicdisplays/nms/v1_16_R2/EntitySpawnNMSPacket.java b/nms/v1_16_r2/src/main/java/me/filoghost/holographicdisplays/nms/v1_16_R2/EntitySpawnNMSPacket.java index 0fe5987f..14f16220 100644 --- a/nms/v1_16_r2/src/main/java/me/filoghost/holographicdisplays/nms/v1_16_R2/EntitySpawnNMSPacket.java +++ b/nms/v1_16_r2/src/main/java/me/filoghost/holographicdisplays/nms/v1_16_R2/EntitySpawnNMSPacket.java @@ -42,7 +42,7 @@ class EntitySpawnNMSPacket extends VersionNMSPacket { packetByteBuffer.writeShort(0); packetByteBuffer.writeShort(0); - this.rawPacket = writeData(new PacketPlayOutSpawnEntity(), packetByteBuffer); + this.rawPacket = packetByteBuffer.writeDataTo(new PacketPlayOutSpawnEntity()); } @Override diff --git a/nms/v1_16_r2/src/main/java/me/filoghost/holographicdisplays/nms/v1_16_R2/EntityTeleportNMSPacket.java b/nms/v1_16_r2/src/main/java/me/filoghost/holographicdisplays/nms/v1_16_R2/EntityTeleportNMSPacket.java index 87817817..9bc20160 100644 --- a/nms/v1_16_r2/src/main/java/me/filoghost/holographicdisplays/nms/v1_16_R2/EntityTeleportNMSPacket.java +++ b/nms/v1_16_r2/src/main/java/me/filoghost/holographicdisplays/nms/v1_16_R2/EntityTeleportNMSPacket.java @@ -31,7 +31,7 @@ class EntityTeleportNMSPacket extends VersionNMSPacket { // On ground packetByteBuffer.writeBoolean(false); - this.rawPacket = writeData(new PacketPlayOutEntityTeleport(), packetByteBuffer); + this.rawPacket = packetByteBuffer.writeDataTo(new PacketPlayOutEntityTeleport()); } @Override diff --git a/nms/v1_16_r2/src/main/java/me/filoghost/holographicdisplays/nms/v1_16_R2/PacketByteBuffer.java b/nms/v1_16_r2/src/main/java/me/filoghost/holographicdisplays/nms/v1_16_R2/PacketByteBuffer.java index 37044192..789bf2bf 100644 --- a/nms/v1_16_r2/src/main/java/me/filoghost/holographicdisplays/nms/v1_16_R2/PacketByteBuffer.java +++ b/nms/v1_16_r2/src/main/java/me/filoghost/holographicdisplays/nms/v1_16_R2/PacketByteBuffer.java @@ -6,25 +6,49 @@ package me.filoghost.holographicdisplays.nms.v1_16_R2; import io.netty.buffer.Unpooled; +import net.minecraft.server.v1_16_R2.Packet; import net.minecraft.server.v1_16_R2.PacketDataSerializer; +import java.io.IOException; import java.util.UUID; -class PacketByteBuffer extends PacketDataSerializer { +class PacketByteBuffer { private static final PacketByteBuffer INSTANCE = new PacketByteBuffer(); + private final PacketDataSerializer serializer; + static PacketByteBuffer get() { INSTANCE.clear(); return INSTANCE; } private PacketByteBuffer() { - super(Unpooled.buffer()); + this.serializer = new PacketDataSerializer(Unpooled.buffer()); + } + + void writeBoolean(boolean flag) { + serializer.writeBoolean(flag); + } + + void writeByte(int i) { + serializer.writeByte(i); + } + + void writeShort(int i) { + serializer.writeShort(i); + } + + void writeInt(int i) { + serializer.writeInt(i); + } + + void writeDouble(double d) { + serializer.writeDouble(d); } void writeVarInt(int i) { - super.d(i); + serializer.d(i); } void writeVarIntArray(int i1) { @@ -33,17 +57,31 @@ class PacketByteBuffer extends PacketDataSerializer { } void writeUUID(UUID uuid) { - super.a(uuid); + serializer.a(uuid); } void writeDataWatcherEntry(DataWatcherKey key, T value) { - writeByte(key.getIndex()); + serializer.writeByte(key.getIndex()); writeVarInt(key.getSerializerTypeID()); - key.getSerializer().a(this, value); + key.getSerializer().a(serializer, value); } void writeDataWatcherEntriesEnd() { - writeByte(0xFF); + serializer.writeByte(0xFF); + } + + void clear() { + serializer.clear(); + } + + > T writeDataTo(T packet) { + try { + packet.a(serializer); + return packet; + } catch (IOException e) { + // Never thrown by the implementations + throw new RuntimeException(e); + } } } diff --git a/nms/v1_16_r2/src/main/java/me/filoghost/holographicdisplays/nms/v1_16_R2/VersionNMSPacket.java b/nms/v1_16_r2/src/main/java/me/filoghost/holographicdisplays/nms/v1_16_R2/VersionNMSPacket.java index 4c9d0b63..1d82a040 100644 --- a/nms/v1_16_r2/src/main/java/me/filoghost/holographicdisplays/nms/v1_16_R2/VersionNMSPacket.java +++ b/nms/v1_16_r2/src/main/java/me/filoghost/holographicdisplays/nms/v1_16_R2/VersionNMSPacket.java @@ -10,8 +10,6 @@ import net.minecraft.server.v1_16_R2.Packet; import org.bukkit.craftbukkit.v1_16_R2.entity.CraftPlayer; import org.bukkit.entity.Player; -import java.io.IOException; - abstract class VersionNMSPacket implements PacketGroup { @Override @@ -21,14 +19,4 @@ abstract class VersionNMSPacket implements PacketGroup { abstract Packet getRawPacket(); - protected static > T writeData(T packet, PacketByteBuffer packetByteBuffer) { - try { - packet.a(packetByteBuffer); - return packet; - } catch (IOException e) { - // Never thrown by the implementations - throw new RuntimeException(e); - } - } - } diff --git a/nms/v1_16_r3/src/main/java/me/filoghost/holographicdisplays/nms/v1_16_R3/EntityLivingSpawnNMSPacket.java b/nms/v1_16_r3/src/main/java/me/filoghost/holographicdisplays/nms/v1_16_R3/EntityLivingSpawnNMSPacket.java index 73a3b5b6..f774c953 100644 --- a/nms/v1_16_r3/src/main/java/me/filoghost/holographicdisplays/nms/v1_16_R3/EntityLivingSpawnNMSPacket.java +++ b/nms/v1_16_r3/src/main/java/me/filoghost/holographicdisplays/nms/v1_16_R3/EntityLivingSpawnNMSPacket.java @@ -38,7 +38,7 @@ class EntityLivingSpawnNMSPacket extends VersionNMSPacket { packetByteBuffer.writeShort(0); packetByteBuffer.writeShort(0); - this.rawPacket = writeData(new PacketPlayOutSpawnEntityLiving(), packetByteBuffer); + this.rawPacket = packetByteBuffer.writeDataTo(new PacketPlayOutSpawnEntityLiving()); } @Override diff --git a/nms/v1_16_r3/src/main/java/me/filoghost/holographicdisplays/nms/v1_16_R3/EntityMetadataNMSPacket.java b/nms/v1_16_r3/src/main/java/me/filoghost/holographicdisplays/nms/v1_16_R3/EntityMetadataNMSPacket.java index 47327c03..6b2abf5c 100644 --- a/nms/v1_16_r3/src/main/java/me/filoghost/holographicdisplays/nms/v1_16_R3/EntityMetadataNMSPacket.java +++ b/nms/v1_16_r3/src/main/java/me/filoghost/holographicdisplays/nms/v1_16_R3/EntityMetadataNMSPacket.java @@ -14,7 +14,7 @@ class EntityMetadataNMSPacket extends VersionNMSPacket { private final Packet rawPacket; private EntityMetadataNMSPacket(PacketByteBuffer packetByteBuffer) { - this.rawPacket = writeData(new PacketPlayOutEntityMetadata(), packetByteBuffer); + this.rawPacket = packetByteBuffer.writeDataTo(new PacketPlayOutEntityMetadata()); } @Override diff --git a/nms/v1_16_r3/src/main/java/me/filoghost/holographicdisplays/nms/v1_16_R3/EntityMountNMSPacket.java b/nms/v1_16_r3/src/main/java/me/filoghost/holographicdisplays/nms/v1_16_R3/EntityMountNMSPacket.java index 22394c61..9d8a70b2 100644 --- a/nms/v1_16_r3/src/main/java/me/filoghost/holographicdisplays/nms/v1_16_R3/EntityMountNMSPacket.java +++ b/nms/v1_16_r3/src/main/java/me/filoghost/holographicdisplays/nms/v1_16_R3/EntityMountNMSPacket.java @@ -19,7 +19,7 @@ class EntityMountNMSPacket extends VersionNMSPacket { packetByteBuffer.writeVarInt(vehicleEntityID.getNumericID()); packetByteBuffer.writeVarIntArray(passengerEntityID.getNumericID()); - this.rawPacket = writeData(new PacketPlayOutMount(), packetByteBuffer); + this.rawPacket = packetByteBuffer.writeDataTo(new PacketPlayOutMount()); } @Override diff --git a/nms/v1_16_r3/src/main/java/me/filoghost/holographicdisplays/nms/v1_16_R3/EntitySpawnNMSPacket.java b/nms/v1_16_r3/src/main/java/me/filoghost/holographicdisplays/nms/v1_16_R3/EntitySpawnNMSPacket.java index 69b8bba6..100677e7 100644 --- a/nms/v1_16_r3/src/main/java/me/filoghost/holographicdisplays/nms/v1_16_R3/EntitySpawnNMSPacket.java +++ b/nms/v1_16_r3/src/main/java/me/filoghost/holographicdisplays/nms/v1_16_R3/EntitySpawnNMSPacket.java @@ -42,7 +42,7 @@ class EntitySpawnNMSPacket extends VersionNMSPacket { packetByteBuffer.writeShort(0); packetByteBuffer.writeShort(0); - this.rawPacket = writeData(new PacketPlayOutSpawnEntity(), packetByteBuffer); + this.rawPacket = packetByteBuffer.writeDataTo(new PacketPlayOutSpawnEntity()); } @Override diff --git a/nms/v1_16_r3/src/main/java/me/filoghost/holographicdisplays/nms/v1_16_R3/EntityTeleportNMSPacket.java b/nms/v1_16_r3/src/main/java/me/filoghost/holographicdisplays/nms/v1_16_R3/EntityTeleportNMSPacket.java index 28d1dbc8..a14a9554 100644 --- a/nms/v1_16_r3/src/main/java/me/filoghost/holographicdisplays/nms/v1_16_R3/EntityTeleportNMSPacket.java +++ b/nms/v1_16_r3/src/main/java/me/filoghost/holographicdisplays/nms/v1_16_R3/EntityTeleportNMSPacket.java @@ -31,7 +31,7 @@ class EntityTeleportNMSPacket extends VersionNMSPacket { // On ground packetByteBuffer.writeBoolean(false); - this.rawPacket = writeData(new PacketPlayOutEntityTeleport(), packetByteBuffer); + this.rawPacket = packetByteBuffer.writeDataTo(new PacketPlayOutEntityTeleport()); } @Override diff --git a/nms/v1_16_r3/src/main/java/me/filoghost/holographicdisplays/nms/v1_16_R3/PacketByteBuffer.java b/nms/v1_16_r3/src/main/java/me/filoghost/holographicdisplays/nms/v1_16_R3/PacketByteBuffer.java index 2956dbca..d7c9d01c 100644 --- a/nms/v1_16_r3/src/main/java/me/filoghost/holographicdisplays/nms/v1_16_R3/PacketByteBuffer.java +++ b/nms/v1_16_r3/src/main/java/me/filoghost/holographicdisplays/nms/v1_16_R3/PacketByteBuffer.java @@ -6,25 +6,49 @@ package me.filoghost.holographicdisplays.nms.v1_16_R3; import io.netty.buffer.Unpooled; +import net.minecraft.server.v1_16_R3.Packet; import net.minecraft.server.v1_16_R3.PacketDataSerializer; +import java.io.IOException; import java.util.UUID; -class PacketByteBuffer extends PacketDataSerializer { +class PacketByteBuffer { private static final PacketByteBuffer INSTANCE = new PacketByteBuffer(); + private final PacketDataSerializer serializer; + static PacketByteBuffer get() { INSTANCE.clear(); return INSTANCE; } + void writeBoolean(boolean flag) { + serializer.writeBoolean(flag); + } + + void writeByte(int i) { + serializer.writeByte(i); + } + + void writeShort(int i) { + serializer.writeShort(i); + } + + void writeInt(int i) { + serializer.writeInt(i); + } + + void writeDouble(double d) { + serializer.writeDouble(d); + } + private PacketByteBuffer() { - super(Unpooled.buffer()); + this.serializer = new PacketDataSerializer(Unpooled.buffer()); } void writeVarInt(int i) { - super.d(i); + serializer.d(i); } void writeVarIntArray(int i1) { @@ -33,17 +57,31 @@ class PacketByteBuffer extends PacketDataSerializer { } void writeUUID(UUID uuid) { - super.a(uuid); + serializer.a(uuid); } void writeDataWatcherEntry(DataWatcherKey key, T value) { - writeByte(key.getIndex()); + serializer.writeByte(key.getIndex()); writeVarInt(key.getSerializerTypeID()); - key.getSerializer().a(this, value); + key.getSerializer().a(serializer, value); } void writeDataWatcherEntriesEnd() { - writeByte(0xFF); + serializer.writeByte(0xFF); + } + + void clear() { + serializer.clear(); + } + + > T writeDataTo(T packet) { + try { + packet.a(serializer); + return packet; + } catch (IOException e) { + // Never thrown by the implementations + throw new RuntimeException(e); + } } } diff --git a/nms/v1_16_r3/src/main/java/me/filoghost/holographicdisplays/nms/v1_16_R3/VersionNMSPacket.java b/nms/v1_16_r3/src/main/java/me/filoghost/holographicdisplays/nms/v1_16_R3/VersionNMSPacket.java index bd0bd6d8..75e871d2 100644 --- a/nms/v1_16_r3/src/main/java/me/filoghost/holographicdisplays/nms/v1_16_R3/VersionNMSPacket.java +++ b/nms/v1_16_r3/src/main/java/me/filoghost/holographicdisplays/nms/v1_16_R3/VersionNMSPacket.java @@ -10,8 +10,6 @@ import net.minecraft.server.v1_16_R3.Packet; import org.bukkit.craftbukkit.v1_16_R3.entity.CraftPlayer; import org.bukkit.entity.Player; -import java.io.IOException; - abstract class VersionNMSPacket implements PacketGroup { @Override @@ -21,14 +19,4 @@ abstract class VersionNMSPacket implements PacketGroup { abstract Packet getRawPacket(); - protected static > T writeData(T packet, PacketByteBuffer packetByteBuffer) { - try { - packet.a(packetByteBuffer); - return packet; - } catch (IOException e) { - // Never thrown by the implementations - throw new RuntimeException(e); - } - } - } diff --git a/nms/v1_17_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_17_R1/EntityDestroyNMSPacket.java b/nms/v1_17_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_17_R1/EntityDestroyNMSPacket.java index b8e0deb9..f6625c3f 100644 --- a/nms/v1_17_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_17_R1/EntityDestroyNMSPacket.java +++ b/nms/v1_17_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_17_R1/EntityDestroyNMSPacket.java @@ -18,7 +18,7 @@ class EntityDestroyNMSPacket extends VersionNMSPacket { packetByteBuffer.writeVarInt(entityID.getNumericID()); - this.rawPacket = new PacketPlayOutEntityDestroy(packetByteBuffer); + this.rawPacket = new PacketPlayOutEntityDestroy(packetByteBuffer.getInternalSerializer()); } @Override diff --git a/nms/v1_17_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_17_R1/EntityListDestroyNMSPacket.java b/nms/v1_17_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_17_R1/EntityListDestroyNMSPacket.java index 9fde995e..5ec72536 100644 --- a/nms/v1_17_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_17_R1/EntityListDestroyNMSPacket.java +++ b/nms/v1_17_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_17_R1/EntityListDestroyNMSPacket.java @@ -18,7 +18,7 @@ class EntityListDestroyNMSPacket extends VersionNMSPacket { packetByteBuffer.writeVarIntArray(entityID.getNumericID()); - this.rawPacket = new PacketPlayOutEntityDestroy(packetByteBuffer); + this.rawPacket = new PacketPlayOutEntityDestroy(packetByteBuffer.getInternalSerializer()); } EntityListDestroyNMSPacket(EntityID entityID1, EntityID entityID2) { @@ -26,7 +26,7 @@ class EntityListDestroyNMSPacket extends VersionNMSPacket { packetByteBuffer.writeVarIntArray(entityID1.getNumericID(), entityID2.getNumericID()); - this.rawPacket = new PacketPlayOutEntityDestroy(packetByteBuffer); + this.rawPacket = new PacketPlayOutEntityDestroy(packetByteBuffer.getInternalSerializer()); } @Override diff --git a/nms/v1_17_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_17_R1/EntityLivingSpawnNMSPacket.java b/nms/v1_17_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_17_R1/EntityLivingSpawnNMSPacket.java index 1cb60c1a..3ddbb5d9 100644 --- a/nms/v1_17_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_17_R1/EntityLivingSpawnNMSPacket.java +++ b/nms/v1_17_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_17_R1/EntityLivingSpawnNMSPacket.java @@ -38,7 +38,7 @@ class EntityLivingSpawnNMSPacket extends VersionNMSPacket { packetByteBuffer.writeShort(0); packetByteBuffer.writeShort(0); - this.rawPacket = new PacketPlayOutSpawnEntityLiving(packetByteBuffer); + this.rawPacket = new PacketPlayOutSpawnEntityLiving(packetByteBuffer.getInternalSerializer()); } @Override diff --git a/nms/v1_17_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_17_R1/EntityMetadataNMSPacket.java b/nms/v1_17_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_17_R1/EntityMetadataNMSPacket.java index 92f837b5..f86a9ea6 100644 --- a/nms/v1_17_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_17_R1/EntityMetadataNMSPacket.java +++ b/nms/v1_17_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_17_R1/EntityMetadataNMSPacket.java @@ -14,7 +14,7 @@ class EntityMetadataNMSPacket extends VersionNMSPacket { private final Packet rawPacket; private EntityMetadataNMSPacket(PacketByteBuffer packetByteBuffer) { - this.rawPacket = new PacketPlayOutEntityMetadata(packetByteBuffer); + this.rawPacket = new PacketPlayOutEntityMetadata(packetByteBuffer.getInternalSerializer()); } @Override diff --git a/nms/v1_17_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_17_R1/EntityMountNMSPacket.java b/nms/v1_17_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_17_R1/EntityMountNMSPacket.java index a63fed1d..13e988f0 100644 --- a/nms/v1_17_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_17_R1/EntityMountNMSPacket.java +++ b/nms/v1_17_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_17_R1/EntityMountNMSPacket.java @@ -19,7 +19,7 @@ class EntityMountNMSPacket extends VersionNMSPacket { packetByteBuffer.writeVarInt(vehicleEntityID.getNumericID()); packetByteBuffer.writeVarIntArray(passengerEntityID.getNumericID()); - this.rawPacket = new PacketPlayOutMount(packetByteBuffer); + this.rawPacket = new PacketPlayOutMount(packetByteBuffer.getInternalSerializer()); } @Override diff --git a/nms/v1_17_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_17_R1/EntitySpawnNMSPacket.java b/nms/v1_17_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_17_R1/EntitySpawnNMSPacket.java index eabba365..ffdf0dd0 100644 --- a/nms/v1_17_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_17_R1/EntitySpawnNMSPacket.java +++ b/nms/v1_17_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_17_R1/EntitySpawnNMSPacket.java @@ -42,7 +42,7 @@ class EntitySpawnNMSPacket extends VersionNMSPacket { packetByteBuffer.writeShort(0); packetByteBuffer.writeShort(0); - this.rawPacket = new PacketPlayOutSpawnEntity(packetByteBuffer); + this.rawPacket = new PacketPlayOutSpawnEntity(packetByteBuffer.getInternalSerializer()); } @Override diff --git a/nms/v1_17_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_17_R1/EntityTeleportNMSPacket.java b/nms/v1_17_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_17_R1/EntityTeleportNMSPacket.java index 4d5d701d..64e90982 100644 --- a/nms/v1_17_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_17_R1/EntityTeleportNMSPacket.java +++ b/nms/v1_17_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_17_R1/EntityTeleportNMSPacket.java @@ -31,7 +31,7 @@ class EntityTeleportNMSPacket extends VersionNMSPacket { // On ground packetByteBuffer.writeBoolean(false); - this.rawPacket = new PacketPlayOutEntityTeleport(packetByteBuffer); + this.rawPacket = new PacketPlayOutEntityTeleport(packetByteBuffer.getInternalSerializer()); } @Override diff --git a/nms/v1_17_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_17_R1/PacketByteBuffer.java b/nms/v1_17_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_17_R1/PacketByteBuffer.java index 8517a315..3937c0de 100644 --- a/nms/v1_17_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_17_R1/PacketByteBuffer.java +++ b/nms/v1_17_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_17_R1/PacketByteBuffer.java @@ -10,21 +10,43 @@ import net.minecraft.network.PacketDataSerializer; import java.util.UUID; -class PacketByteBuffer extends PacketDataSerializer { +class PacketByteBuffer { private static final PacketByteBuffer INSTANCE = new PacketByteBuffer(); + private final PacketDataSerializer serializer; + static PacketByteBuffer get() { INSTANCE.clear(); return INSTANCE; } private PacketByteBuffer() { - super(Unpooled.buffer()); + this.serializer = new PacketDataSerializer(Unpooled.buffer()); + } + + void writeBoolean(boolean flag) { + serializer.writeBoolean(flag); + } + + void writeByte(int i) { + serializer.writeByte(i); + } + + void writeShort(int i) { + serializer.writeShort(i); + } + + void writeInt(int i) { + serializer.writeInt(i); + } + + void writeDouble(double d) { + serializer.writeDouble(d); } void writeVarInt(int i) { - super.d(i); + serializer.d(i); } void writeVarIntArray(int i1) { @@ -39,17 +61,25 @@ class PacketByteBuffer extends PacketDataSerializer { } void writeUUID(UUID uuid) { - super.a(uuid); + serializer.a(uuid); } void writeDataWatcherEntry(DataWatcherKey key, T value) { - writeByte(key.getIndex()); + serializer.writeByte(key.getIndex()); writeVarInt(key.getSerializerTypeID()); - key.getSerializer().a(this, value); + key.getSerializer().a(serializer, value); } void writeDataWatcherEntriesEnd() { - writeByte(0xFF); + serializer.writeByte(0xFF); + } + + public PacketDataSerializer getInternalSerializer() { + return serializer; + } + + void clear() { + serializer.clear(); } } diff --git a/nms/v1_18_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_18_R1/EntityDestroyNMSPacket.java b/nms/v1_18_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_18_R1/EntityDestroyNMSPacket.java index ee719634..c0750ad7 100644 --- a/nms/v1_18_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_18_R1/EntityDestroyNMSPacket.java +++ b/nms/v1_18_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_18_R1/EntityDestroyNMSPacket.java @@ -18,7 +18,7 @@ class EntityDestroyNMSPacket extends VersionNMSPacket { packetByteBuffer.writeVarIntArray(entityID.getNumericID()); - this.rawPacket = new PacketPlayOutEntityDestroy(packetByteBuffer); + this.rawPacket = new PacketPlayOutEntityDestroy(packetByteBuffer.getInternalSerializer()); } EntityDestroyNMSPacket(EntityID entityID1, EntityID entityID2) { @@ -26,7 +26,7 @@ class EntityDestroyNMSPacket extends VersionNMSPacket { packetByteBuffer.writeVarIntArray(entityID1.getNumericID(), entityID2.getNumericID()); - this.rawPacket = new PacketPlayOutEntityDestroy(packetByteBuffer); + this.rawPacket = new PacketPlayOutEntityDestroy(packetByteBuffer.getInternalSerializer()); } @Override diff --git a/nms/v1_18_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_18_R1/EntityLivingSpawnNMSPacket.java b/nms/v1_18_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_18_R1/EntityLivingSpawnNMSPacket.java index c6f2b0af..4805e5a3 100644 --- a/nms/v1_18_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_18_R1/EntityLivingSpawnNMSPacket.java +++ b/nms/v1_18_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_18_R1/EntityLivingSpawnNMSPacket.java @@ -38,7 +38,7 @@ class EntityLivingSpawnNMSPacket extends VersionNMSPacket { packetByteBuffer.writeShort(0); packetByteBuffer.writeShort(0); - this.rawPacket = new PacketPlayOutSpawnEntityLiving(packetByteBuffer); + this.rawPacket = new PacketPlayOutSpawnEntityLiving(packetByteBuffer.getInternalSerializer()); } @Override diff --git a/nms/v1_18_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_18_R1/EntityMetadataNMSPacket.java b/nms/v1_18_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_18_R1/EntityMetadataNMSPacket.java index 275add23..66ecb5f8 100644 --- a/nms/v1_18_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_18_R1/EntityMetadataNMSPacket.java +++ b/nms/v1_18_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_18_R1/EntityMetadataNMSPacket.java @@ -14,7 +14,7 @@ class EntityMetadataNMSPacket extends VersionNMSPacket { private final Packet rawPacket; private EntityMetadataNMSPacket(PacketByteBuffer packetByteBuffer) { - this.rawPacket = new PacketPlayOutEntityMetadata(packetByteBuffer); + this.rawPacket = new PacketPlayOutEntityMetadata(packetByteBuffer.getInternalSerializer()); } @Override diff --git a/nms/v1_18_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_18_R1/EntityMountNMSPacket.java b/nms/v1_18_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_18_R1/EntityMountNMSPacket.java index 0eac776c..d3ccc451 100644 --- a/nms/v1_18_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_18_R1/EntityMountNMSPacket.java +++ b/nms/v1_18_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_18_R1/EntityMountNMSPacket.java @@ -19,7 +19,7 @@ class EntityMountNMSPacket extends VersionNMSPacket { packetByteBuffer.writeVarInt(vehicleEntityID.getNumericID()); packetByteBuffer.writeVarIntArray(passengerEntityID.getNumericID()); - this.rawPacket = new PacketPlayOutMount(packetByteBuffer); + this.rawPacket = new PacketPlayOutMount(packetByteBuffer.getInternalSerializer()); } @Override diff --git a/nms/v1_18_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_18_R1/EntitySpawnNMSPacket.java b/nms/v1_18_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_18_R1/EntitySpawnNMSPacket.java index 01dfb2ab..32f33f6d 100644 --- a/nms/v1_18_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_18_R1/EntitySpawnNMSPacket.java +++ b/nms/v1_18_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_18_R1/EntitySpawnNMSPacket.java @@ -42,7 +42,7 @@ class EntitySpawnNMSPacket extends VersionNMSPacket { packetByteBuffer.writeShort(0); packetByteBuffer.writeShort(0); - this.rawPacket = new PacketPlayOutSpawnEntity(packetByteBuffer); + this.rawPacket = new PacketPlayOutSpawnEntity(packetByteBuffer.getInternalSerializer()); } @Override diff --git a/nms/v1_18_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_18_R1/EntityTeleportNMSPacket.java b/nms/v1_18_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_18_R1/EntityTeleportNMSPacket.java index 8508d7d9..d7bfa3e9 100644 --- a/nms/v1_18_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_18_R1/EntityTeleportNMSPacket.java +++ b/nms/v1_18_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_18_R1/EntityTeleportNMSPacket.java @@ -31,7 +31,7 @@ class EntityTeleportNMSPacket extends VersionNMSPacket { // On ground packetByteBuffer.writeBoolean(false); - this.rawPacket = new PacketPlayOutEntityTeleport(packetByteBuffer); + this.rawPacket = new PacketPlayOutEntityTeleport(packetByteBuffer.getInternalSerializer()); } @Override diff --git a/nms/v1_18_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_18_R1/PacketByteBuffer.java b/nms/v1_18_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_18_R1/PacketByteBuffer.java index d401a128..756a018c 100644 --- a/nms/v1_18_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_18_R1/PacketByteBuffer.java +++ b/nms/v1_18_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_18_R1/PacketByteBuffer.java @@ -10,21 +10,43 @@ import net.minecraft.network.PacketDataSerializer; import java.util.UUID; -class PacketByteBuffer extends PacketDataSerializer { +class PacketByteBuffer { private static final PacketByteBuffer INSTANCE = new PacketByteBuffer(); + private final PacketDataSerializer serializer; + static PacketByteBuffer get() { INSTANCE.clear(); return INSTANCE; } private PacketByteBuffer() { - super(Unpooled.buffer()); + this.serializer = new PacketDataSerializer(Unpooled.buffer()); + } + + void writeBoolean(boolean flag) { + serializer.writeBoolean(flag); + } + + void writeByte(int i) { + serializer.writeByte(i); + } + + void writeShort(int i) { + serializer.writeShort(i); + } + + void writeInt(int i) { + serializer.writeInt(i); + } + + void writeDouble(double d) { + serializer.writeDouble(d); } void writeVarInt(int i) { - super.d(i); + serializer.d(i); } void writeVarIntArray(int i1) { @@ -39,17 +61,25 @@ class PacketByteBuffer extends PacketDataSerializer { } void writeUUID(UUID uuid) { - super.a(uuid); + serializer.a(uuid); } void writeDataWatcherEntry(DataWatcherKey key, T value) { - writeByte(key.getIndex()); + serializer.writeByte(key.getIndex()); writeVarInt(key.getSerializerTypeID()); - key.getSerializer().a(this, value); + key.getSerializer().a(serializer, value); } void writeDataWatcherEntriesEnd() { - writeByte(0xFF); + serializer.writeByte(0xFF); + } + + public PacketDataSerializer getInternalSerializer() { + return serializer; + } + + void clear() { + serializer.clear(); } } diff --git a/nms/v1_18_r2/src/main/java/me/filoghost/holographicdisplays/nms/v1_18_R2/EntityDestroyNMSPacket.java b/nms/v1_18_r2/src/main/java/me/filoghost/holographicdisplays/nms/v1_18_R2/EntityDestroyNMSPacket.java index d7be352f..a27d8bfd 100644 --- a/nms/v1_18_r2/src/main/java/me/filoghost/holographicdisplays/nms/v1_18_R2/EntityDestroyNMSPacket.java +++ b/nms/v1_18_r2/src/main/java/me/filoghost/holographicdisplays/nms/v1_18_R2/EntityDestroyNMSPacket.java @@ -18,7 +18,7 @@ class EntityDestroyNMSPacket extends VersionNMSPacket { packetByteBuffer.writeVarIntArray(entityID.getNumericID()); - this.rawPacket = new PacketPlayOutEntityDestroy(packetByteBuffer); + this.rawPacket = new PacketPlayOutEntityDestroy(packetByteBuffer.getInternalSerializer()); } EntityDestroyNMSPacket(EntityID entityID1, EntityID entityID2) { @@ -26,7 +26,7 @@ class EntityDestroyNMSPacket extends VersionNMSPacket { packetByteBuffer.writeVarIntArray(entityID1.getNumericID(), entityID2.getNumericID()); - this.rawPacket = new PacketPlayOutEntityDestroy(packetByteBuffer); + this.rawPacket = new PacketPlayOutEntityDestroy(packetByteBuffer.getInternalSerializer()); } @Override diff --git a/nms/v1_18_r2/src/main/java/me/filoghost/holographicdisplays/nms/v1_18_R2/EntityLivingSpawnNMSPacket.java b/nms/v1_18_r2/src/main/java/me/filoghost/holographicdisplays/nms/v1_18_R2/EntityLivingSpawnNMSPacket.java index 7e0f0146..fb06d5ad 100644 --- a/nms/v1_18_r2/src/main/java/me/filoghost/holographicdisplays/nms/v1_18_R2/EntityLivingSpawnNMSPacket.java +++ b/nms/v1_18_r2/src/main/java/me/filoghost/holographicdisplays/nms/v1_18_R2/EntityLivingSpawnNMSPacket.java @@ -38,7 +38,7 @@ class EntityLivingSpawnNMSPacket extends VersionNMSPacket { packetByteBuffer.writeShort(0); packetByteBuffer.writeShort(0); - this.rawPacket = new PacketPlayOutSpawnEntityLiving(packetByteBuffer); + this.rawPacket = new PacketPlayOutSpawnEntityLiving(packetByteBuffer.getInternalSerializer()); } @Override diff --git a/nms/v1_18_r2/src/main/java/me/filoghost/holographicdisplays/nms/v1_18_R2/EntityMetadataNMSPacket.java b/nms/v1_18_r2/src/main/java/me/filoghost/holographicdisplays/nms/v1_18_R2/EntityMetadataNMSPacket.java index deabcc0b..ea18f459 100644 --- a/nms/v1_18_r2/src/main/java/me/filoghost/holographicdisplays/nms/v1_18_R2/EntityMetadataNMSPacket.java +++ b/nms/v1_18_r2/src/main/java/me/filoghost/holographicdisplays/nms/v1_18_R2/EntityMetadataNMSPacket.java @@ -14,7 +14,7 @@ class EntityMetadataNMSPacket extends VersionNMSPacket { private final Packet rawPacket; private EntityMetadataNMSPacket(PacketByteBuffer packetByteBuffer) { - this.rawPacket = new PacketPlayOutEntityMetadata(packetByteBuffer); + this.rawPacket = new PacketPlayOutEntityMetadata(packetByteBuffer.getInternalSerializer()); } @Override diff --git a/nms/v1_18_r2/src/main/java/me/filoghost/holographicdisplays/nms/v1_18_R2/EntityMountNMSPacket.java b/nms/v1_18_r2/src/main/java/me/filoghost/holographicdisplays/nms/v1_18_R2/EntityMountNMSPacket.java index e73c77bb..d010d7c7 100644 --- a/nms/v1_18_r2/src/main/java/me/filoghost/holographicdisplays/nms/v1_18_R2/EntityMountNMSPacket.java +++ b/nms/v1_18_r2/src/main/java/me/filoghost/holographicdisplays/nms/v1_18_R2/EntityMountNMSPacket.java @@ -19,7 +19,7 @@ class EntityMountNMSPacket extends VersionNMSPacket { packetByteBuffer.writeVarInt(vehicleEntityID.getNumericID()); packetByteBuffer.writeVarIntArray(passengerEntityID.getNumericID()); - this.rawPacket = new PacketPlayOutMount(packetByteBuffer); + this.rawPacket = new PacketPlayOutMount(packetByteBuffer.getInternalSerializer()); } @Override diff --git a/nms/v1_18_r2/src/main/java/me/filoghost/holographicdisplays/nms/v1_18_R2/EntitySpawnNMSPacket.java b/nms/v1_18_r2/src/main/java/me/filoghost/holographicdisplays/nms/v1_18_R2/EntitySpawnNMSPacket.java index 22e0cd56..c5f30914 100644 --- a/nms/v1_18_r2/src/main/java/me/filoghost/holographicdisplays/nms/v1_18_R2/EntitySpawnNMSPacket.java +++ b/nms/v1_18_r2/src/main/java/me/filoghost/holographicdisplays/nms/v1_18_R2/EntitySpawnNMSPacket.java @@ -42,7 +42,7 @@ class EntitySpawnNMSPacket extends VersionNMSPacket { packetByteBuffer.writeShort(0); packetByteBuffer.writeShort(0); - this.rawPacket = new PacketPlayOutSpawnEntity(packetByteBuffer); + this.rawPacket = new PacketPlayOutSpawnEntity(packetByteBuffer.getInternalSerializer()); } @Override diff --git a/nms/v1_18_r2/src/main/java/me/filoghost/holographicdisplays/nms/v1_18_R2/EntityTeleportNMSPacket.java b/nms/v1_18_r2/src/main/java/me/filoghost/holographicdisplays/nms/v1_18_R2/EntityTeleportNMSPacket.java index 452e6a36..1c570be1 100644 --- a/nms/v1_18_r2/src/main/java/me/filoghost/holographicdisplays/nms/v1_18_R2/EntityTeleportNMSPacket.java +++ b/nms/v1_18_r2/src/main/java/me/filoghost/holographicdisplays/nms/v1_18_R2/EntityTeleportNMSPacket.java @@ -31,7 +31,7 @@ class EntityTeleportNMSPacket extends VersionNMSPacket { // On ground packetByteBuffer.writeBoolean(false); - this.rawPacket = new PacketPlayOutEntityTeleport(packetByteBuffer); + this.rawPacket = new PacketPlayOutEntityTeleport(packetByteBuffer.getInternalSerializer()); } @Override diff --git a/nms/v1_18_r2/src/main/java/me/filoghost/holographicdisplays/nms/v1_18_R2/PacketByteBuffer.java b/nms/v1_18_r2/src/main/java/me/filoghost/holographicdisplays/nms/v1_18_R2/PacketByteBuffer.java index 9e1a722f..47641c29 100644 --- a/nms/v1_18_r2/src/main/java/me/filoghost/holographicdisplays/nms/v1_18_R2/PacketByteBuffer.java +++ b/nms/v1_18_r2/src/main/java/me/filoghost/holographicdisplays/nms/v1_18_R2/PacketByteBuffer.java @@ -10,21 +10,43 @@ import net.minecraft.network.PacketDataSerializer; import java.util.UUID; -class PacketByteBuffer extends PacketDataSerializer { +class PacketByteBuffer { private static final PacketByteBuffer INSTANCE = new PacketByteBuffer(); + private final PacketDataSerializer serializer; + static PacketByteBuffer get() { INSTANCE.clear(); return INSTANCE; } private PacketByteBuffer() { - super(Unpooled.buffer()); + this.serializer = new PacketDataSerializer(Unpooled.buffer()); + } + + void writeBoolean(boolean flag) { + serializer.writeBoolean(flag); + } + + void writeByte(int i) { + serializer.writeByte(i); + } + + void writeShort(int i) { + serializer.writeShort(i); + } + + void writeInt(int i) { + serializer.writeInt(i); + } + + void writeDouble(double d) { + serializer.writeDouble(d); } void writeVarInt(int i) { - super.d(i); + serializer.d(i); } void writeVarIntArray(int i1) { @@ -39,17 +61,25 @@ class PacketByteBuffer extends PacketDataSerializer { } void writeUUID(UUID uuid) { - super.a(uuid); + serializer.a(uuid); } void writeDataWatcherEntry(DataWatcherKey key, T value) { - writeByte(key.getIndex()); + serializer.writeByte(key.getIndex()); writeVarInt(key.getSerializerTypeID()); - key.getSerializer().a(this, value); + key.getSerializer().a(serializer, value); } void writeDataWatcherEntriesEnd() { - writeByte(0xFF); + serializer.writeByte(0xFF); + } + + public PacketDataSerializer getInternalSerializer() { + return serializer; + } + + void clear() { + serializer.clear(); } } diff --git a/nms/v1_19_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_19_R1/EntityDestroyNMSPacket.java b/nms/v1_19_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_19_R1/EntityDestroyNMSPacket.java index 716302da..1903f57b 100644 --- a/nms/v1_19_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_19_R1/EntityDestroyNMSPacket.java +++ b/nms/v1_19_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_19_R1/EntityDestroyNMSPacket.java @@ -18,7 +18,7 @@ class EntityDestroyNMSPacket extends VersionNMSPacket { packetByteBuffer.writeVarIntArray(entityID.getNumericID()); - this.rawPacket = new PacketPlayOutEntityDestroy(packetByteBuffer); + this.rawPacket = new PacketPlayOutEntityDestroy(packetByteBuffer.getInternalSerializer()); } EntityDestroyNMSPacket(EntityID entityID1, EntityID entityID2) { @@ -26,7 +26,7 @@ class EntityDestroyNMSPacket extends VersionNMSPacket { packetByteBuffer.writeVarIntArray(entityID1.getNumericID(), entityID2.getNumericID()); - this.rawPacket = new PacketPlayOutEntityDestroy(packetByteBuffer); + this.rawPacket = new PacketPlayOutEntityDestroy(packetByteBuffer.getInternalSerializer()); } @Override diff --git a/nms/v1_19_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_19_R1/EntityMetadataNMSPacket.java b/nms/v1_19_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_19_R1/EntityMetadataNMSPacket.java index 9d8ba102..0be81ea2 100644 --- a/nms/v1_19_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_19_R1/EntityMetadataNMSPacket.java +++ b/nms/v1_19_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_19_R1/EntityMetadataNMSPacket.java @@ -14,7 +14,7 @@ class EntityMetadataNMSPacket extends VersionNMSPacket { private final Packet rawPacket; private EntityMetadataNMSPacket(PacketByteBuffer packetByteBuffer) { - this.rawPacket = new PacketPlayOutEntityMetadata(packetByteBuffer); + this.rawPacket = new PacketPlayOutEntityMetadata(packetByteBuffer.getInternalSerializer()); } @Override diff --git a/nms/v1_19_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_19_R1/EntityMountNMSPacket.java b/nms/v1_19_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_19_R1/EntityMountNMSPacket.java index b7f6bef5..5d38c095 100644 --- a/nms/v1_19_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_19_R1/EntityMountNMSPacket.java +++ b/nms/v1_19_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_19_R1/EntityMountNMSPacket.java @@ -19,7 +19,7 @@ class EntityMountNMSPacket extends VersionNMSPacket { packetByteBuffer.writeVarInt(vehicleEntityID.getNumericID()); packetByteBuffer.writeVarIntArray(passengerEntityID.getNumericID()); - this.rawPacket = new PacketPlayOutMount(packetByteBuffer); + this.rawPacket = new PacketPlayOutMount(packetByteBuffer.getInternalSerializer()); } @Override diff --git a/nms/v1_19_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_19_R1/EntitySpawnNMSPacket.java b/nms/v1_19_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_19_R1/EntitySpawnNMSPacket.java index 460e7923..befbd98e 100644 --- a/nms/v1_19_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_19_R1/EntitySpawnNMSPacket.java +++ b/nms/v1_19_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_19_R1/EntitySpawnNMSPacket.java @@ -42,7 +42,7 @@ class EntitySpawnNMSPacket extends VersionNMSPacket { packetByteBuffer.writeShort(0); packetByteBuffer.writeShort(0); - this.rawPacket = new PacketPlayOutSpawnEntity(packetByteBuffer); + this.rawPacket = new PacketPlayOutSpawnEntity(packetByteBuffer.getInternalSerializer()); } @Override diff --git a/nms/v1_19_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_19_R1/EntityTeleportNMSPacket.java b/nms/v1_19_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_19_R1/EntityTeleportNMSPacket.java index c0b92681..ad6aea83 100644 --- a/nms/v1_19_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_19_R1/EntityTeleportNMSPacket.java +++ b/nms/v1_19_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_19_R1/EntityTeleportNMSPacket.java @@ -31,7 +31,7 @@ class EntityTeleportNMSPacket extends VersionNMSPacket { // On ground packetByteBuffer.writeBoolean(false); - this.rawPacket = new PacketPlayOutEntityTeleport(packetByteBuffer); + this.rawPacket = new PacketPlayOutEntityTeleport(packetByteBuffer.getInternalSerializer()); } @Override diff --git a/nms/v1_19_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_19_R1/PacketByteBuffer.java b/nms/v1_19_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_19_R1/PacketByteBuffer.java index 2159f56b..a7cd14c4 100644 --- a/nms/v1_19_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_19_R1/PacketByteBuffer.java +++ b/nms/v1_19_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_19_R1/PacketByteBuffer.java @@ -10,21 +10,43 @@ import net.minecraft.network.PacketDataSerializer; import java.util.UUID; -class PacketByteBuffer extends PacketDataSerializer { +class PacketByteBuffer { private static final PacketByteBuffer INSTANCE = new PacketByteBuffer(); + private final PacketDataSerializer serializer; + static PacketByteBuffer get() { INSTANCE.clear(); return INSTANCE; } private PacketByteBuffer() { - super(Unpooled.buffer()); + this.serializer = new PacketDataSerializer(Unpooled.buffer()); + } + + void writeBoolean(boolean flag) { + serializer.writeBoolean(flag); + } + + void writeByte(int i) { + serializer.writeByte(i); + } + + void writeShort(int i) { + serializer.writeShort(i); + } + + void writeInt(int i) { + serializer.writeInt(i); + } + + void writeDouble(double d) { + serializer.writeDouble(d); } void writeVarInt(int i) { - super.d(i); + serializer.d(i); } void writeVarIntArray(int i1) { @@ -39,17 +61,25 @@ class PacketByteBuffer extends PacketDataSerializer { } void writeUUID(UUID uuid) { - super.a(uuid); + serializer.a(uuid); } void writeDataWatcherEntry(DataWatcherKey key, T value) { - writeByte(key.getIndex()); + serializer.writeByte(key.getIndex()); writeVarInt(key.getSerializerTypeID()); - key.getSerializer().a(this, value); + key.getSerializer().a(serializer, value); } void writeDataWatcherEntriesEnd() { - writeByte(0xFF); + serializer.writeByte(0xFF); + } + + public PacketDataSerializer getInternalSerializer() { + return serializer; + } + + void clear() { + serializer.clear(); } } diff --git a/nms/v1_19_r2/src/main/java/me/filoghost/holographicdisplays/nms/v1_19_R2/EntityDestroyNMSPacket.java b/nms/v1_19_r2/src/main/java/me/filoghost/holographicdisplays/nms/v1_19_R2/EntityDestroyNMSPacket.java index 92bad83e..802b49b5 100644 --- a/nms/v1_19_r2/src/main/java/me/filoghost/holographicdisplays/nms/v1_19_R2/EntityDestroyNMSPacket.java +++ b/nms/v1_19_r2/src/main/java/me/filoghost/holographicdisplays/nms/v1_19_R2/EntityDestroyNMSPacket.java @@ -18,7 +18,7 @@ class EntityDestroyNMSPacket extends VersionNMSPacket { packetByteBuffer.writeVarIntArray(entityID.getNumericID()); - this.rawPacket = new PacketPlayOutEntityDestroy(packetByteBuffer); + this.rawPacket = new PacketPlayOutEntityDestroy(packetByteBuffer.getInternalSerializer()); } EntityDestroyNMSPacket(EntityID entityID1, EntityID entityID2) { @@ -26,7 +26,7 @@ class EntityDestroyNMSPacket extends VersionNMSPacket { packetByteBuffer.writeVarIntArray(entityID1.getNumericID(), entityID2.getNumericID()); - this.rawPacket = new PacketPlayOutEntityDestroy(packetByteBuffer); + this.rawPacket = new PacketPlayOutEntityDestroy(packetByteBuffer.getInternalSerializer()); } @Override diff --git a/nms/v1_19_r2/src/main/java/me/filoghost/holographicdisplays/nms/v1_19_R2/EntityMetadataNMSPacket.java b/nms/v1_19_r2/src/main/java/me/filoghost/holographicdisplays/nms/v1_19_R2/EntityMetadataNMSPacket.java index fbc2d047..4619c3fb 100644 --- a/nms/v1_19_r2/src/main/java/me/filoghost/holographicdisplays/nms/v1_19_R2/EntityMetadataNMSPacket.java +++ b/nms/v1_19_r2/src/main/java/me/filoghost/holographicdisplays/nms/v1_19_R2/EntityMetadataNMSPacket.java @@ -14,7 +14,7 @@ class EntityMetadataNMSPacket extends VersionNMSPacket { private final Packet rawPacket; private EntityMetadataNMSPacket(PacketByteBuffer packetByteBuffer) { - this.rawPacket = new PacketPlayOutEntityMetadata(packetByteBuffer); + this.rawPacket = new PacketPlayOutEntityMetadata(packetByteBuffer.getInternalSerializer()); } @Override diff --git a/nms/v1_19_r2/src/main/java/me/filoghost/holographicdisplays/nms/v1_19_R2/EntityMountNMSPacket.java b/nms/v1_19_r2/src/main/java/me/filoghost/holographicdisplays/nms/v1_19_R2/EntityMountNMSPacket.java index 9ef243d5..adb64f68 100644 --- a/nms/v1_19_r2/src/main/java/me/filoghost/holographicdisplays/nms/v1_19_R2/EntityMountNMSPacket.java +++ b/nms/v1_19_r2/src/main/java/me/filoghost/holographicdisplays/nms/v1_19_R2/EntityMountNMSPacket.java @@ -19,7 +19,7 @@ class EntityMountNMSPacket extends VersionNMSPacket { packetByteBuffer.writeVarInt(vehicleEntityID.getNumericID()); packetByteBuffer.writeVarIntArray(passengerEntityID.getNumericID()); - this.rawPacket = new PacketPlayOutMount(packetByteBuffer); + this.rawPacket = new PacketPlayOutMount(packetByteBuffer.getInternalSerializer()); } @Override diff --git a/nms/v1_19_r2/src/main/java/me/filoghost/holographicdisplays/nms/v1_19_R2/EntitySpawnNMSPacket.java b/nms/v1_19_r2/src/main/java/me/filoghost/holographicdisplays/nms/v1_19_R2/EntitySpawnNMSPacket.java index 09f53cb4..06702ec1 100644 --- a/nms/v1_19_r2/src/main/java/me/filoghost/holographicdisplays/nms/v1_19_R2/EntitySpawnNMSPacket.java +++ b/nms/v1_19_r2/src/main/java/me/filoghost/holographicdisplays/nms/v1_19_R2/EntitySpawnNMSPacket.java @@ -42,7 +42,7 @@ class EntitySpawnNMSPacket extends VersionNMSPacket { packetByteBuffer.writeShort(0); packetByteBuffer.writeShort(0); - this.rawPacket = new PacketPlayOutSpawnEntity(packetByteBuffer); + this.rawPacket = new PacketPlayOutSpawnEntity(packetByteBuffer.getInternalSerializer()); } @Override diff --git a/nms/v1_19_r2/src/main/java/me/filoghost/holographicdisplays/nms/v1_19_R2/EntityTeleportNMSPacket.java b/nms/v1_19_r2/src/main/java/me/filoghost/holographicdisplays/nms/v1_19_R2/EntityTeleportNMSPacket.java index d54931b0..bb4bfa77 100644 --- a/nms/v1_19_r2/src/main/java/me/filoghost/holographicdisplays/nms/v1_19_R2/EntityTeleportNMSPacket.java +++ b/nms/v1_19_r2/src/main/java/me/filoghost/holographicdisplays/nms/v1_19_R2/EntityTeleportNMSPacket.java @@ -31,7 +31,7 @@ class EntityTeleportNMSPacket extends VersionNMSPacket { // On ground packetByteBuffer.writeBoolean(false); - this.rawPacket = new PacketPlayOutEntityTeleport(packetByteBuffer); + this.rawPacket = new PacketPlayOutEntityTeleport(packetByteBuffer.getInternalSerializer()); } @Override diff --git a/nms/v1_19_r2/src/main/java/me/filoghost/holographicdisplays/nms/v1_19_R2/PacketByteBuffer.java b/nms/v1_19_r2/src/main/java/me/filoghost/holographicdisplays/nms/v1_19_R2/PacketByteBuffer.java index 65009fb9..a554a794 100644 --- a/nms/v1_19_r2/src/main/java/me/filoghost/holographicdisplays/nms/v1_19_R2/PacketByteBuffer.java +++ b/nms/v1_19_r2/src/main/java/me/filoghost/holographicdisplays/nms/v1_19_R2/PacketByteBuffer.java @@ -10,21 +10,43 @@ import net.minecraft.network.PacketDataSerializer; import java.util.UUID; -class PacketByteBuffer extends PacketDataSerializer { +class PacketByteBuffer { private static final PacketByteBuffer INSTANCE = new PacketByteBuffer(); + private final PacketDataSerializer serializer; + static PacketByteBuffer get() { INSTANCE.clear(); return INSTANCE; } private PacketByteBuffer() { - super(Unpooled.buffer()); + this.serializer = new PacketDataSerializer(Unpooled.buffer()); + } + + void writeBoolean(boolean flag) { + serializer.writeBoolean(flag); + } + + void writeByte(int i) { + serializer.writeByte(i); + } + + void writeShort(int i) { + serializer.writeShort(i); + } + + void writeInt(int i) { + serializer.writeInt(i); + } + + void writeDouble(double d) { + serializer.writeDouble(d); } void writeVarInt(int i) { - super.d(i); + serializer.d(i); } void writeVarIntArray(int i1) { @@ -39,17 +61,25 @@ class PacketByteBuffer extends PacketDataSerializer { } void writeUUID(UUID uuid) { - super.a(uuid); + serializer.a(uuid); } void writeDataWatcherEntry(DataWatcherKey key, T value) { - writeByte(key.getIndex()); + serializer.writeByte(key.getIndex()); writeVarInt(key.getSerializerTypeID()); - key.getSerializer().a(this, value); + key.getSerializer().a(serializer, value); } void writeDataWatcherEntriesEnd() { - writeByte(0xFF); + serializer.writeByte(0xFF); + } + + public PacketDataSerializer getInternalSerializer() { + return serializer; + } + + void clear() { + serializer.clear(); } } diff --git a/nms/v1_8_r3/src/main/java/me/filoghost/holographicdisplays/nms/v1_8_R3/EntityLivingSpawnNMSPacket.java b/nms/v1_8_r3/src/main/java/me/filoghost/holographicdisplays/nms/v1_8_R3/EntityLivingSpawnNMSPacket.java index 8350fb25..63546a2b 100644 --- a/nms/v1_8_r3/src/main/java/me/filoghost/holographicdisplays/nms/v1_8_R3/EntityLivingSpawnNMSPacket.java +++ b/nms/v1_8_r3/src/main/java/me/filoghost/holographicdisplays/nms/v1_8_R3/EntityLivingSpawnNMSPacket.java @@ -62,7 +62,7 @@ class EntityLivingSpawnNMSPacket extends VersionNMSPacket { // Entries are deserialized and saved into a field which is not used during the re-serialization, set as empty packetByteBuffer.writeDataWatcherEntriesEnd(); - Packet rawPacket = writeData(new PacketPlayOutSpawnEntityLiving(), packetByteBuffer); + Packet rawPacket = packetByteBuffer.writeDataTo(new PacketPlayOutSpawnEntityLiving()); return new Builder(rawPacket, PacketByteBuffer.get()); } diff --git a/nms/v1_8_r3/src/main/java/me/filoghost/holographicdisplays/nms/v1_8_R3/EntityMetadataNMSPacket.java b/nms/v1_8_r3/src/main/java/me/filoghost/holographicdisplays/nms/v1_8_R3/EntityMetadataNMSPacket.java index ef770330..ac144a19 100644 --- a/nms/v1_8_r3/src/main/java/me/filoghost/holographicdisplays/nms/v1_8_R3/EntityMetadataNMSPacket.java +++ b/nms/v1_8_r3/src/main/java/me/filoghost/holographicdisplays/nms/v1_8_R3/EntityMetadataNMSPacket.java @@ -14,7 +14,7 @@ class EntityMetadataNMSPacket extends VersionNMSPacket { private final Packet rawPacket; private EntityMetadataNMSPacket(PacketByteBuffer packetByteBuffer) { - this.rawPacket = writeData(new PacketPlayOutEntityMetadata(), packetByteBuffer); + this.rawPacket = packetByteBuffer.writeDataTo(new PacketPlayOutEntityMetadata()); } @Override diff --git a/nms/v1_8_r3/src/main/java/me/filoghost/holographicdisplays/nms/v1_8_R3/EntityMountNMSPacket.java b/nms/v1_8_r3/src/main/java/me/filoghost/holographicdisplays/nms/v1_8_R3/EntityMountNMSPacket.java index 0858509b..707bc7b0 100644 --- a/nms/v1_8_r3/src/main/java/me/filoghost/holographicdisplays/nms/v1_8_R3/EntityMountNMSPacket.java +++ b/nms/v1_8_r3/src/main/java/me/filoghost/holographicdisplays/nms/v1_8_R3/EntityMountNMSPacket.java @@ -21,7 +21,7 @@ class EntityMountNMSPacket extends VersionNMSPacket { packetByteBuffer.writeByte(0); // Leash - this.rawPacket = writeData(new PacketPlayOutAttachEntity(), packetByteBuffer); + this.rawPacket = packetByteBuffer.writeDataTo(new PacketPlayOutAttachEntity()); } @Override diff --git a/nms/v1_8_r3/src/main/java/me/filoghost/holographicdisplays/nms/v1_8_R3/EntitySpawnNMSPacket.java b/nms/v1_8_r3/src/main/java/me/filoghost/holographicdisplays/nms/v1_8_R3/EntitySpawnNMSPacket.java index 5042a3c0..00a14399 100644 --- a/nms/v1_8_r3/src/main/java/me/filoghost/holographicdisplays/nms/v1_8_R3/EntitySpawnNMSPacket.java +++ b/nms/v1_8_r3/src/main/java/me/filoghost/holographicdisplays/nms/v1_8_R3/EntitySpawnNMSPacket.java @@ -42,7 +42,7 @@ class EntitySpawnNMSPacket extends VersionNMSPacket { packetByteBuffer.writeShort(0); packetByteBuffer.writeShort(0); - this.rawPacket = writeData(new PacketPlayOutSpawnEntity(), packetByteBuffer); + this.rawPacket = packetByteBuffer.writeDataTo(new PacketPlayOutSpawnEntity()); } @Override diff --git a/nms/v1_8_r3/src/main/java/me/filoghost/holographicdisplays/nms/v1_8_R3/EntityTeleportNMSPacket.java b/nms/v1_8_r3/src/main/java/me/filoghost/holographicdisplays/nms/v1_8_R3/EntityTeleportNMSPacket.java index 7b5512eb..51892201 100644 --- a/nms/v1_8_r3/src/main/java/me/filoghost/holographicdisplays/nms/v1_8_R3/EntityTeleportNMSPacket.java +++ b/nms/v1_8_r3/src/main/java/me/filoghost/holographicdisplays/nms/v1_8_R3/EntityTeleportNMSPacket.java @@ -32,7 +32,7 @@ class EntityTeleportNMSPacket extends VersionNMSPacket { // On ground packetByteBuffer.writeBoolean(false); - this.rawPacket = writeData(new PacketPlayOutEntityTeleport(), packetByteBuffer); + this.rawPacket = packetByteBuffer.writeDataTo(new PacketPlayOutEntityTeleport()); } @Override diff --git a/nms/v1_8_r3/src/main/java/me/filoghost/holographicdisplays/nms/v1_8_R3/PacketByteBuffer.java b/nms/v1_8_r3/src/main/java/me/filoghost/holographicdisplays/nms/v1_8_R3/PacketByteBuffer.java index 6b5d8845..83841763 100644 --- a/nms/v1_8_r3/src/main/java/me/filoghost/holographicdisplays/nms/v1_8_R3/PacketByteBuffer.java +++ b/nms/v1_8_r3/src/main/java/me/filoghost/holographicdisplays/nms/v1_8_R3/PacketByteBuffer.java @@ -7,45 +7,88 @@ package me.filoghost.holographicdisplays.nms.v1_8_R3; import io.netty.buffer.Unpooled; import net.minecraft.server.v1_8_R3.ItemStack; +import net.minecraft.server.v1_8_R3.Packet; import net.minecraft.server.v1_8_R3.PacketDataSerializer; -class PacketByteBuffer extends PacketDataSerializer { +import java.io.IOException; + +class PacketByteBuffer { private static final PacketByteBuffer INSTANCE = new PacketByteBuffer(); + private final PacketDataSerializer serializer; + static PacketByteBuffer get() { INSTANCE.clear(); return INSTANCE; } private PacketByteBuffer() { - super(Unpooled.buffer()); + this.serializer = new PacketDataSerializer(Unpooled.buffer()); + } + + int readableBytes() { + return serializer.readableBytes(); + } + + void readBytes(byte[] bytes) { + serializer.readBytes(bytes); + } + + void writeBoolean(boolean flag) { + serializer.writeBoolean(flag); } void writeByte(byte b) { - super.writeByte(b); + serializer.writeByte(b); + } + + void writeByte(int i) { + serializer.writeByte(i); + } + + void writeShort(int i) { + serializer.writeShort(i); + } + + void writeInt(int i) { + serializer.writeInt(i); } void writeVarInt(int i) { - super.b(i); + serializer.b(i); } void writeString(String s) { - super.a(s); + serializer.a(s); } void writeItemStack(ItemStack itemStack) { - super.a(itemStack); + serializer.a(itemStack); } void writeDataWatcherEntry(DataWatcherKey key, T value) { int typeIDAndIndex = (key.getSerializer().getTypeID() << 5 | key.getIndex() & 0x1F) & 0xFF; - writeByte(typeIDAndIndex); + serializer.writeByte(typeIDAndIndex); key.getSerializer().write(this, value); } void writeDataWatcherEntriesEnd() { - writeByte(0x7F); + serializer.writeByte(0x7F); + } + + void clear() { + serializer.clear(); + } + + > T writeDataTo(T packet) { + try { + packet.a(serializer); + return packet; + } catch (IOException e) { + // Never thrown by the implementations + throw new RuntimeException(e); + } } } diff --git a/nms/v1_8_r3/src/main/java/me/filoghost/holographicdisplays/nms/v1_8_R3/VersionNMSPacket.java b/nms/v1_8_r3/src/main/java/me/filoghost/holographicdisplays/nms/v1_8_R3/VersionNMSPacket.java index d35a8880..fda3b8bc 100644 --- a/nms/v1_8_r3/src/main/java/me/filoghost/holographicdisplays/nms/v1_8_R3/VersionNMSPacket.java +++ b/nms/v1_8_r3/src/main/java/me/filoghost/holographicdisplays/nms/v1_8_R3/VersionNMSPacket.java @@ -10,8 +10,6 @@ import net.minecraft.server.v1_8_R3.Packet; import org.bukkit.craftbukkit.v1_8_R3.entity.CraftPlayer; import org.bukkit.entity.Player; -import java.io.IOException; - abstract class VersionNMSPacket implements PacketGroup { @Override @@ -21,14 +19,4 @@ abstract class VersionNMSPacket implements PacketGroup { abstract Packet getRawPacket(); - protected static > T writeData(T packet, PacketByteBuffer packetByteBuffer) { - try { - packet.a(packetByteBuffer); - return packet; - } catch (IOException e) { - // Never thrown by the implementations - throw new RuntimeException(e); - } - } - } diff --git a/nms/v1_9_r2/src/main/java/me/filoghost/holographicdisplays/nms/v1_9_R2/EntityLivingSpawnNMSPacket.java b/nms/v1_9_r2/src/main/java/me/filoghost/holographicdisplays/nms/v1_9_R2/EntityLivingSpawnNMSPacket.java index e9c3a5f4..a3d698fc 100644 --- a/nms/v1_9_r2/src/main/java/me/filoghost/holographicdisplays/nms/v1_9_R2/EntityLivingSpawnNMSPacket.java +++ b/nms/v1_9_r2/src/main/java/me/filoghost/holographicdisplays/nms/v1_9_R2/EntityLivingSpawnNMSPacket.java @@ -62,7 +62,7 @@ class EntityLivingSpawnNMSPacket extends VersionNMSPacket { // Entries are deserialized and saved into a field which is not used during the re-serialization, set as empty packetByteBuffer.writeDataWatcherEntriesEnd(); - Packet rawPacket = writeData(new PacketPlayOutSpawnEntityLiving(), packetByteBuffer); + Packet rawPacket = packetByteBuffer.writeDataTo(new PacketPlayOutSpawnEntityLiving()); return new Builder(rawPacket, PacketByteBuffer.get()); } diff --git a/nms/v1_9_r2/src/main/java/me/filoghost/holographicdisplays/nms/v1_9_R2/EntityMetadataNMSPacket.java b/nms/v1_9_r2/src/main/java/me/filoghost/holographicdisplays/nms/v1_9_R2/EntityMetadataNMSPacket.java index 673c5630..dec4918b 100644 --- a/nms/v1_9_r2/src/main/java/me/filoghost/holographicdisplays/nms/v1_9_R2/EntityMetadataNMSPacket.java +++ b/nms/v1_9_r2/src/main/java/me/filoghost/holographicdisplays/nms/v1_9_R2/EntityMetadataNMSPacket.java @@ -14,7 +14,7 @@ class EntityMetadataNMSPacket extends VersionNMSPacket { private final Packet rawPacket; private EntityMetadataNMSPacket(PacketByteBuffer packetByteBuffer) { - this.rawPacket = writeData(new PacketPlayOutEntityMetadata(), packetByteBuffer); + this.rawPacket = packetByteBuffer.writeDataTo(new PacketPlayOutEntityMetadata()); } @Override diff --git a/nms/v1_9_r2/src/main/java/me/filoghost/holographicdisplays/nms/v1_9_R2/EntityMountNMSPacket.java b/nms/v1_9_r2/src/main/java/me/filoghost/holographicdisplays/nms/v1_9_R2/EntityMountNMSPacket.java index 10c420c0..dd5810d0 100644 --- a/nms/v1_9_r2/src/main/java/me/filoghost/holographicdisplays/nms/v1_9_R2/EntityMountNMSPacket.java +++ b/nms/v1_9_r2/src/main/java/me/filoghost/holographicdisplays/nms/v1_9_R2/EntityMountNMSPacket.java @@ -19,7 +19,7 @@ class EntityMountNMSPacket extends VersionNMSPacket { packetByteBuffer.writeVarInt(vehicleEntityID.getNumericID()); packetByteBuffer.writeVarIntArray(passengerEntityID.getNumericID()); - this.rawPacket = writeData(new PacketPlayOutMount(), packetByteBuffer); + this.rawPacket = packetByteBuffer.writeDataTo(new PacketPlayOutMount()); } @Override diff --git a/nms/v1_9_r2/src/main/java/me/filoghost/holographicdisplays/nms/v1_9_R2/EntitySpawnNMSPacket.java b/nms/v1_9_r2/src/main/java/me/filoghost/holographicdisplays/nms/v1_9_R2/EntitySpawnNMSPacket.java index 4edd3fb6..d457c6b1 100644 --- a/nms/v1_9_r2/src/main/java/me/filoghost/holographicdisplays/nms/v1_9_R2/EntitySpawnNMSPacket.java +++ b/nms/v1_9_r2/src/main/java/me/filoghost/holographicdisplays/nms/v1_9_R2/EntitySpawnNMSPacket.java @@ -42,7 +42,7 @@ class EntitySpawnNMSPacket extends VersionNMSPacket { packetByteBuffer.writeShort(0); packetByteBuffer.writeShort(0); - this.rawPacket = writeData(new PacketPlayOutSpawnEntity(), packetByteBuffer); + this.rawPacket = packetByteBuffer.writeDataTo(new PacketPlayOutSpawnEntity()); } @Override diff --git a/nms/v1_9_r2/src/main/java/me/filoghost/holographicdisplays/nms/v1_9_R2/EntityTeleportNMSPacket.java b/nms/v1_9_r2/src/main/java/me/filoghost/holographicdisplays/nms/v1_9_R2/EntityTeleportNMSPacket.java index 18cbdcda..11496a5a 100644 --- a/nms/v1_9_r2/src/main/java/me/filoghost/holographicdisplays/nms/v1_9_R2/EntityTeleportNMSPacket.java +++ b/nms/v1_9_r2/src/main/java/me/filoghost/holographicdisplays/nms/v1_9_R2/EntityTeleportNMSPacket.java @@ -31,7 +31,7 @@ class EntityTeleportNMSPacket extends VersionNMSPacket { // On ground packetByteBuffer.writeBoolean(false); - this.rawPacket = writeData(new PacketPlayOutEntityTeleport(), packetByteBuffer); + this.rawPacket = packetByteBuffer.writeDataTo(new PacketPlayOutEntityTeleport()); } @Override diff --git a/nms/v1_9_r2/src/main/java/me/filoghost/holographicdisplays/nms/v1_9_R2/PacketByteBuffer.java b/nms/v1_9_r2/src/main/java/me/filoghost/holographicdisplays/nms/v1_9_R2/PacketByteBuffer.java index 2c998c2f..e7d8bb6c 100644 --- a/nms/v1_9_r2/src/main/java/me/filoghost/holographicdisplays/nms/v1_9_R2/PacketByteBuffer.java +++ b/nms/v1_9_r2/src/main/java/me/filoghost/holographicdisplays/nms/v1_9_R2/PacketByteBuffer.java @@ -6,25 +6,57 @@ package me.filoghost.holographicdisplays.nms.v1_9_R2; import io.netty.buffer.Unpooled; +import net.minecraft.server.v1_9_R2.Packet; import net.minecraft.server.v1_9_R2.PacketDataSerializer; +import java.io.IOException; import java.util.UUID; -class PacketByteBuffer extends PacketDataSerializer { +class PacketByteBuffer { private static final PacketByteBuffer INSTANCE = new PacketByteBuffer(); + private final PacketDataSerializer serializer; + static PacketByteBuffer get() { INSTANCE.clear(); return INSTANCE; } private PacketByteBuffer() { - super(Unpooled.buffer()); + this.serializer = new PacketDataSerializer(Unpooled.buffer()); + } + + int readableBytes() { + return serializer.readableBytes(); + } + + void readBytes(byte[] bytes) { + serializer.readBytes(bytes); + } + + void writeBoolean(boolean flag) { + serializer.writeBoolean(flag); + } + + void writeByte(int i) { + serializer.writeByte(i); + } + + void writeShort(int i) { + serializer.writeShort(i); + } + + void writeInt(int i) { + serializer.writeInt(i); + } + + void writeDouble(double d) { + serializer.writeDouble(d); } void writeVarInt(int i) { - super.d(i); + serializer.d(i); } void writeVarIntArray(int i1) { @@ -33,17 +65,31 @@ class PacketByteBuffer extends PacketDataSerializer { } void writeUUID(UUID uuid) { - super.a(uuid); + serializer.a(uuid); } void writeDataWatcherEntry(DataWatcherKey key, T value) { - writeByte(key.getIndex()); + serializer.writeByte(key.getIndex()); writeVarInt(key.getSerializerTypeID()); - key.getSerializer().a(this, value); + key.getSerializer().a(serializer, value); } void writeDataWatcherEntriesEnd() { - writeByte(0xFF); + serializer.writeByte(0xFF); + } + + void clear() { + serializer.clear(); + } + + > T writeDataTo(T packet) { + try { + packet.a(serializer); + return packet; + } catch (IOException e) { + // Never thrown by the implementations + throw new RuntimeException(e); + } } } diff --git a/nms/v1_9_r2/src/main/java/me/filoghost/holographicdisplays/nms/v1_9_R2/VersionNMSPacket.java b/nms/v1_9_r2/src/main/java/me/filoghost/holographicdisplays/nms/v1_9_R2/VersionNMSPacket.java index b476ee05..ef59c2e9 100644 --- a/nms/v1_9_r2/src/main/java/me/filoghost/holographicdisplays/nms/v1_9_R2/VersionNMSPacket.java +++ b/nms/v1_9_r2/src/main/java/me/filoghost/holographicdisplays/nms/v1_9_R2/VersionNMSPacket.java @@ -10,8 +10,6 @@ import net.minecraft.server.v1_9_R2.Packet; import org.bukkit.craftbukkit.v1_9_R2.entity.CraftPlayer; import org.bukkit.entity.Player; -import java.io.IOException; - abstract class VersionNMSPacket implements PacketGroup { @Override @@ -21,14 +19,4 @@ abstract class VersionNMSPacket implements PacketGroup { abstract Packet getRawPacket(); - protected static > T writeData(T packet, PacketByteBuffer packetByteBuffer) { - try { - packet.a(packetByteBuffer); - return packet; - } catch (IOException e) { - // Never thrown by the implementations - throw new RuntimeException(e); - } - } - }