diff --git a/src/API/PlayerAPI.php b/src/API/PlayerAPI.php index 661c7708..86d7d6a1 100644 --- a/src/API/PlayerAPI.php +++ b/src/API/PlayerAPI.php @@ -9,7 +9,6 @@ class PlayerAPI{ } public function init(){ - $this->server->schedule(20 * 15, [$this, "handle"], 1, true, "server.regeneration"); $this->server->addHandler("player.death", [$this, "handle"], 1); $this->registerCmd("list"); $this->registerCmd("kill", ""); @@ -32,7 +31,6 @@ class PlayerAPI{ $this->server->api->console->cmdWhitelist("ping"); $this->server->api->console->cmdWhitelist("spawn"); $this->server->api->console->cmdWhitelist("loc"); - //$this->server->preparedSQL->selectPlayersToHeal = $this->server->database->prepare("SELECT EID FROM entities WHERE class = " . ENTITY_PLAYER . " AND health < 20;"); } public function registerCmd($cmd, $help = ""){ @@ -41,22 +39,6 @@ class PlayerAPI{ public function handle($data, $event){ switch($event){ - case "server.regeneration": - if($this->server->difficulty === 0){ - //$result = $this->server->preparedSQL->selectPlayersToHeal->execute(); - if($result !== false){ - while(($player = $result->fetchArray()) !== false){ - if(($player = $this->server->api->entity->get($player["EID"])) !== false){ - if($player->getHealth() <= 0){ - continue; - } - $player->setHealth(min(20, $player->getHealth() + $data), "regeneration"); - } - } - return true; - } - } - break; case "player.death": if(is_numeric($data["cause"])){ $e = $this->server->api->entity->get($data["cause"]); diff --git a/src/Player.php b/src/Player.php index caf5bc74..9f5d5518 100755 --- a/src/Player.php +++ b/src/Player.php @@ -1398,6 +1398,13 @@ class Player{ } public function entityTick(){ if($this->isSleeping) ++$this->sleepingTime; + + if($this->server->difficulty == 0 && $this->entity->counter % (20 * 15) == 0){ + if($this->entity->health < 20 && $this->entity->health > 0){ + $this->entity->setHealth(min(20, $this->entity->health + 1), "regeneration"); + } + } + } public function handleDataPacket(RakNetDataPacket $packet){ if($this->connected === false){