当前位置: 首页>>代码示例>>PHP>>正文


PHP Server::getGamemodeString方法代码示例

本文整理汇总了PHP中pocketmine\Server::getGamemodeString方法的典型用法代码示例。如果您正苦于以下问题:PHP Server::getGamemodeString方法的具体用法?PHP Server::getGamemodeString怎么用?PHP Server::getGamemodeString使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在pocketmine\Server的用法示例。


在下文中一共展示了Server::getGamemodeString方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: 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;
 }
开发者ID:NewDelion,项目名称:PocketMine-0.13.x,代码行数:18,代码来源:DefaultGamemodeCommand.php

示例2: 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;
 }
开发者ID:Edwardthedog2,项目名称:Steadfast2,代码行数:18,代码来源:DefaultGamemodeCommand.php

示例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->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;
 }
开发者ID:Edwardthedog2,项目名称:Steadfast2,代码行数:42,代码来源:GamemodeCommand.php

示例4: 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;
 }
开发者ID:GamerXzavier,项目名称:PocketMine-0.13.0,代码行数:38,代码来源:GamemodeCommand.php

示例5: setGamemode

 /**
  * Sets the gamemode, and if needed, kicks the player
  * TODO: Check if Mojang adds the ability to change gamemode without kicking players
  *
  * @param int $gm
  *
  * @return bool
  */
 public function setGamemode($gm)
 {
     if ($gm < 0 or $gm > 3 or $this->gamemode === $gm) {
         return false;
     }
     $this->server->getPluginManager()->callEvent($ev = new PlayerGameModeChangeEvent($this, (int) $gm));
     if ($ev->isCancelled()) {
         return false;
     }
     if (($this->gamemode & 0x1) === ($gm & 0x1)) {
         $this->gamemode = $gm;
         $this->sendMessage("Your gamemode has been changed to " . Server::getGamemodeString($this->getGamemode()) . ".\n");
     } else {
         $this->gamemode = $gm;
         $this->sendMessage("Your gamemode has been changed to " . Server::getGamemodeString($this->getGamemode()) . ".\n");
         $this->inventory->clearAll();
         $this->inventory->sendContents($this->getViewers());
         $this->inventory->sendHeldItem($this->hasSpawned);
     }
     $this->namedtag->playerGameType = new Int("playerGameType", $this->gamemode);
     $spawnPosition = $this->getSpawn();
     $pk = new StartGamePacket();
     $pk->seed = $this->level->getSeed();
     $pk->x = $this->x;
     $pk->y = $this->y + $this->getEyeHeight();
     $pk->z = $this->z;
     $pk->spawnX = (int) $spawnPosition->x;
     $pk->spawnY = (int) $spawnPosition->y;
     $pk->spawnZ = (int) $spawnPosition->z;
     $pk->generator = 1;
     //0 old, 1 infinite, 2 flat
     $pk->gamemode = $this->gamemode & 0x1;
     $pk->eid = 0;
     //Always use EntityID as zero for the actual player
     $this->dataPacket($pk);
     $this->sendSettings();
     return true;
 }
开发者ID:rryy,项目名称:PocketMine-MP,代码行数:46,代码来源:Player.php

示例6: setGamemode

 /**
  * Sets the gamemode, and if needed, kicks the Player.
  *
  * @param int  $gm
  * @param bool $client if the client made this change in their GUI
  *
  * @return bool
  */
 public function setGamemode(int $gm, bool $client = false)
 {
     if ($gm < 0 or $gm > 3 or $this->gamemode === $gm) {
         return false;
     }
     $this->server->getPluginManager()->callEvent($ev = new PlayerGameModeChangeEvent($this, (int) $gm));
     if ($ev->isCancelled()) {
         if ($client) {
             //gamemode change by client in the GUI
             $pk = new SetPlayerGameTypePacket();
             $pk->gamemode = $this->gamemode & 0x1;
             $this->dataPacket($pk);
             $this->sendSettings();
         }
         return false;
     }
     $this->gamemode = $gm;
     $this->allowFlight = $this->isCreative();
     if ($this->isSpectator()) {
         $this->flying = true;
         $this->despawnFromAll();
         // Client automatically turns off flight controls when on the ground.
         // A combination of this hack and a new AdventureSettings flag FINALLY
         // fixes spectator flight controls. Thank @robske110 for this hack.
         $this->teleport($this->temporalVector->setComponents($this->x, $this->y + 0.1, $this->z));
     } else {
         if ($this->isSurvival()) {
             $this->flying = false;
         }
         $this->spawnToAll();
     }
     $this->resetFallDistance();
     $this->namedtag->playerGameType = new IntTag("playerGameType", $this->gamemode);
     if (!$client) {
         //Gamemode changed by server, do not send for client changes
         $pk = new SetPlayerGameTypePacket();
         $pk->gamemode = $this->gamemode & 0x1;
         $this->dataPacket($pk);
         $this->sendSettings();
     } else {
         Command::broadcastCommandMessage($this, new TranslationContainer("commands.gamemode.success.self", [Server::getGamemodeString($gm)]));
     }
     $this->inventory->sendContents($this);
     $this->inventory->sendContents($this->getViewers());
     $this->inventory->sendHeldItem($this->hasSpawned);
     if ($this->isCreative()) {
         $this->inventory->sendCreativeContents();
     }
     return true;
 }
