本文整理汇总了PHP中pocketmine\Server::getGamemodeFromString方法的典型用法代码示例。如果您正苦于以下问题:PHP Server::getGamemodeFromString方法的具体用法?PHP Server::getGamemodeFromString怎么用?PHP Server::getGamemodeFromString使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pocketmine\Server
的用法示例。
在下文中一共展示了Server::getGamemodeFromString方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: gameModeChange
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) . " 모드입니다."));
}
}
}
示例2: execute
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;
}
示例3: execute
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;
}
示例4: execute
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;
}
示例5: execute
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;
}
示例6: execute
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;
//.........这里部分代码省略.........