本文整理汇总了PHP中pocketmine\event\player\PlayerBedEnterEvent::isCancelled方法的典型用法代码示例。如果您正苦于以下问题:PHP PlayerBedEnterEvent::isCancelled方法的具体用法?PHP PlayerBedEnterEvent::isCancelled怎么用?PHP PlayerBedEnterEvent::isCancelled使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pocketmine\event\player\PlayerBedEnterEvent
的用法示例。
在下文中一共展示了PlayerBedEnterEvent::isCancelled方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: onPlayerInteract
/**
* @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);
}
示例2: sleepOn
/**
* @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;
}
示例3: sleepOn
/**
* @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;
}
示例4: sleepOn
/**
* @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;
}