pocketmine\Player::getFirstPlayed PHP Method

getFirstPlayed() public method

public getFirstPlayed ( )
    public function getFirstPlayed()
    {
        return $this->namedtag instanceof CompoundTag ? $this->namedtag["firstPlayed"] : null;
    }

Usage Example

Exemplo n.º 1
0
 /**
  * Register a player to ServerAuth
  * 
  * @param Player $player
  * @param string $password
  * 
  * @return int|boolean true on SUCCESS, otherwise the current error
  */
 public function registerPlayer(Player $player, $password)
 {
     $cfg = $this->getConfig()->getAll();
     if ($this->isPlayerRegistered($player->getName())) {
         return ServerAuth::ERR_USER_ALREADY_REGISTERED;
     } else {
         if (strlen($password) <= $cfg["minPasswordLength"]) {
             return ServerAuth::ERR_PASSWORD_TOO_SHORT;
         } elseif (strlen($password) >= $cfg["maxPasswordLength"]) {
             return ServerAuth::ERR_PASSWORD_TOO_LONG;
         } else {
             $this->getServer()->getPluginManager()->callEvent($event = new Events\ServerAuthRegisterEvent($player, $password));
             if ($event->isCancelled()) {
                 return ServerAuth::CANCELLED;
             }
             if ($this->getDataProvider()) {
                 //Check MySQL connection
                 if ($this->getDatabase() && $this->getDatabase()->ping()) {
                     if ($cfg["register"]["enable-max-ip"]) {
                         if (\mysqli_num_rows($this->getDatabase()->query("SELECT user, password, ip, firstlogin, lastlogin FROM " . $this->getDatabaseConfig()["table_prefix"] . "serverauthdata WHERE ip='" . $player->getAddress() . "'")) + 1 <= $cfg["register"]["max-ip"]) {
                             $query = "INSERT INTO " . $this->getDatabaseConfig()["table_prefix"] . "serverauthdata (user, password, ip, firstlogin, lastlogin) VALUES ('" . $player->getName() . "', '" . hash($this->getPasswordHash(), $password) . "', '" . $player->getAddress() . "', '" . $player->getFirstPlayed() . "', '" . $player->getLastPlayed() . "')";
                             if ($this->getDatabase()->query($query)) {
                                 return ServerAuth::SUCCESS;
                             } else {
                                 return ServerAuth::ERR_GENERIC;
                             }
                         } else {
                             return ServerAuth::ERR_MAX_IP_REACHED;
                         }
                     } else {
                         $query = "INSERT INTO " . $this->getDatabaseConfig()["table_prefix"] . "serverauthdata (user, password, ip, firstlogin, lastlogin) VALUES ('" . $player->getName() . "', '" . hash($this->getPasswordHash(), $password) . "', '" . $player->getAddress() . "', '" . $player->getFirstPlayed() . "', '" . $player->getLastPlayed() . "')";
                         if ($this->getDatabase()->query($query)) {
                             return ServerAuth::SUCCESS;
                         } else {
                             return ServerAuth::ERR_GENERIC;
                         }
                     }
                 } else {
                     return ServerAuth::ERR_GENERIC;
                 }
             } else {
                 if ($cfg["register"]["enable-max-ip"]) {
                     if ($this->grep($this->getDataFolder() . "users/", $player->getAddress()) + 1 <= $cfg["register"]["max-ip"]) {
                         $data = new Config($this->getDataFolder() . "users/" . strtolower($player->getName() . ".yml"), Config::YAML);
                         $data->set("password", hash($this->getPasswordHash(), $password));
                         $data->set("ip", $player->getAddress());
                         $data->set("firstlogin", $player->getFirstPlayed());
                         $data->set("lastlogin", $player->getLastPlayed());
                         $data->save();
                         return ServerAuth::SUCCESS;
                     } else {
                         return ServerAuth::ERR_MAX_IP_REACHED;
                     }
                 } else {
                     $data = new Config($this->getDataFolder() . "users/" . strtolower($player->getName() . ".yml"), Config::YAML);
                     $data->set("password", hash($this->getPasswordHash(), $password));
                     $data->set("ip", $player->getAddress());
                     $data->set("firstlogin", $player->getFirstPlayed());
                     $data->set("lastlogin", $player->getLastPlayed());
                     $data->save();
                     return ServerAuth::SUCCESS;
                 }
             }
         }
     }
 }
All Usage Examples Of pocketmine\Player::getFirstPlayed
Player