Exemplo n.º 1
0
 public function onEnable()
 {
     self::$instance = $this;
     @mkdir($this->getDataFolder());
     $this->saveDefaultConfig();
     $this->reloadConfig();
     StormClient::setApiKey($this->getConfig()->get("api-key"));
     StormClient::setApiHost($this->getConfig()->get("api-host"));
     $this->playerManager = new PlayerManager();
     $this->writeDefault("formats.yml");
     $this->formats = new Config($this->getDataFolder() . "formats.yml", Config::YAML);
     StormFormatter::loadPrefix();
     self::registerListener(new AuthenticationListener());
     self::registerListener(new PunishmentListener());
     $this->registerStormCommand("login", new LoginCommand());
     $this->registerStormCommand("register", new RegisterCommand());
     $this->registerStormCommand("netop", new NetOpCommand());
     $this->registerStormCommand("netdeop", new NetDeOpCommand());
     $var = "yeah";
     StormClient::sendData('GET', [], 'ping', $var, function ($t, $r) {
         if ($r->code != 200) {
             Server::getInstance()->shutdown();
         }
     });
 }
Exemplo n.º 2
0
 public function onPlayerLogin(PlayerLoginEvent $event)
 {
     StormClient::sendData('POST', ['username' => $event->getPlayer()->getName(), 'ip' => $event->getPlayer()->getAddress()], 'punishments/targeted/noAuth', $this, function ($ca, $resp) {
         if ($resp->code != 200) {
             return;
         }
         $punishments = $resp->response;
         foreach ($punishments as $punishment) {
             $ca->handlePunishment($punishment);
         }
     });
 }
Exemplo n.º 3
0
 protected function handleCommandUnspecific(CommandSender $sender, array $args)
 {
     if (!$sender->hasPermission("storm.netop")) {
         throw new BasicStormCommandException("You do not have permission for this command!");
     }
     if (sizeof($args) < 1) {
         throw new BasicStormCommandException("You did not supply a player!");
     }
     $player = $args[0];
     StormClient::sendData('POST', ["username" => $player, 'op' => 'true'], 'users/op', $sender, function ($pl, $resp) {
         if ($resp->code != 200) {
             $pl->sendMessage(TextFormat::RED . $resp->response);
         } else {
             $pl->sendMessage(StormFormatter::withPath('opped-player')->with("player", $resp->response->user->Username)->get());
         }
     });
 }
Exemplo n.º 4
0
 public function handleAuthCallback($result)
 {
     if ($result->code != 200) {
         $this->authenticated = false;
         StormCore::callEvent(new PlayerAuthenticationErrorEvent($this, StormClient::teaseError($result->response)));
         return;
     }
     $this->loadJson($result->response);
 }
Exemplo n.º 5
0
 public function updatePunishments()
 {
     StormClient::sendData('GET', [], 'punishments/targeted/auth/' . $this->id, $this, function ($uThis, $resp) {
         if ($resp->code != 200) {
             return;
         }
         /** @noinspection PhpUndefinedMethodInspection */
         $uThis->setPunishmentsJson($resp->response);
     });
 }
 /**
  * Actions to execute when completed (on main thread)
  * Implement this if you want to handle the data in your AsyncTask after it has been processed
  *
  * @param Server $server
  *
  * @return void
  */
 public function onCompletion(Server $server)
 {
     if ($this->shouldReschdule) {
         $this->schedule();
         return;
     }
     StormClient::finished($this->id, $this->result);
 }
Exemplo n.º 7
0
 /**
  * @param $id int
  * @param $find boolean
  * @return null|StormPlayer|StormFuturePlayer
  */
 public function getPlayerByID($id, $find)
 {
     foreach ($this->players as $pl) {
         if ($pl->getId() == $id) {
             return $pl;
         }
     }
     if ($find) {
         $futurePlayer = new StormFuturePlayer();
         StormClient::sendData("GET", [], "users/get/id/" . $id, $futurePlayer, function ($uThis, $result) {
             $uThis->dropIn(StormOfflinePlayer::withJson($result->response));
         });
         return $futurePlayer;
     }
     return null;
 }