sleepOn() public method

public sleepOn ( Vector3 $pos ) : boolean
$pos pocketmine\math\Vector3
return boolean
示例#1
0
 public function onActivate(Item $item, Player $player = null)
 {
     $time = $this->getLevel()->getTime() % Level::TIME_FULL;
     $isNight = ($time >= Level::TIME_NIGHT and $time < Level::TIME_SUNRISE);
     if ($player instanceof Player and !$isNight) {
         $pk = new ChatPacket();
         $pk->message = "You can only sleep at night";
         $player->dataPacket($pk);
         return true;
     }
     $blockNorth = $this->getSide(2);
     //Gets the blocks around them
     $blockSouth = $this->getSide(3);
     $blockEast = $this->getSide(5);
     $blockWest = $this->getSide(4);
     if (($this->meta & 0x8) === 0x8) {
         //This is the Top part of bed
         $b = $this;
     } else {
         //Bottom Part of Bed
         if ($blockNorth->getID() === $this->id and ($blockNorth->meta & 0x8) === 0x8) {
             $b = $blockNorth;
         } elseif ($blockSouth->getID() === $this->id and ($blockSouth->meta & 0x8) === 0x8) {
             $b = $blockSouth;
         } elseif ($blockEast->getID() === $this->id and ($blockEast->meta & 0x8) === 0x8) {
             $b = $blockEast;
         } elseif ($blockWest->getID() === $this->id and ($blockWest->meta & 0x8) === 0x8) {
             $b = $blockWest;
         } else {
             if ($player instanceof Player) {
                 $pk = new ChatPacket();
                 $pk->message = "This bed is incomplete";
                 $player->dataPacket($pk);
             }
             return true;
         }
     }
     if ($player instanceof Player and $player->sleepOn($b) === false) {
         $pk = new ChatPacket();
         $pk->message = "This bed is occupied";
         $player->dataPacket($pk);
     }
     return true;
 }
示例#2
0
 public function onActivate(Item $item, Player $player = null)
 {
     if ($this->getLevel()->getDimension() == Level::DIMENSION_NETHER) {
         $explosion = new Explosion($this, 6, $this);
         $explosion->explode();
         return true;
     }
     $time = $this->getLevel()->getTime() % Level::TIME_FULL;
     $isNight = ($time >= Level::TIME_NIGHT and $time < Level::TIME_SUNRISE);
     if ($player instanceof Player and !$isNight) {
         $player->sendMessage(TextFormat::GRAY . "You can only sleep at night");
         return true;
     }
     $blockNorth = $this->getSide(2);
     //Gets the blocks around them
     $blockSouth = $this->getSide(3);
     $blockEast = $this->getSide(5);
     $blockWest = $this->getSide(4);
     if (($this->meta & 0x8) === 0x8) {
         //This is the Top part of bed
         $b = $this;
     } else {
         //Bottom Part of Bed
         if ($blockNorth->getId() === $this->id and ($blockNorth->meta & 0x8) === 0x8) {
             $b = $blockNorth;
         } elseif ($blockSouth->getId() === $this->id and ($blockSouth->meta & 0x8) === 0x8) {
             $b = $blockSouth;
         } elseif ($blockEast->getId() === $this->id and ($blockEast->meta & 0x8) === 0x8) {
             $b = $blockEast;
         } elseif ($blockWest->getId() === $this->id and ($blockWest->meta & 0x8) === 0x8) {
             $b = $blockWest;
         } else {
             if ($player instanceof Player) {
                 $player->sendMessage(TextFormat::GRAY . "This bed is incomplete");
             }
             return true;
         }
     }
     if ($player instanceof Player and $player->sleepOn($b) === false) {
         $player->sendMessage(TextFormat::GRAY . "This bed is occupied");
     }
     return true;
 }