mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-06-30 07:09:56 +00:00
Allow setting nametag for any kind of entity
This commit is contained in:
parent
fbbe02a3bc
commit
85c43ba011
@ -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];
|
||||
|
@ -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;
|
||||
|
@ -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;
|
||||
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
@ -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;
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user