Use a trait for nameable tiles instead of repeating code

This commit is contained in:
Dylan K. Taylor
2017-10-16 12:32:10 +01:00
parent 251d5d7946
commit 95fa1824c8
6 changed files with 96 additions and 53 deletions

View File

@ -30,23 +30,13 @@ use pocketmine\nbt\tag\StringTag;
use pocketmine\Player;
class EnchantTable extends Spawnable implements Nameable{
use NameableTrait;
public function getName() : string{
return isset($this->namedtag->CustomName) ? $this->namedtag->CustomName->getValue() : "Enchanting Table";
}
public function hasName() : bool{
return isset($this->namedtag->CustomName);
}
public function setName(string $str){
if($str === ""){
unset($this->namedtag->CustomName);
return;
}
$this->namedtag->CustomName = new StringTag("CustomName", $str);
/**
* @return string
*/
public function getDefaultName() : string{
return "Enchanting Table";
}
public function addAdditionalSpawnData(CompoundTag $nbt){