From 868602a559cf697f9318d9f266f4d9a74339fe9a Mon Sep 17 00:00:00 2001 From: "Dylan K. Taylor" Date: Wed, 29 Mar 2017 13:55:10 +0100 Subject: [PATCH] Add __clone to CompoundTag and ListTag, fixed issues with items sharing the same NBT tag objects --- src/pocketmine/nbt/tag/CompoundTag.php | 8 ++++++++ src/pocketmine/nbt/tag/ListTag.php | 8 ++++++++ 2 files changed, 16 insertions(+) diff --git a/src/pocketmine/nbt/tag/CompoundTag.php b/src/pocketmine/nbt/tag/CompoundTag.php index 99f384a4e..45ab5bf6d 100644 --- a/src/pocketmine/nbt/tag/CompoundTag.php +++ b/src/pocketmine/nbt/tag/CompoundTag.php @@ -111,4 +111,12 @@ class CompoundTag extends NamedTag implements \ArrayAccess{ } return $str . "}"; } + + public function __clone(){ + foreach($this as $key => $tag){ + if($tag instanceof Tag){ + $this->{$key} = clone $tag; + } + } + } } \ No newline at end of file diff --git a/src/pocketmine/nbt/tag/ListTag.php b/src/pocketmine/nbt/tag/ListTag.php index 3fed630be..361db14d6 100644 --- a/src/pocketmine/nbt/tag/ListTag.php +++ b/src/pocketmine/nbt/tag/ListTag.php @@ -220,4 +220,12 @@ class ListTag extends NamedTag implements \ArrayAccess, \Countable{ } return $str . "}"; } + + public function __clone(){ + foreach($this as $key => $tag){ + if($tag instanceof Tag){ + $this->{$key} = clone $tag; + } + } + } }