Exemple #1
0
 /**
  * @priority HIGHEST
  */
 public function onPlayerInteract(PlayerInteractEvent $event)
 {
     if ($event->isCancelled()) {
         return;
     }
     $p = $event->getPlayer();
     $b = $event->getBlock();
     if ($b->getID() !== 26) {
         return;
     }
     $event->setCancelled();
     $xTabel = [3 => 1, 1 => -1];
     $b = $b->getSide(5, isset($xTabel[$dmg = $b->getDamage()]) ? $xTabel[$dmg] : 0);
     $zTabel = [0 => 1, 2 => -1];
     $b = $b->getSide(3, isset($zTabel[$dmg]) ? $zTabel[$dmg] : 0);
     $this->getServer()->getPluginManager()->callEvent($ev = new PlayerBedEnterEvent($p, $b));
     if ($ev->isCancelled()) {
         return;
     }
     $property = (new \ReflectionClass("\\pocketmine\\Player"))->getProperty("sleeping");
     $property->setAccessible(true);
     foreach ($p->getLevel()->getNearbyEntities($p->getBoundingBox()->grow(2, 1, 2), $p) as $pl) {
         if ($pl instanceof Player && $pl->isSleeping()) {
             if ($b->distance($property->getValue($pl)) <= 0.1) {
                 $p->sendMessage("This bed is occupied");
                 return;
             }
         }
     }
     $property->setValue($p, $b);
     $p->teleport($b->add(0.5, 0.5, 0.5));
     $p->sendMetadata($p->getViewers());
     $p->sendMetadata($p);
 }
 /**
  * @param Vector3 $pos
  *
  * @return boolean
  */
 public function sleepOn(Vector3 $pos)
 {
     if (!$this->isOnline()) {
         return false;
     }
     foreach ($this->level->getNearbyEntities($this->boundingBox->grow(2, 1, 2), $this) as $p) {
         if ($p instanceof Player) {
             if ($p->sleeping !== null and $pos->distance($p->sleeping) <= 0.1) {
                 return false;
             }
         }
     }
     $this->server->getPluginManager()->callEvent($ev = new PlayerBedEnterEvent($this, $this->level->getBlock($pos)));
     if ($ev->isCancelled()) {
         return false;
     }
     $this->sleeping = clone $pos;
     $this->teleport(new Position($pos->x + 0.5, $pos->y - 0.5, $pos->z + 0.5, $this->level));
     $this->setDataProperty(self::DATA_PLAYER_BED_POSITION, self::DATA_TYPE_POS, [$pos->x, $pos->y, $pos->z]);
     $this->setDataFlag(self::DATA_PLAYER_FLAGS, self::DATA_PLAYER_FLAG_SLEEP, true);
     $this->setSpawn($pos);
     $this->level->sleepTicks = 60;
     return true;
 }
Exemple #3
0
 /**
  * @param Vector3 $pos
  *
  * @return boolean
  */
 public function sleepOn(Vector3 $pos)
 {
     foreach ($this->level->getNearbyEntities($this->boundingBox->grow(2, 1, 2), $this) as $p) {
         if ($p instanceof Player) {
             if ($p->sleeping !== null and $pos->distance($p->sleeping) <= 0.1) {
                 return false;
             }
         }
     }
     $this->server->getPluginManager()->callEvent($ev = new PlayerBedEnterEvent($this, $this->level->getBlock($pos)));
     if ($ev->isCancelled()) {
         return false;
     }
     $this->sleeping = clone $pos;
     $this->setDataProperty(self::DATA_PLAYER_BED_POSITION, self::DATA_TYPE_POS, [$pos->x, $pos->y, $pos->z]);
     $this->setDataFlag(self::DATA_PLAYER_FLAGS, self::DATA_PLAYER_FLAG_SLEEP, true);
     $this->setSpawn($pos);
     $this->tasks[] = $this->server->getScheduler()->scheduleDelayedTask(new CallbackTask([$this, "checkSleep"]), 60);
     return true;
 }
Exemple #4
0
 /**
  * @param Vector3 $pos
  *
  * @return boolean
  */
 public function sleepOn(Vector3 $pos)
 {
     foreach ($this->level->getNearbyEntities($this->boundingBox->grow(2, 1, 2), $this) as $p) {
         if ($p instanceof Player) {
             if ($p->sleeping !== null) {
                 if ($pos->distance($p->sleeping) <= 0.1) {
                     return false;
                 }
             }
         }
     }
     $this->server->getPluginManager()->callEvent($ev = new PlayerBedEnterEvent($this, $this->level->getBlock($pos)));
     if ($ev->isCancelled()) {
         return false;
     }
     $this->sleeping = clone $pos;
     $this->teleport(new Position($pos->x + 0.5, $pos->y + 1, $pos->z + 0.5, $this->level));
     $this->sendMetadata($this->getViewers());
     $this->sendMetadata($this);
     $this->setSpawn($pos);
     $this->tasks[] = $this->server->getScheduler()->scheduleDelayedTask(new CallbackTask([$this, "checkSleep"]), 60);
     return true;
 }