diff --git a/src/pocketmine/OfflinePlayer.php b/src/pocketmine/OfflinePlayer.php index 0b7af091a..e14e1a544 100644 --- a/src/pocketmine/OfflinePlayer.php +++ b/src/pocketmine/OfflinePlayer.php @@ -108,11 +108,11 @@ class OfflinePlayer implements IPlayer, Metadatable{ } public function getFirstPlayed(){ - return $this->namedtag instanceof CompoundTag ? $this->namedtag["firstPlayed"] : null; + return $this->namedtag instanceof CompoundTag ? $this->namedtag->getLong("firstPlayed", 0, true) : null; } public function getLastPlayed(){ - return $this->namedtag instanceof CompoundTag ? $this->namedtag["lastPlayed"] : null; + return $this->namedtag instanceof CompoundTag ? $this->namedtag->getLong("lastPlayed", 0, true) : null; } public function hasPlayedBefore() : bool{ diff --git a/src/pocketmine/Player.php b/src/pocketmine/Player.php index 1016bdada..6239b268c 100644 --- a/src/pocketmine/Player.php +++ b/src/pocketmine/Player.php @@ -95,6 +95,7 @@ use pocketmine\metadata\MetadataValue; use pocketmine\nbt\NBT; use pocketmine\nbt\tag\ByteTag; use pocketmine\nbt\tag\CompoundTag; +use pocketmine\nbt\tag\ListTag; use pocketmine\network\mcpe\PlayerNetworkSessionAdapter; use pocketmine\network\mcpe\protocol\AdventureSettingsPacket; use pocketmine\network\mcpe\protocol\AnimatePacket; @@ -392,11 +393,11 @@ class Player extends Human implements CommandSender, ChunkLoader, IPlayer{ } public function getFirstPlayed(){ - return $this->namedtag instanceof CompoundTag ? $this->namedtag["firstPlayed"] : null; + return $this->namedtag instanceof CompoundTag ? $this->namedtag->getLong("firstPlayed", 0, true) : null; } public function getLastPlayed(){ - return $this->namedtag instanceof CompoundTag ? $this->namedtag["lastPlayed"] : null; + return $this->namedtag instanceof CompoundTag ? $this->namedtag->getLong("lastPlayed", 0, true) : null; } public function hasPlayedBefore() : bool{ @@ -1816,7 +1817,7 @@ class Player extends Human implements CommandSender, ChunkLoader, IPlayer{ $this->namedtag = $this->server->getOfflinePlayerData($this->username); - $this->playedBefore = ($this->namedtag["lastPlayed"] - $this->namedtag["firstPlayed"]) > 1; // microtime(true) - microtime(true) may have less than one millisecond difference + $this->playedBefore = ($this->getLastPlayed() - $this->getFirstPlayed()) > 1; // microtime(true) - microtime(true) may have less than one millisecond difference $this->namedtag->setString("NameTag", $this->username); $this->gamemode = $this->namedtag->getInt("playerGameType", self::SURVIVAL) & 0x03; @@ -1827,12 +1828,14 @@ class Player extends Human implements CommandSender, ChunkLoader, IPlayer{ $this->allowFlight = $this->isCreative(); - if(($level = $this->server->getLevelByName((string) $this->namedtag["Level"])) === null){ + if(($level = $this->server->getLevelByName($this->namedtag->getString("Level", "", true))) === null){ $this->setLevel($this->server->getDefaultLevel()); - $this->namedtag["Level"] = $this->level->getName(); - $this->namedtag["Pos"][0] = $this->level->getSpawnLocation()->x; - $this->namedtag["Pos"][1] = $this->level->getSpawnLocation()->y; - $this->namedtag["Pos"][2] = $this->level->getSpawnLocation()->z; + $this->namedtag->setString("Level", $this->level->getName()); + $this->namedtag->setTag(new ListTag("Pos", [ + $this->level->getSpawnLocation()->x, + $this->level->getSpawnLocation()->y, + $this->level->getSpawnLocation()->z + ])); }else{ $this->setLevel($level); } diff --git a/src/pocketmine/entity/Entity.php b/src/pocketmine/entity/Entity.php index bf305e40d..ce06387b1 100644 --- a/src/pocketmine/entity/Entity.php +++ b/src/pocketmine/entity/Entity.php @@ -496,15 +496,16 @@ abstract class Entity extends Location implements Metadatable, EntityIds{ $this->id = Entity::$entityCount++; $this->namedtag = $nbt; - $this->chunk = $level->getChunk($this->namedtag["Pos"][0] >> 4, $this->namedtag["Pos"][2] >> 4, true); + /** @var float[] $pos */ + $pos = $this->namedtag->getListTag("Pos")->getAllValues(); + + $this->chunk = $level->getChunk(((int) $pos[0]) >> 4, ((int) $pos[2]) >> 4, true); assert($this->chunk !== null); $this->setLevel($level); $this->server = $level->getServer(); $this->boundingBox = new AxisAlignedBB(0, 0, 0, 0, 0, 0); - /** @var float[] $pos */ - $pos = $this->namedtag->getListTag("Pos")->getAllValues(); /** @var float[] $rotation */ $rotation = $this->namedtag->getListTag("Rotation")->getAllValues(); diff --git a/src/pocketmine/entity/Item.php b/src/pocketmine/entity/Item.php index a2acddac0..c8174897a 100644 --- a/src/pocketmine/entity/Item.php +++ b/src/pocketmine/entity/Item.php @@ -57,7 +57,7 @@ class Item extends Entity{ parent::initEntity(); $this->setMaxHealth(5); - $this->setHealth((int) $this->namedtag["Health"]); + $this->setHealth($this->namedtag->getShort("Health", (int) $this->getHealth())); $this->age = $this->namedtag->getShort("Age", $this->age); $this->pickupDelay = $this->namedtag->getShort("PickupDelay", $this->pickupDelay); $this->owner = $this->namedtag->getString("Owner", $this->owner); diff --git a/src/pocketmine/entity/Living.php b/src/pocketmine/entity/Living.php index af30d026a..f7255d1f2 100644 --- a/src/pocketmine/entity/Living.php +++ b/src/pocketmine/entity/Living.php @@ -68,7 +68,7 @@ abstract class Living extends Entity implements Damageable{ $health = $this->getMaxHealth(); if($this->namedtag->hasTag("HealF", FloatTag::class)){ - $health = new FloatTag("Health", (float) $this->namedtag["HealF"]); + $health = new FloatTag("Health", $this->namedtag->getFloat("HealF")); $this->namedtag->removeTag("HealF"); }elseif($this->namedtag->hasTag("Health")){ $healthTag = $this->namedtag->getTag("Health");