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

@ -38,6 +38,7 @@ use pocketmine\nbt\tag\StringTag;
use pocketmine\Player;
class Chest extends Spawnable implements InventoryHolder, Container, Nameable{
use NameableTrait;
/** @var ChestInventory */
protected $inventory;
@ -188,27 +189,8 @@ class Chest extends Spawnable implements InventoryHolder, Container, Nameable{
/**
* @return string
*/
public function getName() : string{
return isset($this->namedtag->CustomName) ? $this->namedtag->CustomName->getValue() : "Chest";
}
/**
* @return bool
*/
public function hasName() : bool{
return isset($this->namedtag->CustomName);
}
/**
* @param string $str
*/
public function setName(string $str){
if($str === ""){
unset($this->namedtag->CustomName);
return;
}
$this->namedtag->CustomName = new StringTag("CustomName", $str);
public function getDefaultName() : string{
return "Chest";
}
public function isPaired(){