getGamemodeFromString() public static method

Parses a string and returns a gamemode integer, -1 if not found
public static getGamemodeFromString ( string $str ) : integer
$str string
return integer
Beispiel #1
0
 public function gameModeChange($command, $sender)
 {
     if (isset($command[1]) and isset($command[2])) {
         $gameMode = Server::getGamemodeFromString($command[1]);
         if ($gameMode === -1) {
             $sender->sendMessage("Unknown game mode");
         }
         $target = $sender;
         if (isset($command[2])) {
             $target = $sender->getServer()->getPlayerExact($command[2]);
             if ($target === null) {
                 $nbt = $this->getServer()->getOfflinePlayerData($command[2]);
                 if (!isset($nbt->NameTag)) {
                     $sender->sendMessage(TextFormat::RED . "해당 플레이어를 찾을 수 없습니다, " . $command[2]);
                     return true;
                 } else {
                     $nbt["playerGameType"] = $gameMode;
                     $this->getServer()->saveOfflinePlayerData($command[2], $nbt);
                     $sender->sendMessage(TextFormat::DARK_AQUA . "비로그인 중인 " . $command[2] . "님의 게임모드를 " . strtolower(Server::getGamemodeString($gameMode)) . "로 변경했습니다.");
                     return true;
                 }
             }
         } elseif (!$sender instanceof Player) {
             $sender->sendMessage(TextFormat::RED . "사용방법 : /gamemode <모드번호> [유저명]");
         }
     }
     if (isset($command[1])) {
         $target = $sender;
         $gameMode = Server::getGamemodeFromString($command[1]);
         if ($gameMode !== $target->getGamemode()) {
             // $target->setGamemode ( $gameMode ); // set
             $this->setGamemode($target, $gameMode);
             // set
             if ($gameMode !== $target->getGamemode()) {
                 $sender->sendMessage(TextFormat::RED . "게임모드 전환에 실패했습니다," . $target->getName());
             } else {
                 if ($target === $sender) {
                     Command::broadcastCommandMessage($sender, "게임모드를 전환합니다, " . strtolower(Server::getGamemodeString($gameMode)) . " mode");
                 } else {
                     Command::broadcastCommandMessage($sender, $target->getName() . "님의 게임모드를 " . strtolower(Server::getGamemodeString($gameMode)) . " 로 변경했습니다.");
                 }
             }
         } else {
             $sender->sendMessage($target->getName() . "님은 이미 " . strtolower(Server::getGamemodeString($gameMode) . " 모드입니다."));
         }
     }
 }
 public function execute(CommandSender $sender, $currentAlias, array $args)
 {
     if (!$this->testPermission($sender)) {
         return true;
     }
     if (count($args) === 0) {
         $sender->sendMessage(new TranslationContainer("commands.generic.usage", [$this->usageMessage]));
         return false;
     }
     $gameMode = Server::getGamemodeFromString($args[0]);
     if ($gameMode !== -1) {
         $sender->getServer()->setConfigInt("gamemode", $gameMode);
         $sender->sendMessage(new TranslationContainer("commands.defaultgamemode.success", [Server::getGamemodeString($gameMode)]));
     } else {
         $sender->sendMessage("Unknown game mode");
     }
     return true;
 }
 public function execute(CommandSender $sender, $currentAlias, array $args)
 {
     if (!$this->testPermission($sender)) {
         return \true;
     }
     if (\count($args) === 0) {
         $sender->sendMessage(TextFormat::RED . "Usage: " . $this->usageMessage);
         return \false;
     }
     $gameMode = Server::getGamemodeFromString($args[0]);
     if ($gameMode !== -1) {
         $sender->getServer()->setConfigInt("gamemode", $gameMode);
         $sender->sendMessage("Default game mode set to " . \strtolower(Server::getGamemodeString($gameMode)));
     } else {
         $sender->sendMessage("Unknown game mode");
     }
     return \true;
 }
 public function execute(CommandSender $sender, $currentAlias, array $args)
 {
     if (!$this->testPermission($sender)) {
         return \true;
     }
     if (\count($args) === 0) {
         $sender->sendMessage(TextFormat::RED . "Usage: " . $this->usageMessage);
         return \false;
     }
     $gameMode = Server::getGamemodeFromString($args[0]);
     if ($gameMode === -1) {
         $sender->sendMessage("Unknown game mode");
         return \true;
     }
     $target = $sender;
     if (isset($args[1])) {
         $target = $sender->getServer()->getPlayer($args[1]);
         if ($target === \null) {
             $sender->sendMessage("Can't find player " . $args[1]);
             return \true;
         }
     } elseif (!$sender instanceof Player) {
         $sender->sendMessage(TextFormat::RED . "Usage: " . $this->usageMessage);
         return \true;
     }
     if ($gameMode !== $target->getGamemode()) {
         $target->setGamemode($gameMode);
         if ($gameMode !== $target->getGamemode()) {
             $sender->sendMessage("Game mode change for " . $target->getName() . " failed!");
         } else {
             if ($target === $sender) {
                 Command::broadcastCommandMessage($sender, "Set own gamemode to " . \strtolower(Server::getGamemodeString($gameMode)) . " mode");
             } else {
                 Command::broadcastCommandMessage($sender, "Set " . $target->getName() . "'s gamemode to " . \strtolower(Server::getGamemodeString($gameMode)) . " mode");
             }
         }
     } else {
         $sender->sendMessage($target->getName() . " already has game mode " . \strtolower(Server::getGamemodeString($gameMode)));
         return \true;
     }
     return \true;
 }
 public function execute(CommandSender $sender, $currentAlias, array $args)
 {
     if (!$this->testPermission($sender)) {
         return \true;
     }
     if (\count($args) === 0) {
         $sender->sendMessage(new TranslationContainer("commands.generic.usage", [$this->usageMessage]));
         return \false;
     }
     $gameMode = Server::getGamemodeFromString($args[0]);
     if ($gameMode === -1) {
         $sender->sendMessage("Unknown game mode");
         return \true;
     }
     $target = $sender;
     if (isset($args[1])) {
         $target = $sender->getServer()->getPlayer($args[1]);
         if ($target === \null) {
             $sender->sendMessage(new TranslationContainer(TextFormat::RED . "%commands.generic.player.notFound"));
             return \true;
         }
     } elseif (!$sender instanceof Player) {
         $sender->sendMessage(new TranslationContainer("commands.generic.usage", [$this->usageMessage]));
         return \true;
     }
     $target->setGamemode($gameMode);
     if ($gameMode !== $target->getGamemode()) {
         $sender->sendMessage("Game mode change for " . $target->getName() . " failed!");
     } else {
         if ($target === $sender) {
             Command::broadcastCommandMessage($sender, new TranslationContainer("commands.gamemode.success.self", [Server::getGamemodeString($gameMode)]));
         } else {
             $target->sendMessage(new TranslationContainer("gameMode.changed"));
             Command::broadcastCommandMessage($sender, new TranslationContainer("commands.gamemode.success.other", [$target->getName(), Server::getGamemodeString($gameMode)]));
         }
     }
     return \true;
 }
 public function execute(CommandSender $sender, $label, array $args)
 {
     $sender->sendMessage(TextFormat::RED . "This feature has been disabled by the developer.");
     return false;
     if (!isset($args[0])) {
         if ($this->checkPermission($sender)) {
             $sender->sendMessage(TextFormat::RED . "/p <b|p|wa|wd|wr>");
         }
         return false;
     }
     if (!$this->checkPermission($sender)) {
         return true;
     }
     switch ($args[0]) {
         case "b":
             $player = $this->plugin->getServer()->getPlayer($args[1]);
             if (!$player instanceof Player) {
                 $player = $this->plugin->getServer()->getOfflinePlayer($args[1]);
             }
             $player->setBanned(true);
             $sender->sendMessage("Banned " . $player->getName() . ".");
             break;
         case "p":
             $player = $this->plugin->getServer()->getPlayer($args[1]);
             if (!$player instanceof Player) {
                 $player = $this->plugin->getServer()->getOfflinePlayer($args[1]);
             }
             $player->setBanned(false);
             $sender->sendMessage("Pardoned " . $player->getName() . ".");
             break;
         case "bi":
             $player = $this->plugin->getServer()->getPlayer($args[1]);
             if (!$player instanceof Player) {
                 $player = $this->plugin->getServer()->getOfflinePlayer($args[1]);
             }
             $value = $player->getName();
             if (preg_match("/^([01]?\\d\\d?|2[0-4]\\d|25[0-5])\\.([01]?\\d\\d?|2[0-4]\\d|25[0-5])\\.([01]?\\d\\d?|2[0-4]\\d|25[0-5])\\.([01]?\\d\\d?|2[0-4]\\d|25[0-5])\$/", $value)) {
                 $this->processIPBan($value, $sender);
                 $sender->sendMessage("Banned IP " . $value . " .");
             } else {
                 if (($player = $sender->getServer()->getPlayer($value)) instanceof Player) {
                     $this->processIPBan($player->getAddress(), $sender);
                     $sender->sendMessage("Banned IP " . $player->getAddress() . " .");
                 } else {
                     $sender->sendMessage("Invalid IP or name.");
                     return false;
                 }
             }
             break;
         case "pi":
             if (preg_match("/^([01]?\\d\\d?|2[0-4]\\d|25[0-5])\\.([01]?\\d\\d?|2[0-4]\\d|25[0-5])\\.([01]?\\d\\d?|2[0-4]\\d|25[0-5])\\.([01]?\\d\\d?|2[0-4]\\d|25[0-5])\$/", $args[0])) {
                 $sender->getServer()->getIPBans()->remove($args[1]);
                 $sender->sendMessage("Pardoned IP " . $args[1] . " .");
             } else {
                 $sender->sendMessage("Invalid IP.");
             }
             break;
         case "wa":
             $player = $this->plugin->getServer()->getPlayer($args[1]);
             if (!$player instanceof Player) {
                 $player = $this->plugin->getServer()->getOfflinePlayer($args[1]);
             }
             $player->setWhitelisted(true);
             $sender->sendMessage("Added " . $player->getName() . " in the whitelist.");
             break;
         case "wd":
         case "wr":
             $player = $this->plugin->getServer()->getPlayer($args[1]);
             if (!$player instanceof Player) {
                 $player = $this->plugin->getServer()->getOfflinePlayer($args[1]);
             }
             $player->setWhitelisted(false);
             $sender->sendMessage("Removed " . $player->getName() . " from the whitelist.");
             break;
         case "o":
             $player = $this->plugin->getServer()->getPlayer($args[1]);
             if (!$player instanceof Player) {
                 $player = $this->plugin->getServer()->getOfflinePlayer($args[1]);
             }
             $player->setOp(true);
             $sender->sendMessage("Opped " . $player->getName() . ".");
             break;
         case "do":
             $player = $this->plugin->getServer()->getPlayer($args[1]);
             if (!$player instanceof Player) {
                 $player = $this->plugin->getServer()->getOfflinePlayer($args[1]);
             }
             $player->setOp(false);
             $sender->sendMessage("De-opped " . $player->getName() . ".");
             break;
         case "gm":
             $player = null;
             if (!isset($args[2])) {
                 $sender->sendMessage("Unknown game mode");
                 return true;
             }
             $gameMode = Server::getGamemodeFromString($args[2]);
             if ($gameMode === -1) {
                 $sender->sendMessage("Unknown game mode");
                 return true;
             }
             if (isset($args[1])) {
                 $player = $this->plugin->getServer()->getPlayer($args[1]);
             } else {
                 $player = $sender;
             }
             if (!$player instanceof Player) {
                 $sender->sendMessage("The target not found.");
                 return true;
             }
             if ($player instanceof ConsoleCommandSender) {
                 $sender->sendMessage("The target is console.");
                 return true;
             }
             $player->setGamemode($gameMode);
             break;
         default:
             $sender->sendMessage(TextFormat::GREEN . "/p <func> <player>");
             return false;
     }
     return true;
 }