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-03-03 23:05:34 +01:00
|
|
|
index 7d3d32679bdfe373d89a28c3616da5069640d1bb..9137d6d56386111dfd072859df84e533580ee294 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-20 23:13:41 +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);
|
|
|
|
}
|
2024-01-21 13:56:22 +01:00
|
|
|
// Paper end - Add API for CanPlaceOn and CanDestroy NBT values
|
2023-08-22 06:59:31 +02:00
|
|
|
- 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-26 20:17:06 +01:00
|
|
|
@@ -1393,7 +1395,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
|
|
|
}
|