Exemple #1
0
 public function onActivate(Item $item, Player $player = null)
 {
     if ($player instanceof Player and $player->getHealth() < $player->getMaxHealth()) {
         $ev = new EntityEatBlockEvent($player, $this);
         if (!$ev->isCancelled()) {
             $this->getLevel()->setBlock($this, $ev->getResidue());
             return true;
         }
     }
     return false;
 }
Exemple #2
0
 public function onActivate(Item $item, Player $player = null)
 {
     if ($player instanceof Player and $player->getHealth() < $player->getMaxHealth()) {
         ++$this->meta;
         $ev = new EntityRegainHealthEvent($player, 3, EntityRegainHealthEvent::CAUSE_EATING);
         $player->heal($ev->getAmount(), $ev);
         if ($this->meta >= 0x6) {
             $this->getLevel()->setBlock($this, new Air(), true);
         } else {
             $this->getLevel()->setBlock($this, $this, true);
         }
         return true;
     }
     return false;
 }
 public function getHealthStatus(Player $player)
 {
     $config = $this->getConfig()->getAll();
     $symbol = $config["Symbol"];
     $currenthealth = $player->getHealth();
     $usedhealth = $player->getMaxHealth() - $player->getHealth();
     $healthstatus = $config["Health-Color"] . str_repeat($symbol, $currenthealth / 2) . TextFormat::RESET . $config["Used-Health-Color"] . str_repeat($symbol, $usedhealth / 2);
     return $healthstatus;
 }