當前位置: 首頁>>代碼示例>>PHP>>正文


PHP CommandSender::getAllowFlight方法代碼示例

本文整理匯總了PHP中pocketmine\command\CommandSender::getAllowFlight方法的典型用法代碼示例。如果您正苦於以下問題:PHP CommandSender::getAllowFlight方法的具體用法?PHP CommandSender::getAllowFlight怎麽用?PHP CommandSender::getAllowFlight使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在pocketmine\command\CommandSender的用法示例。


在下文中一共展示了CommandSender::getAllowFlight方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。

示例1: onCommand

 public function onCommand(CommandSender $sender, Command $cmd, $label, array $args)
 {
     if (strtolower($cmd->getName()) === "fly") {
         if (empty($args)) {
             if (!$sender->hasPermission("flycommand.me")) {
                 $sender->sendMessage(TextFormat::RED . "You do not have permission to use this command");
                 return true;
             } else {
                 if (!$sender instanceof Player) {
                     $sender->sendMessage(TextFormat::RED . "Command only allowed in-game");
                     return true;
                 }
                 if ($sender->getAllowFlight()) {
                     $sender->setAllowFlight(false);
                     $sender->sendMessage(TextFormat::GREEN . "Flight mode disabled");
                     return true;
                 } else {
                     $sender->setAllowFlight(true);
                     $sender->sendMessage(TextFormat::GREEN . "Flight mode enabled");
                     return true;
                 }
             }
         } else {
             if (count($args === 1)) {
                 $player = $this->getServer()->getPlayer($args[0]);
                 if (!$sender->hasPermission("flycommand.others")) {
                     $sender->sendMessage(TextFormat::RED . "You do not have permission to use this command");
                     return true;
                 } else {
                     if ($player === null) {
                         $sender->sendMessage(TextFormat::RED . "Player not online");
                         return true;
                     }
                     if ($player->getAllowFlight()) {
                         $player->setAllowFlight(false);
                         $player->sendMessage(TextFormat::GREEN . "Flight mode disabled");
                         $sender->sendMessage(TextFormat::GREEN . "Flight mode disabled for player: " . TextFormat::WHITE . $player->getName());
                         return true;
                     } else {
                         $player->setAllowFlight(true);
                         $player->sendMessage(TextFormat::GREEN . "Flight mode enabled");
                         $sender->sendMessage(TextFormat::GREEN . "Flight mode enabled for player: " . TextFormat::WHITE . $player->getName());
                         return true;
                     }
                 }
             }
         }
     }
     return false;
 }
開發者ID:GAalexandres,項目名稱:FlyCommand,代碼行數:50,代碼來源:Main.php


注:本文中的pocketmine\command\CommandSender::getAllowFlight方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。