aboutsummaryrefslogtreecommitdiffhomepage
path: root/patches/api/0187-Add-Raw-Byte-ItemStack-Serialization.patch
diff options
context:
space:
mode:
Diffstat (limited to 'patches/api/0187-Add-Raw-Byte-ItemStack-Serialization.patch')
-rw-r--r--patches/api/0187-Add-Raw-Byte-ItemStack-Serialization.patch56
1 files changed, 56 insertions, 0 deletions
diff --git a/patches/api/0187-Add-Raw-Byte-ItemStack-Serialization.patch b/patches/api/0187-Add-Raw-Byte-ItemStack-Serialization.patch
new file mode 100644
index 0000000000..68a57597a7
--- /dev/null
+++ b/patches/api/0187-Add-Raw-Byte-ItemStack-Serialization.patch
@@ -0,0 +1,56 @@
+From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
+From: Mariell Hoversholm <[email protected]>
+Date: Thu, 30 Apr 2020 16:56:31 +0200
+Subject: [PATCH] Add Raw Byte ItemStack Serialization
+
+Serializes using NBT which is safer for server data migrations than bukkits format.
+
+diff --git a/src/main/java/org/bukkit/UnsafeValues.java b/src/main/java/org/bukkit/UnsafeValues.java
+index 4ac6f5488eb988486ee40473b9b0db84b5fe35c4..77a06e58f86f908916e68e80ce365ae25884e5a2 100644
+--- a/src/main/java/org/bukkit/UnsafeValues.java
++++ b/src/main/java/org/bukkit/UnsafeValues.java
+@@ -154,5 +154,9 @@ public interface UnsafeValues {
+ default com.destroystokyo.paper.util.VersionFetcher getVersionFetcher() {
+ return new com.destroystokyo.paper.util.VersionFetcher.DummyVersionFetcher();
+ }
++
++ byte[] serializeItem(ItemStack item);
++
++ ItemStack deserializeItem(byte[] data);
+ // Paper end
+ }
+diff --git a/src/main/java/org/bukkit/inventory/ItemStack.java b/src/main/java/org/bukkit/inventory/ItemStack.java
+index 276cfd52817115981fe7dc46363278f8b8c5aee3..e82eeadc7cb53572351670761c4e592a33345c6b 100644
+--- a/src/main/java/org/bukkit/inventory/ItemStack.java
++++ b/src/main/java/org/bukkit/inventory/ItemStack.java
+@@ -653,6 +653,30 @@ public class ItemStack implements Cloneable, ConfigurationSerializable, Translat
+ return Bukkit.getServer().getItemFactory().ensureServerConversions(this);
+ }
+
++ /**
++ * Deserializes this itemstack from raw NBT bytes. NBT is safer for data migrations as it will
++ * use the built in data converter instead of bukkits dangerous serialization system.
++ *
++ * This expects that the DataVersion was stored on the root of the Compound, as saved from
++ * the {@link #serializeAsBytes()} API returned.
++ * @param bytes bytes representing an item in NBT
++ * @return ItemStack migrated to this version of Minecraft if needed.
++ */
++ @NotNull
++ public static ItemStack deserializeBytes(@NotNull byte[] bytes) {
++ return org.bukkit.Bukkit.getUnsafe().deserializeItem(bytes);
++ }
++
++ /**
++ * Serializes this itemstack to raw bytes in NBT. NBT is safer for data migrations as it will
++ * use the built in data converter instead of bukkits dangerous serialization system.
++ * @return bytes representing this item in NBT.
++ */
++ @NotNull
++ public byte[] serializeAsBytes() {
++ return org.bukkit.Bukkit.getUnsafe().serializeItem(this);
++ }
++
+ /**
+ * Gets the Display name as seen in the Client.
+ * Currently the server only supports the English language. To override this,