mirror of
https://github.com/PaperMC/Paper.git
synced 2024-12-11 09:23:42 +01:00
bc127ea819
Upstream has released updates that appear to apply and compile correctly. This update has not been tested by PaperMC and as with ANY update, please do your own testing Bukkit Changes: eec4aab0 SPIGOT-6657: Add getPlayer to SheepDyeWoolEvent 205213c6 SPIGOT-6656: CauldronLevelChangeEvent is not fired correctly when dripstone fills the cauldron CraftBukkit Changes: b8c522d5 SPIGOT-6657: Add getPlayer to SheepDyeWoolEvent f04a77dc SPIGOT-6656: CauldronLevelChangeEvent is not fired correctly when dripstone fills the cauldron d1dbcebc SPIGOT-6653: Canceling snow bucket placement removes snow from bucket 4f34a67b #891: Fix scheduler task ID overflow and duplication issues Spigot Changes: d03d7f12 BUILDTOOLS-604: Rebuild patches
58 lines
2.8 KiB
Diff
58 lines
2.8 KiB
Diff
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
|
|
From: Mariell Hoversholm <proximyst@proximyst.com>
|
|
Date: Thu, 30 Apr 2020 16:56:54 +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/craftbukkit/util/CraftMagicNumbers.java b/src/main/java/org/bukkit/craftbukkit/util/CraftMagicNumbers.java
|
|
index f8cb210390958ddba9f9685f2ec1f8bb91690162..6b79b1ea43b713105f37de517019c033477f9835 100644
|
|
--- a/src/main/java/org/bukkit/craftbukkit/util/CraftMagicNumbers.java
|
|
+++ b/src/main/java/org/bukkit/craftbukkit/util/CraftMagicNumbers.java
|
|
@@ -378,6 +378,46 @@ public final class CraftMagicNumbers implements UnsafeValues {
|
|
public boolean isSupportedApiVersion(String apiVersion) {
|
|
return apiVersion != null && SUPPORTED_API.contains(apiVersion);
|
|
}
|
|
+
|
|
+ @Override
|
|
+ public byte[] serializeItem(ItemStack item) {
|
|
+ Preconditions.checkNotNull(item, "null cannot be serialized");
|
|
+ Preconditions.checkArgument(item.getType() != Material.AIR, "air cannot be serialized");
|
|
+
|
|
+ java.io.ByteArrayOutputStream outputStream = new java.io.ByteArrayOutputStream();
|
|
+ CompoundTag compound = (item instanceof CraftItemStack ? ((CraftItemStack) item).handle : CraftItemStack.asNMSCopy(item)).save(new CompoundTag());
|
|
+ compound.putInt("DataVersion", getDataVersion());
|
|
+ try {
|
|
+ net.minecraft.nbt.NbtIo.writeCompressed(
|
|
+ compound,
|
|
+ outputStream
|
|
+ );
|
|
+ } catch (IOException ex) {
|
|
+ throw new RuntimeException(ex);
|
|
+ }
|
|
+
|
|
+ return outputStream.toByteArray();
|
|
+ }
|
|
+
|
|
+ @Override
|
|
+ public ItemStack deserializeItem(byte[] data) {
|
|
+ Preconditions.checkNotNull(data, "null cannot be deserialized");
|
|
+ Preconditions.checkArgument(data.length > 0, "cannot deserialize nothing");
|
|
+
|
|
+ try {
|
|
+ CompoundTag compound = net.minecraft.nbt.NbtIo.readCompressed(
|
|
+ new java.io.ByteArrayInputStream(data)
|
|
+ );
|
|
+ int dataVersion = compound.getInt("DataVersion");
|
|
+
|
|
+ Preconditions.checkArgument(dataVersion <= getDataVersion(), "Newer version! Server downgrades are not supported!");
|
|
+ Dynamic<Tag> converted = DataFixers.getDataFixer().update(References.ITEM_STACK, new Dynamic<Tag>(NbtOps.INSTANCE, compound), dataVersion, getDataVersion());
|
|
+ return CraftItemStack.asCraftMirror(net.minecraft.world.item.ItemStack.of((CompoundTag) converted.getValue()));
|
|
+ } catch (IOException ex) {
|
|
+ com.destroystokyo.paper.util.SneakyThrow.sneaky(ex);
|
|
+ throw new RuntimeException();
|
|
+ }
|
|
+ }
|
|
// Paper end
|
|
|
|
/**
|