Example #1
0
 /**
  * @param PlayerInteractEvent $event
  * @priority HIGHEST
  */
 public function onTouchBlock(PlayerInteractEvent $event)
 {
     $player = $event->getPlayer();
     $session = $this->getMain()->getSessions()->getSession($player);
     if (!$session instanceof Session or !$session->inSession($this)) {
         return;
     }
     $event->setCancelled($event->getFace() !== 0xff);
     if ($event->getFace() === 0xff) {
         return;
     }
     Settings::spleef_getType($event->getBlock(), $arenaId, $spectator);
     if ($arenaId !== -1) {
         $data = $this->getPlayerData($session);
         if ($data->isInArena()) {
             $this->rebouncePlayer($data);
             return;
         }
         $arena = $this->getArena($arenaId);
         if ($spectator === 2) {
             $arena->kick($data, "Spectator quit", false);
         } elseif ($spectator === 1) {
             $arena->spectate($this->getPlayerData($session));
         } else {
             if ($arena->isPlaying()) {
                 $session->tell("A match is going on in {$arena}!");
                 return;
             }
             if ($arena->isFull()) {
                 $session->tell("The arena is already full!");
                 return;
             }
             $arena->join($data);
         }
     } else {
         $data = $this->getPlayerData($session);
         if ($data->isPlaying() and $data->getArena()->isPlaying() and Settings::spleef_isArenaFloor($event->getBlock())) {
             $event->setCancelled(false);
         } elseif ($result = Settings::spleef_incineratorInfo($event->getBlock())) {
             if ($event->getItem()->getId() !== Item::AIR) {
                 $event->setCancelled();
                 $item = $event->getItem();
                 $player->getInventory()->setItemInHand(Item::get(Item::AIR, 0, 1));
                 $player->getInventory()->sendContents($player->getInventory()->getViewers());
                 for ($x = 936; $x <= 938; $x++) {
                     $this->spleefWorld->setBlock(new Vector3($x, 21, -13), Block::get(Block::JACK_O_LANTERN), false, false);
                 }
                 for ($z = -16; $z <= -14; $z++) {
                     $this->spleefWorld->setBlock(new Vector3(935, 21, $z), Block::get(Block::JACK_O_LANTERN, 1), false, false);
                 }
                 $motion = $result[0]->subtract($player)->multiply(0.3);
                 $source = $player->add(0, 1.3);
                 $itemEntity = Entity::createEntity("Item", $player->getLevel()->getChunk($source->getX() >> 4, $source->getZ() >> 4), new Compound("", ["Pos" => new Enum("Pos", [new Double("", $source->getX()), new Double("", $source->getY()), new Double("", $source->getZ())]), "Motion" => new Enum("Motion", [new Double("", $motion->x), new Double("", $motion->y), new Double("", $motion->z)]), "Rotation" => new Enum("Rotation", [new Float("", lcg_value() * 360), new Float("", 0)]), "Health" => new Short("Health", 1), "Item" => new Compound("Item", ["id" => new Short("id", $item->getId()), "Damage" => new Short("Damage", $item->getDamage()), "Count" => new Byte("Count", $item->getCount())]), "PickupDelay" => new Short("PickupDelay", 0x7fff)]));
                 $itemEntity->spawnToAll();
                 $this->getMain()->getServer()->getScheduler()->scheduleDelayedTask(new CallbackPluginTask($this->getMain(), function (\pocketmine\entity\Item $item, Vector3 $pos) {
                     $item->teleport($pos);
                 }, $itemEntity, $result[0]), 10);
                 $this->getMain()->getServer()->getScheduler()->scheduleDelayedTask(new CallbackPluginTask($this->getMain(), function (\pocketmine\entity\Item $item, Vector3 $target) {
                     $item->setMotion($target->subtract($item)->multiply(0.1));
                 }, $itemEntity, $result[1]), 40);
                 $this->getMain()->getServer()->getScheduler()->scheduleDelayedTask(new CallbackPluginTask($this->getMain(), function (\pocketmine\entity\Item $item) {
                     $item->kill();
                 }, $itemEntity), 70);
                 $this->getMain()->getServer()->getScheduler()->scheduleDelayedTask(new CallbackPluginTask($this->getMain(), function () {
                     for ($x = 936; $x <= 938; $x++) {
                         $this->spleefWorld->setBlock(new Vector3($x, 21, -13), Block::get(Block::PUMPKIN), false, false);
                     }
                     for ($z = -16; $z <= -14; $z++) {
                         $this->spleefWorld->setBlock(new Vector3(935, 21, $z), Block::get(Block::PUMPKIN, 1), false, false);
                     }
                 }), 80);
             }
         }
     }
 }