Esempio n. 1
0
 public function onBlockTouch(PlayerInteractEvent $event)
 {
     $session = $this->main->getSessions()->getSession($p = $event->getPlayer());
     if (isset($this->data[$session->getUID()])) {
         $data = $this->data[$session->getUID()];
         $sign = Settings::parkour_checkpoint_signs($event->getBlock());
         if ($sign === -1) {
             if (is_array($coords = Settings::parkour_teleportSign($event->getBlock(), $session->getPlayer()))) {
                 foreach ($coords as $c) {
                     $p->teleport($c);
                 }
             }
             return;
         }
         if ($sign === $data->getProgress()) {
             $session->tell("Checkpoint unchanged.");
             return;
         }
         if ($sign === 0) {
             if (microtime(true) - $data->lastClaimCoins < 10) {
                 $session->tell("Don't spam the sign!");
                 return;
             }
             $coins = 15;
             $tmpFalls = $data->getTmpFalls();
             $tmpFalls = max(min($tmpFalls, 50), 0);
             $tmpFalls /= 5;
             $award = round(($coins - $tmpFalls) * Settings::coinsFactor($session), 2);
             $session->tell("You have completed parkour! You are awarded with %d coins!", $award);
             $coins = $session->getCoins() + $award;
             $session->setCoins($coins);
             $session->tell("You now have {$coins} coins!");
             $data->setCompletions($data->getCompletions() + 1);
             $data->setProgress(0);
             $data->resetTmpFalls();
             if ($data->race instanceof ParkourRace) {
                 $data->race->broadcastProgress($data->getSession(), 0);
             }
         } else {
             $session->tell("You reached checkpoint {$sign}!");
             $data->setProgress($sign);
             if ($data->race instanceof ParkourRace) {
                 $data->race->broadcastProgress($data->getSession(), 0);
             }
         }
         $session->getPlayer()->setSpawn($pos = Settings::parkour_checkpoint_startPos($sign, $this->getMain()->getServer()));
         if ($data->getProgress() === 0) {
             $session->teleport($pos);
         }
         $event->setCancelled();
     }
 }