From fc9a61859ac375c2e419b842f412ff45b266f398 Mon Sep 17 00:00:00 2001 From: "Dylan K. Taylor" Date: Sun, 3 Mar 2019 12:36:46 +0000 Subject: [PATCH] Item: remove misleading methods & premature optimization --- src/pocketmine/item/Item.php | 34 +++++----------------------------- 1 file changed, 5 insertions(+), 29 deletions(-) diff --git a/src/pocketmine/item/Item.php b/src/pocketmine/item/Item.php index 37236f615..bb2f0b11a 100644 --- a/src/pocketmine/item/Item.php +++ b/src/pocketmine/item/Item.php @@ -61,32 +61,6 @@ class Item implements ItemIds, \JsonSerializable{ public const TAG_DISPLAY_NAME = "Name"; public const TAG_DISPLAY_LORE = "Lore"; - - /** @var LittleEndianNbtSerializer */ - private static $cachedParser = null; - - /** - * @param string $tag - * - * @return CompoundTag - * @throws NbtDataException - */ - private static function parseCompoundTag(string $tag) : CompoundTag{ - if(self::$cachedParser === null){ - self::$cachedParser = new LittleEndianNbtSerializer(); - } - - return self::$cachedParser->read($tag); - } - - private static function writeCompoundTag(CompoundTag $tag) : string{ - if(self::$cachedParser === null){ - self::$cachedParser = new LittleEndianNbtSerializer(); - } - - return self::$cachedParser->write($tag); - } - /** * Returns a new Item instance with the specified ID, damage, count and NBT. * @@ -841,7 +815,7 @@ class Item implements ItemIds, \JsonSerializable{ * @return string */ final public function __toString() : string{ - return "Item " . $this->name . " (" . $this->id . ":" . ($this->hasAnyDamageValue() ? "?" : $this->getMeta()) . ")x" . $this->count . ($this->hasNamedTag() ? " tags:" . base64_encode(self::writeCompoundTag($this->nbt)) : ""); + return "Item " . $this->name . " (" . $this->id . ":" . ($this->hasAnyDamageValue() ? "?" : $this->getMeta()) . ")x" . $this->count . ($this->hasNamedTag() ? " tags:" . base64_encode((new LittleEndianNbtSerializer())->write($this->nbt)) : ""); } /** @@ -863,7 +837,7 @@ class Item implements ItemIds, \JsonSerializable{ } if($this->hasNamedTag()){ - $data["nbt_b64"] = base64_encode(self::writeCompoundTag($this->getNamedTag())); + $data["nbt_b64"] = base64_encode((new LittleEndianNbtSerializer())->write($this->getNamedTag())); } return $data; @@ -875,6 +849,8 @@ class Item implements ItemIds, \JsonSerializable{ * @param array $data * * @return Item + * @throws NbtDataException + * @throws \InvalidArgumentException */ final public static function jsonDeserialize(array $data) : Item{ $nbt = ""; @@ -888,7 +864,7 @@ class Item implements ItemIds, \JsonSerializable{ $nbt = base64_decode($data["nbt_b64"], true); } return ItemFactory::get( - (int) $data["id"], (int) ($data["damage"] ?? 0), (int) ($data["count"] ?? 1), $nbt !== "" ? self::parseCompoundTag($nbt) : null + (int) $data["id"], (int) ($data["damage"] ?? 0), (int) ($data["count"] ?? 1), $nbt !== "" ? (new LittleEndianNbtSerializer())->read($nbt) : null ); }