2022-09-18 06:06:53 +02:00
|
|
|
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
|
|
|
|
From: Nex <nex@bits.team>
|
|
|
|
Date: Thu, 24 Feb 2022 16:28:07 +0100
|
|
|
|
Subject: [PATCH] Added byte array serialization/deserialization for
|
|
|
|
PersistentDataContainers
|
|
|
|
|
|
|
|
|
|
|
|
diff --git a/src/main/java/org/bukkit/craftbukkit/persistence/CraftPersistentDataContainer.java b/src/main/java/org/bukkit/craftbukkit/persistence/CraftPersistentDataContainer.java
|
2023-12-08 20:00:39 +01:00
|
|
|
index 43545bac94fbf118a982b654fbe0d6afc6e25897..416d2ca909d30e267fb97082a0aaac90444510de 100644
|
2022-09-18 06:06:53 +02:00
|
|
|
--- a/src/main/java/org/bukkit/craftbukkit/persistence/CraftPersistentDataContainer.java
|
|
|
|
+++ b/src/main/java/org/bukkit/craftbukkit/persistence/CraftPersistentDataContainer.java
|
2023-12-08 20:00:39 +01:00
|
|
|
@@ -180,4 +180,27 @@ public class CraftPersistentDataContainer implements PersistentDataContainer {
|
|
|
|
this.customDataTags.clear();
|
2022-09-18 06:06:53 +02:00
|
|
|
}
|
2023-12-08 20:00:39 +01:00
|
|
|
// Paper end
|
2022-09-18 06:06:53 +02:00
|
|
|
+
|
2023-12-08 20:00:39 +01:00
|
|
|
+ // Paper start - byte array serialization
|
2022-09-18 06:06:53 +02:00
|
|
|
+ @Override
|
|
|
|
+ public byte[] serializeToBytes() throws java.io.IOException {
|
2023-12-08 20:00:39 +01:00
|
|
|
+ final net.minecraft.nbt.CompoundTag root = this.toTagCompound();
|
|
|
|
+ final java.io.ByteArrayOutputStream byteArrayOutput = new java.io.ByteArrayOutputStream();
|
|
|
|
+ try (final java.io.DataOutputStream dataOutput = new java.io.DataOutputStream(byteArrayOutput)) {
|
2022-09-18 06:06:53 +02:00
|
|
|
+ net.minecraft.nbt.NbtIo.write(root, dataOutput);
|
|
|
|
+ return byteArrayOutput.toByteArray();
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ @Override
|
2023-12-08 20:00:39 +01:00
|
|
|
+ public void readFromBytes(final byte[] bytes, final boolean clear) throws java.io.IOException {
|
2022-09-18 06:06:53 +02:00
|
|
|
+ if (clear) {
|
|
|
|
+ this.clear();
|
|
|
|
+ }
|
2023-12-08 20:00:39 +01:00
|
|
|
+ try (final java.io.DataInputStream dataInput = new java.io.DataInputStream(new java.io.ByteArrayInputStream(bytes))) {
|
|
|
|
+ final net.minecraft.nbt.CompoundTag compound = net.minecraft.nbt.NbtIo.read(dataInput);
|
2022-09-18 06:06:53 +02:00
|
|
|
+ this.putAll(compound);
|
|
|
|
+ }
|
|
|
|
+ }
|
2023-12-08 20:00:39 +01:00
|
|
|
+ // Paper end - byte array serialization
|
2022-09-18 06:06:53 +02:00
|
|
|
}
|