Allow setting nametag for any kind of entity

This commit is contained in:
Shoghi Cervantes 2015-05-18 13:08:06 +02:00
parent fbbe02a3bc
commit 85c43ba011
5 changed files with 12 additions and 15 deletions

View File

@ -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 * Gets the player IP address
* *
@ -1512,7 +1504,7 @@ class Player extends Human implements CommandSender, InventoryHolder, ChunkLoade
$this->username = TextFormat::clean($packet->username); $this->username = TextFormat::clean($packet->username);
$this->displayName = $this->username; $this->displayName = $this->username;
$this->nameTag = $this->username; $this->setNameTag($this->username);
$this->iusername = strtolower($this->username); $this->iusername = strtolower($this->username);
$this->randomClientId = $packet->clientId; $this->randomClientId = $packet->clientId;
$this->loginData = ["clientId" => $packet->clientId, "loginData" => null]; $this->loginData = ["clientId" => $packet->clientId, "loginData" => null];

View File

@ -81,6 +81,7 @@ abstract class Entity extends Location implements Metadatable{
const DATA_FLAGS = 0; const DATA_FLAGS = 0;
const DATA_AIR = 1; const DATA_AIR = 1;
const DATA_NAMETAG = 2;
const DATA_SHOW_NAMETAG = 3; const DATA_SHOW_NAMETAG = 3;
const DATA_POTION_COLOR = 7; const DATA_POTION_COLOR = 7;
const DATA_POTION_AMBIENT = 8; const DATA_POTION_AMBIENT = 8;

View File

@ -43,7 +43,6 @@ class Human extends Creature implements ProjectileSource, InventoryHolder{
const DATA_PLAYER_FLAGS = 16; const DATA_PLAYER_FLAGS = 16;
const DATA_PLAYER_BED_POSITION = 17; const DATA_PLAYER_BED_POSITION = 17;
protected $nameTag = "TESTIFICATE";
/** @var PlayerInventory */ /** @var PlayerInventory */
protected $inventory; protected $inventory;
@ -76,14 +75,14 @@ class Human extends Creature implements ProjectileSource, InventoryHolder{
* @return string * @return string
*/ */
public function getNameTag(){ public function getNameTag(){
return $this->nameTag; return $this->getDataProperty(self::DATA_NAMETAG);
} }
/** /**
* @param string $name * @param string $name
*/ */
public function setNameTag($name){ public function setNameTag($name){
$this->nameTag = $name; $this->setDataProperty(self::DATA_NAMETAG, self::DATA_TYPE_STRING, $name);
} }
public function getInventory(){ public function getInventory(){
@ -102,7 +101,7 @@ class Human extends Creature implements ProjectileSource, InventoryHolder{
if(isset($this->namedtag->NameTag)){ 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){ 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(){ public function getName(){
return $this->nameTag; return $this->getNameTag();
} }
public function getDrops(){ public function getDrops(){
@ -212,7 +211,7 @@ class Human extends Creature implements ProjectileSource, InventoryHolder{
$pk = new AddPlayerPacket(); $pk = new AddPlayerPacket();
$pk->clientID = $this->getId(); $pk->clientID = $this->getId();
$pk->username = $this->nameTag; $pk->username = $this->getName();
$pk->eid = $this->getId(); $pk->eid = $this->getId();
$pk->x = $this->x; $pk->x = $this->x;
$pk->y = $this->y; $pk->y = $this->y;

View File

@ -222,6 +222,8 @@ class Item extends Entity{
$pk->item = $this->getItem(); $pk->item = $this->getItem();
$player->dataPacket($pk->setChannel(Network::CHANNEL_ENTITY_SPAWNING)); $player->dataPacket($pk->setChannel(Network::CHANNEL_ENTITY_SPAWNING));
$this->sendData($player);
parent::spawnTo($player); parent::spawnTo($player);
} }
} }

View File

@ -2220,6 +2220,9 @@ class Level implements ChunkManager, Metadatable{
} }
if($entity instanceof Player){ if($entity instanceof Player){
$this->players[$entity->getId()] = $entity; $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; $this->entities[$entity->getId()] = $entity;
} }