Added nametag saving

This commit is contained in:
Shoghi Cervantes 2015-05-18 19:04:37 +02:00
parent 840690d801
commit 70a7c4c552

View File

@ -268,6 +268,13 @@ abstract class Entity extends Location implements Metadatable{
return $this->getDataProperty(self::DATA_NAMETAG);
}
/**
* @return bool
*/
public function isNameTagVisible(){
return $this->getDataProperty(self::DATA_SHOW_NAMETAG) > 0;
}
/**
* @param string $name
*/
@ -275,6 +282,13 @@ abstract class Entity extends Location implements Metadatable{
$this->setDataProperty(self::DATA_NAMETAG, self::DATA_TYPE_STRING, $name);
}
/**
* @param bool $value
*/
public function setNameTagVisible($value = true){
$this->setDataProperty(self::DATA_SHOW_NAMETAG, self::DATA_TYPE_BYTE, $value ? 1 : 0);
}
/**
* @return Effect[]
*/
@ -406,6 +420,8 @@ abstract class Entity extends Location implements Metadatable{
public function saveNBT(){
if(!($this instanceof Player)){
$this->namedtag->id = new String("id", $this->getSaveId());
$this->namedtag->CustomName = new String("CustomName", $this->getNameTag());
$this->namedtag->CustomNameVisible = new String("CustomNameVisible", $this->isNameTagVisible());
}
$this->namedtag->Pos = new Enum("Pos", [
@ -463,6 +479,12 @@ abstract class Entity extends Location implements Metadatable{
}
}
if(isset($this->namedtag->CustomName)){
$this->setNameTag($this->namedtag["CustomName"]);
$this->setNameTagVisible($this->namedtag["CustomNameVisible"] > 0);
}
$this->scheduleUpdate();
}