Exemplo n.º 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;
 }
Exemplo n.º 2
0
 public function onActivate(Item $item, Player $player = null)
 {
     if ($player instanceof Player and $player->getHealth() < 20) {
         ++$this->meta;
         $player->heal(3, "cake");
         if ($this->meta >= 0x6) {
             $this->getLevel()->setBlock($this, new Air(), true);
         } else {
             $this->getLevel()->setBlock($this, $this, true);
         }
         return true;
     }
     return false;
 }
Exemplo n.º 3
0
 public function onActivate(Item $item, Player $player = \null)
 {
     if ($player instanceof Player and $player->getHealth() < 20) {
         ++$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;
 }
Exemplo n.º 4
0
 public function onActivate(Item $item, Player $player = null)
 {
     if ($player instanceof Player and $player->getHealth() < 20) {
         ++$this->meta;
         Server::getInstance()->getPluginManager()->callEvent($ev = new EntityRegainHealthEvent($player, 3, EntityRegainHealthEvent::CAUSE_EATING));
         if (!$ev->isCancelled()) {
             $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;
 }
Exemplo n.º 5
0
 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;
 }