diff --git a/src/pocketmine/Player.php b/src/pocketmine/Player.php index c9ab6d7a5..226421704 100644 --- a/src/pocketmine/Player.php +++ b/src/pocketmine/Player.php @@ -565,14 +565,6 @@ class Player extends Human implements CommandSender, InventoryHolder, ChunkLoade } } - public function setNameTag($name){ - parent::setNameTag($name); - if($this->spawned === true){ - $this->despawnFromAll(); - $this->spawnToAll(); - } - } - /** * Gets the player IP address * @@ -1512,7 +1504,7 @@ class Player extends Human implements CommandSender, InventoryHolder, ChunkLoade $this->username = TextFormat::clean($packet->username); $this->displayName = $this->username; - $this->nameTag = $this->username; + $this->setNameTag($this->username); $this->iusername = strtolower($this->username); $this->randomClientId = $packet->clientId; $this->loginData = ["clientId" => $packet->clientId, "loginData" => null]; diff --git a/src/pocketmine/entity/Entity.php b/src/pocketmine/entity/Entity.php index 92106733c..c3cc0efe6 100644 --- a/src/pocketmine/entity/Entity.php +++ b/src/pocketmine/entity/Entity.php @@ -81,6 +81,7 @@ abstract class Entity extends Location implements Metadatable{ const DATA_FLAGS = 0; const DATA_AIR = 1; + const DATA_NAMETAG = 2; const DATA_SHOW_NAMETAG = 3; const DATA_POTION_COLOR = 7; const DATA_POTION_AMBIENT = 8; diff --git a/src/pocketmine/entity/Human.php b/src/pocketmine/entity/Human.php index febd69b8d..9e006a359 100644 --- a/src/pocketmine/entity/Human.php +++ b/src/pocketmine/entity/Human.php @@ -43,7 +43,6 @@ class Human extends Creature implements ProjectileSource, InventoryHolder{ const DATA_PLAYER_FLAGS = 16; const DATA_PLAYER_BED_POSITION = 17; - protected $nameTag = "TESTIFICATE"; /** @var PlayerInventory */ protected $inventory; @@ -76,14 +75,14 @@ class Human extends Creature implements ProjectileSource, InventoryHolder{ * @return string */ public function getNameTag(){ - return $this->nameTag; + return $this->getDataProperty(self::DATA_NAMETAG); } /** * @param string $name */ public function setNameTag($name){ - $this->nameTag = $name; + $this->setDataProperty(self::DATA_NAMETAG, self::DATA_TYPE_STRING, $name); } public function getInventory(){ @@ -102,7 +101,7 @@ class Human extends Creature implements ProjectileSource, InventoryHolder{ if(isset($this->namedtag->NameTag)){ - $this->nameTag = $this->namedtag["NameTag"]; + $this->setNameTag($this->namedtag["NameTag"]); } if(isset($this->namedtag->Inventory) and $this->namedtag->Inventory instanceof Enum){ @@ -125,7 +124,7 @@ class Human extends Creature implements ProjectileSource, InventoryHolder{ } public function getName(){ - return $this->nameTag; + return $this->getNameTag(); } public function getDrops(){ @@ -212,7 +211,7 @@ class Human extends Creature implements ProjectileSource, InventoryHolder{ $pk = new AddPlayerPacket(); $pk->clientID = $this->getId(); - $pk->username = $this->nameTag; + $pk->username = $this->getName(); $pk->eid = $this->getId(); $pk->x = $this->x; $pk->y = $this->y; diff --git a/src/pocketmine/entity/Item.php b/src/pocketmine/entity/Item.php index 10ea7948c..c8eac8cc4 100644 --- a/src/pocketmine/entity/Item.php +++ b/src/pocketmine/entity/Item.php @@ -222,6 +222,8 @@ class Item extends Entity{ $pk->item = $this->getItem(); $player->dataPacket($pk->setChannel(Network::CHANNEL_ENTITY_SPAWNING)); + $this->sendData($player); + parent::spawnTo($player); } } diff --git a/src/pocketmine/level/Level.php b/src/pocketmine/level/Level.php index 2862a0153..889c329a3 100644 --- a/src/pocketmine/level/Level.php +++ b/src/pocketmine/level/Level.php @@ -2220,6 +2220,9 @@ class Level implements ChunkManager, Metadatable{ } if($entity instanceof Player){ $this->players[$entity->getId()] = $entity; + }else{ + $entity->setDataProperty(Entity::DATA_NAMETAG, Entity::DATA_TYPE_STRING, (new \ReflectionObject($entity))->getShortName()); + $entity->setDataProperty(Entity::DATA_SHOW_NAMETAG, Entity::DATA_TYPE_BYTE, 1); } $this->entities[$entity->getId()] = $entity; }