pocketmine\entity\Attribute::getAttributeByName PHP Method

getAttributeByName() public static method

public static getAttributeByName ( $name ) : null | Attribute
$name
return null | Attribute
    public static function getAttributeByName($name)
    {
        foreach (self::$attributes as $a) {
            if ($a->getName() === $name) {
                return clone $a;
            }
        }
        return null;
    }

Usage Example

Exemplo n.º 1
0
 public function updateAttribute()
 {
     $player = $this->server->getPlayer($this->userName);
     if ($player instanceof Player and $player->isConnected()) {
         $pk = new UpdateAttributesPacket();
         $pk->entityId = 0;
         $experience = Attribute::getAttributeByName("player.experience");
         $experience->setValue($this->getExpBarPercent());
         $experience_level = Attribute::getAttributeByName("player.level");
         $experience_level->setValue($this->getExpLevel());
         $hunger = Attribute::getAttributeByName("player.hunger");
         $hunger->setValue($this->getHunger());
         $pk->entries = [$experience, $experience_level, $hunger];
         $player->dataPacket($pk);
     }
 }