2023-08-22 06:59:31 +02:00
|
|
|
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
|
|
|
|
From: SoSeDiK <mrsosedik@gmail.com>
|
|
|
|
Date: Thu, 26 May 2022 03:30:05 +0300
|
|
|
|
Subject: [PATCH] Deep clone unhandled nbt tags
|
|
|
|
|
|
|
|
|
|
|
|
diff --git a/src/main/java/org/bukkit/craftbukkit/inventory/CraftMetaItem.java b/src/main/java/org/bukkit/craftbukkit/inventory/CraftMetaItem.java
|
2024-01-19 22:13:42 +01:00
|
|
|
index b7c0c9a40dac3e828f880ef928ca34206a898cb9..678cebb12e290a9a3967177d97a67bebb9116104 100644
|
2023-08-22 06:59:31 +02:00
|
|
|
--- a/src/main/java/org/bukkit/craftbukkit/inventory/CraftMetaItem.java
|
|
|
|
+++ b/src/main/java/org/bukkit/craftbukkit/inventory/CraftMetaItem.java
|
2024-01-14 10:46:04 +01:00
|
|
|
@@ -305,7 +305,7 @@ class CraftMetaItem implements ItemMeta, Damageable, Repairable, BlockDataMeta {
|
2023-08-22 06:59:31 +02:00
|
|
|
private static final CraftPersistentDataTypeRegistry DATA_TYPE_REGISTRY = new CraftPersistentDataTypeRegistry();
|
|
|
|
|
|
|
|
private CompoundTag internalTag;
|
|
|
|
- final Map<String, Tag> unhandledTags = new TreeMap<String, Tag>(); // Visible for testing only // Paper
|
2024-01-19 22:13:42 +01:00
|
|
|
+ Map<String, Tag> unhandledTags = new TreeMap<String, Tag>(); // Visible for testing only // Paper & Deep clone unhandled nbt tags; remove final
|
2023-08-22 06:59:31 +02:00
|
|
|
private CraftPersistentDataContainer persistentDataContainer = new CraftPersistentDataContainer(CraftMetaItem.DATA_TYPE_REGISTRY);
|
|
|
|
|
|
|
|
private int version = CraftMagicNumbers.INSTANCE.getDataVersion(); // Internal use only
|
2024-01-14 10:46:04 +01:00
|
|
|
@@ -346,8 +346,10 @@ class CraftMetaItem implements ItemMeta, Damageable, Repairable, BlockDataMeta {
|
2023-08-22 06:59:31 +02:00
|
|
|
this.destroyableKeys = new java.util.HashSet<>(meta.destroyableKeys);
|
|
|
|
}
|
|
|
|
// Paper end
|
|
|
|
- this.unhandledTags.putAll(meta.unhandledTags);
|
|
|
|
- this.persistentDataContainer.putAll(meta.persistentDataContainer.getRaw());
|
|
|
|
+ // Paper start - Deep clone unhandled nbt tags
|
|
|
|
+ meta.unhandledTags.forEach((key, tag) -> this.unhandledTags.put(key, tag.copy()));
|
|
|
|
+ this.persistentDataContainer.putAll(meta.persistentDataContainer.getTagsCloned());
|
2024-01-14 16:31:39 +01:00
|
|
|
+ // Paper end - Deep clone unhandled nbt tags
|
2023-08-22 06:59:31 +02:00
|
|
|
|
|
|
|
this.internalTag = meta.internalTag;
|
|
|
|
if (this.internalTag != null) {
|
2024-01-14 10:46:04 +01:00
|
|
|
@@ -1386,7 +1388,11 @@ class CraftMetaItem implements ItemMeta, Damageable, Repairable, BlockDataMeta {
|
2023-08-22 06:59:31 +02:00
|
|
|
if (this.hasAttributeModifiers()) {
|
|
|
|
clone.attributeModifiers = LinkedHashMultimap.create(this.attributeModifiers);
|
|
|
|
}
|
|
|
|
- clone.persistentDataContainer = new CraftPersistentDataContainer(this.persistentDataContainer.getRaw(), CraftMetaItem.DATA_TYPE_REGISTRY);
|
|
|
|
+ // Paper start - Deep clone unhandled nbt tags
|
|
|
|
+ clone.persistentDataContainer = new CraftPersistentDataContainer(this.persistentDataContainer.getTagsCloned(), CraftMetaItem.DATA_TYPE_REGISTRY);
|
|
|
|
+ clone.unhandledTags = new TreeMap<>(this.unhandledTags);
|
|
|
|
+ clone.unhandledTags.replaceAll((key, tag) -> tag.copy());
|
|
|
|
+ // Paper end - Deep clone unhandled nbt tags
|
|
|
|
clone.hideFlag = this.hideFlag;
|
|
|
|
clone.unbreakable = this.unbreakable;
|
|
|
|
clone.damage = this.damage;
|
|
|
|
diff --git a/src/main/java/org/bukkit/craftbukkit/persistence/CraftPersistentDataContainer.java b/src/main/java/org/bukkit/craftbukkit/persistence/CraftPersistentDataContainer.java
|
2024-01-14 10:46:04 +01:00
|
|
|
index 5a4e7e7150b7c137b077e0b393f17ed35b5aec34..f55fdd57ced259ad5a95878840e98ffaa3db2e05 100644
|
2023-08-22 06:59:31 +02:00
|
|
|
--- a/src/main/java/org/bukkit/craftbukkit/persistence/CraftPersistentDataContainer.java
|
|
|
|
+++ b/src/main/java/org/bukkit/craftbukkit/persistence/CraftPersistentDataContainer.java
|
2024-01-14 10:46:04 +01:00
|
|
|
@@ -207,4 +207,12 @@ public class CraftPersistentDataContainer implements PersistentDataContainer {
|
2023-08-22 06:59:31 +02:00
|
|
|
}
|
|
|
|
}
|
2023-12-08 20:00:39 +01:00
|
|
|
// Paper end - byte array serialization
|
2023-08-22 06:59:31 +02:00
|
|
|
+
|
2023-12-08 20:00:39 +01:00
|
|
|
+ // Paper start - deep clone tags
|
2023-08-22 06:59:31 +02:00
|
|
|
+ public Map<String, Tag> getTagsCloned() {
|
|
|
|
+ final Map<String, Tag> tags = new HashMap<>();
|
|
|
|
+ this.customDataTags.forEach((key, tag) -> tags.put(key, tag.copy()));
|
|
|
|
+ return tags;
|
|
|
|
+ }
|
2023-12-08 20:00:39 +01:00
|
|
|
+ // Paper end - deep clone tags
|
2023-08-22 06:59:31 +02:00
|
|
|
}
|