pocketmine\item\Item::getCustomName PHP Method

getCustomName() public method

public getCustomName ( ) : string
return string
    public function getCustomName() : string
    {
        if (!$this->hasCompoundTag()) {
            return "";
        }
        $tag = $this->getNamedTag();
        if (isset($tag->display)) {
            $tag = $tag->display;
            if ($tag instanceof CompoundTag and isset($tag->Name) and $tag->Name instanceof StringTag) {
                return $tag->Name->getValue();
            }
        }
        return "";
    }

Usage Example

Example #1
1
 public function onActivate(Item $item, Player $player = null)
 {
     if ($player instanceof Player) {
         $t = $this->getLevel()->getTile($this);
         if ($t instanceof FurnaceTile) {
             $furnace = $t;
         } else {
             $nbt = new CompoundTag("", [new ListTag("Items", []), new StringTag("id", Tile::FURNACE), new IntTag("x", $this->x), new IntTag("y", $this->y), new IntTag("z", $this->z)]);
             $nbt->Items->setTagType(NBT::TAG_Compound);
             $furnace = Tile::createTile("Furnace", $this->getLevel()->getChunk($this->x >> 4, $this->z >> 4), $nbt);
         }
         if (isset($furnace->namedtag->Lock) and $furnace->namedtag->Lock instanceof StringTag) {
             if ($furnace->namedtag->Lock->getValue() !== $item->getCustomName()) {
                 return true;
             }
         }
         if ($player->isCreative() and $player->getServer()->limitedCreative) {
             return true;
         }
         $player->addWindow($furnace->getInventory());
     }
     return true;
 }
All Usage Examples Of pocketmine\item\Item::getCustomName