开发者ID:xxFlare,项目名称:PocketMine-MP,代码行数:58,代码来源:Player.php

示例7: setGamemode

 public function setGamemode(Player $player, $gm)
 {
     if ($gm < 0 or $gm > 3 or $player->gamemode === $gm) {
         return \false;
     }
     $player->getServer()->getPluginManager()->callEvent($ev = new PlayerGameModeChangeEvent($player, (int) $gm));
     if ($ev->isCancelled()) {
         return false;
     }
     if (($player->gamemode & 0x1) === ($gm & 0x1)) {
         $player->gamemode = $gm;
         $player->sendMessage(TextFormat::DARK_AQUA . "게임모드가 변경되었습니다, " . Server::getGamemodeString($player->getGamemode()) . ".\n");
     } else {
         $player->gamemode = $gm;
         $player->sendMessage(TextFormat::DARK_AQUA . "게임모드가 변경되었습니다, " . Server::getGamemodeString($player->getGamemode()) . ".\n");
         $player->getInventory()->clearAll();
         $player->getInventory()->sendContents($player->getViewers());
         $player->getInventory()->sendHeldItem($player->getViewers());
     }
     $player->namedtag->playerGameType = new Int("playerGameType", $player->gamemode);
     $player->sendMessage(TextFormat::DARK_AQUA . "새 게임모드 적용을 위해 서버에서 킥처리됩니다.");
     $this->getServer()->getScheduler()->scheduleDelayedTask(new CallbackTask([$this, "Kick"], [$player]), 50);
     return true;
 }
开发者ID:EmreTr1,项目名称:rtr,代码行数:24,代码来源:GameModeKick.php

示例8: onEnable

 public function onEnable()
 {
     $this->saveDefaultConfig();
     self::$token = $this->getConfig()->get("token", "");
     self::$defaultChannel = $this->getConfig()->get("defaultChannel", "");
     self::$updateInterval = $this->getConfig()->get("updateInterval", 20);
     if (self::$token === "") {
         $this->getLogger()->alert("You need to set your Telegram bot token to enable this plugin");
         $this->getLogger()->alert("-> " . $this->getDataFolder() . "config.yml");
         $this->getServer()->getPluginManager()->disablePlugin($this);
         return;
     }
     self::$broadcastToTelegram = $this->getConfig()->get("broadcastToTelegram", true);
     self::$broadcastTelegramMessages = $this->getConfig()->get("broadcastTelegramMessages", true);
     self::$enableTelegramCommands = $this->getConfig()->get("enableTelegramCommands", true);
     self::$disableWebPagePreview = $this->getConfig()->get("disableWebPagePreview", true);
     self::$enableMarkdownParsing = $this->getConfig()->get("enableMarkdownParsing", false);
     self::$debugMode = $this->getConfig()->get("debugMode", false);
     $handler = new EventHandler();
     $this->getServer()->getPluginManager()->registerEvents($handler, $this);
     $this->getServer()->getPluginManager()->subscribeToPermission(Server::BROADCAST_CHANNEL_USERS, $handler);
     PocketTelegram::getMe();
     PocketTelegram::getUpdates();
     if ($this->getConfig()->get("broadcastServerStart", false) === true) {
         PocketTelegram::sendMessage(PocketTelegram::translateString("pocketmine.server.start", [TextFormat::AQUA . $this->getServer()->getVersion()]) . PHP_EOL . PocketTelegram::translateString("pocketmine.server.defaultGameMode", [Server::getGamemodeString($this->getServer()->getGamemode())]) . PHP_EOL . PHP_EOL . "#" . $this->getServer()->getMotd(), self::$defaultChannel);
     }
 }
开发者ID:ChalkPE,项目名称:PocketTelegram,代码行数:27,代码来源:PocketTelegram.php


注:本文中的pocketmine\Server::getGamemodeString方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。