Exemple #1
0
 public function execute(CommandSender $sender, $command, array $args)
 {
     if ($sender instanceof Player) {
         if (count($args) == 1) {
             if (User::exist($sender->getName())) {
                 $user = User::get($sender->getName());
                 if (!$user->isLogged()) {
                     if ($user->login($args[0])) {
                         $sender->sendMessage(TextFormat::GREEN . "You are logged in !");
                     } else {
                         $sender->sendMessage(TextFormat::RED . "Wrong password !");
                     }
                 } else {
                     $sender->sendMessage(TextFormat::RED . "You are already logged in !");
                 }
             } else {
                 $sender->sendMessage(TextFormat::RED . "You need to register first !");
             }
         } else {
             $sender->sendMessage(TextFormat::RED . $this->getUsage());
         }
     } else {
         $sender->sendMessage(TextFormat::GOLD . "You need to be in-game to perform this command");
     }
     return true;
 }
 /**
  * Prevent the player to use the chat (Speak or command)
  * only if the command is not "/login" or "/register"
  * @param PlayerCommandPreprocessEvent $event
  */
 public function onPlayerPreprocess(PlayerCommandPreprocessEvent $event)
 {
     $message = $event->getMessage();
     if (preg_match("/^\\/login|\\/register\$/", $message)) {
         return;
     }
     $player = $event->getPlayer();
     if (!User::exist($player->getName()) || User::exist($player->getName()) && !User::get($player->getName())->isLogged()) {
         $event->setCancelled(true);
         $player->sendMessage($this->needLogin);
     }
 }