diff --git a/src/Player.php b/src/Player.php index b69384a00..c0256a5f3 100644 --- a/src/Player.php +++ b/src/Player.php @@ -293,13 +293,21 @@ class Player{ } public function sleepOn(Vector3 $pos){ + foreach($this->server->api->player->getAll($this->level) as $p){ + if($p->isSleeping instanceof Vector3){ + if($p->distance($pos) <= 0.1){ + return false; + } + } + } $this->isSleeping = $pos; $this->teleport(new Position($pos->x, $pos->y, $pos->z, $this->level)); if($this->entity instanceof Entity){ $this->entity->updateMetadata(); } $this->setSpawn($pos); - $this->server->schedule(30, array($this, "checkSleep")); + $this->server->schedule(60, array($this, "checkSleep")); + return true; } public function stopSleep(){ diff --git a/src/material/block/misc/Bed.php b/src/material/block/misc/Bed.php index a2d9f4ced..0ea9ad4aa 100644 --- a/src/material/block/misc/Bed.php +++ b/src/material/block/misc/Bed.php @@ -29,11 +29,15 @@ class BedBlock extends TransparentBlock{ public function onActivate(Item $item, Player $player){ if(ServerAPI::request()->api->time->getPhase($player->level) !== "night"){ $player->dataPacket(MC_CLIENT_MESSAGE, array( - "message" => "You can only sleep at night." + "message" => "You can only sleep at night" )); return true; } - $player->sleepOn($this); + if($player->sleepOn($this) === false){ + $player->dataPacket(MC_CLIENT_MESSAGE, array( + "message" => "This bed is occupied" + )); + } return true; }