public function onRun()
 {
     foreach ($this->queries as $query) {
         if (($return = Utils::getURL(str_replace("{USERNAME}", urlencode($this->id), $query->getCheckURL()))) != false && is_array($return = json_decode($return, true)) && isset($return["voted"]) && is_bool($return["voted"]) && isset($return["claimed"]) && is_bool($return["claimed"])) {
             $query->setVoted($return["voted"] ? 1 : -1);
             $query->setClaimed($return["claimed"] ? 1 : -1);
             if ($query->hasVoted() && !$query->hasClaimed()) {
                 if (($return = Utils::getURL(str_replace("{USERNAME}", urlencode($this->id), $query->getClaimURL()))) != false && is_array($return = json_decode($return, true)) && isset($return["voted"]) && is_bool($return["voted"]) && isset($return["claimed"]) && is_bool($return["claimed"])) {
                     $query->setVoted($return["voted"] ? 1 : -1);
                     $query->setClaimed($return["claimed"] ? 1 : -1);
                     if ($query->hasVoted() && $query->hasClaimed()) {
                         $this->rewards++;
                     }
                 } else {
                     $this->error = "Error sending claim data for \"" . $this->id . "\" to \"" . str_replace("{USERNAME}", urlencode($this->id), $query->getClaimURL()) . "\". Invalid VRC file or bad Internet connection.";
                     $query->setVoted(-1);
                     $query->setClaimed(-1);
                 }
             }
         } else {
             $this->error = "Error fetching vote data for \"" . $this->id . "\" from \"" . str_replace("{USERNAME}", urlencode($this->id), $query->getCheckURL()) . "\". Invalid VRC file or bad Internet connection.";
             $query->setVoted(-1);
             $query->setClaimed(-1);
         }
     }
 }
Beispiel #2
0
 public function rewardPlayer($player, $multiplier)
 {
     if (!$player instanceof Player) {
         return;
     }
     if ($multiplier < 1) {
         $player->sendMessage("[VoteReward] You haven't voted on any server lists!");
         return;
     }
     $clones = [];
     foreach ($this->items as $item) {
         $clones[] = clone $item;
     }
     foreach ($clones as $item) {
         $item->setCount($item->getCount() * $multiplier);
         $player->getInventory()->addItem($item);
     }
     foreach ($this->commands as $command) {
         $this->getServer()->dispatchCommand(new ConsoleCommandSender(), str_replace(array("{USERNAME}", "{NICKNAME}", "{X}", "{Y}", "{Y1}", "{Z}"), array($player->getName(), $player->getDisplayName(), $player->getX(), $player->getY(), $player->getY() + 1, $player->getZ()), Utils::translateColors($command)));
     }
     if (trim($this->message) != "") {
         $message = str_replace(array("{USERNAME}", "{NICKNAME}"), array($player->getName(), $player->getDisplayName()), Utils::translateColors($this->message));
         foreach ($this->getServer()->getOnlinePlayers() as $p) {
             $p->sendMessage($message);
         }
         $this->getServer()->getLogger()->info($message);
     }
     $player->sendMessage("[VoteReward] You voted on {$multiplier} server list" . ($multiplier == 1 ? "" : "s") . "!");
 }