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


PHP command\Command類代碼示例

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


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

示例1: onCommand

 public function onCommand(CommandSender $sender, Command $command, $label, array $args)
 {
     switch ($command->getName()) {
         case "sgw":
             if (count($args) != 2) {
                 return false;
             }
             if (!isset(self::$games[$args[0]])) {
                 $sender->sendMessage(TextFormat::RED . self::getTranslation("UNKNOWN_GAME"));
                 return true;
             }
             if ($this->getServer()->getLevelByName($args[1]) === null) {
                 $sender->sendMessage(TextFormat::RED . self::getTranslation("UNKNOWN_LEVEL"));
                 return true;
             }
             if (isset(self::$worlds[$args[1]])) {
                 $sender->sendMessage(TextFormat::RED . self::getTranslation("WORLD_ALREADY_OCCUPIED"));
                 return true;
             }
             $worlds = json_decode($this->getDataFolder() . "worlds.json", true);
             if (!isset($worlds[$args[0]])) {
                 $worlds[$args[0]] = [];
             }
             $worlds[$args[0]][$args[1]] = ["config" => self::$games[$args[0]]->getStaticPropertyValue("defaultConfigs")];
             file_put_contents($this->getDataFolder() . "worlds.json", json_encode($worlds));
             $sender->sendMessage(TextFormat::AQUA . self::getTranslation("PLEASE_RESTART_SERVER"));
     }
     return true;
 }
開發者ID:organization,項目名稱:XcelNgien,代碼行數:29,代碼來源:XcelNgien.php

示例2: onCommand

 public function onCommand(CommandSender $sender, Command $cmd, $label, array $args)
 {
     if ($cmd->getName() != "motd") {
         return false;
     }
     if ($sender instanceof Player) {
         $world = $sender->getLevel()->getName();
     } else {
         $level = $this->owner->getServer()->getDefaultLevel();
         if ($level) {
             $world = $level->getName();
         } else {
             $world = null;
         }
     }
     if (isset($args[0]) && $this->owner->getServer()->isLevelGenerated($args[0])) {
         $world = array_shift($args);
     }
     if ($world === null) {
         $sender->sendMessage(mc::_("[WP] Must specify a world"));
         return false;
     }
     if (count($args) != 0) {
         return false;
     }
     $this->showMotd($sender, $world);
     return true;
 }
開發者ID:DWWf,項目名稱:pocketmine-plugins,代碼行數:28,代碼來源:WpMotdMgr.php

示例3: onCommand

 public function onCommand(CommandSender $sender, Command $command, $label, array $args)
 {
     if (strtolower($command->getName()) == "nf") {
         if (!($sender->hasPermission("notify") || $sender->hasPermission("notify.command") || $sender->hasPermission("notify.command.nf"))) {
             $sender->sendMessage(TextFormat::RED . "You don't have permission to use that command!");
             return true;
         } else {
             if (!isset($args[0])) {
                 return false;
             } else {
                 if ($args[0] == "on") {
                     if ($this->enabled[0] == "on") {
                         $sender->sendMessage("NotifySounds are already enabled!");
                         return true;
                     } else {
                         $this->enabled[0] = "on";
                         $sender->sendMessage("NotifySounds enabled!");
                         return true;
                     }
                 } elseif ($args[0] == "off") {
                     if ($this->enabled[0] == "off") {
                         $sender->sendMessage("NotifySounds are already disabled!");
                         return true;
                     } else {
                         $this->enabled[0] = "off";
                         $sender->sendMessage("NotifySounds disabled");
                     }
                 } else {
                     return false;
                 }
             }
         }
     }
 }
開發者ID:Blubberboy333,項目名稱:NotifySounds,代碼行數:34,代碼來源:Main.php

示例4: onCommand

 public function onCommand(CommandSender $sender, Command $cmd, $label, array $args)
 {
     if ($cmd->getName() != "near") {
         return false;
     }
     if (!MPMU::inGame($sender)) {
         return true;
     }
     switch (count($args)) {
         case 0:
             $radius = 64 * 64;
             break;
         case 1:
             $radius = (int) $args[0] * (int) $args[0];
             break;
         default:
             return false;
     }
     $players = [];
     foreach ($sender->getLevel()->getPlayers() as $pl) {
         $dist = $pl->distanceSquared($players);
         if ($dist < $radius) {
             $players[] = $pl->getDisplayName();
         }
     }
     if (count($players) == 0) {
         $sender->sendMessage(mc::_("No near by players found!"));
     } else {
         $sender->sendMessage(mc::_("Neighbors(%1%): %2%", count($players), implode(", ", $players)));
     }
     return true;
 }
開發者ID:edwinyoo44,項目名稱:pocketmine-plugins,代碼行數:32,代碼來源:CmdNear.php

示例5: onCommand

 public function onCommand(CommandSender $sender, Command $cmd, $label, array $args)
 {
     if (strtolower($cmd->getName()) === "warn") {
         if (!(isset($args[0]) and isset($args[1]))) {
             $sender->sendMessage(TF::RED . "Error: not enough args. Usage: /warn <player> < reason >");
             return true;
         } else {
             $name = $args[0];
             $player = $this->getServer()->getPlayer($name);
             $player_name = $player->getName();
             $sender_name = $sender->getName();
             $sender_display_name = $sender->getDisplayName();
             unset($args[0]);
             $reason = implode(" ", $args);
             if ($player === null) {
                 $sender->sendMessage(TF::RED . "Player " . $name . " could not be found.");
                 return true;
             } else {
                 $player->sendMessage(TF::RED . "You have been warned by " . $sender_name . " for " . $reason);
                 $sender->sendMessage(TF::GREEN . "You have warned " . $player_name . " for " . $reason);
                 $this->getServer()->broadcastMessage(TF::YELLOW . $player_name . " has been warned by " . $sender_name . " for " . $reason);
                 return true;
             }
         }
     }
 }
開發者ID:applqpak,項目名稱:WarnPlayer,代碼行數:26,代碼來源:Main.php

示例6: onCommand

 public function onCommand(CommandSender $sender, Command $cmd, $label, array $args)
 {
     $fcmd = strtolower($cmd->getName());
     switch ($fcmd) {
         case "mute":
             if ($sender->hasPermission("chatcensor.command.mute")) {
                 if (isset($args[0])) {
                     $args[0] = strtolower($args[0]);
                     //Check if player exists
                     if ($this->plugin->getServer()->getPlayer($args[0]) != null) {
                         $player = $args[0];
                         //Check if player is already muted
                         if ($this->plugin->mutePlayer($player)) {
                             $sender->sendMessage($this->plugin->translateColors("&", Main::PREFIX . "&aYou muted &b" . $player));
                         } else {
                             $sender->sendMessage($this->plugin->translateColors("&", Main::PREFIX . "&cPlayer " . $player . " is already muted!"));
                         }
                     } else {
                         $sender->sendMessage($this->plugin->translateColors("&", Main::PREFIX . "&cPlayer not found!"));
                     }
                 } else {
                     $sender->sendMessage($this->plugin->translateColors("&", Main::PREFIX . "&cUsage: /mute <player>"));
                 }
             } else {
                 $sender->sendMessage($this->plugin->translateColors("&", "&cYou don't have permissions to use this command"));
                 break;
             }
     }
 }
開發者ID:sarhatabaot,項目名稱:ChatCensor,代碼行數:29,代碼來源:Mute.php

示例7: onCommand

 public function onCommand(CommandSender $sender, Command $cmd, $label, array $args)
 {
     if ($cmd->getName() != "players") {
         return false;
     }
     $tab = [[mc::_("Player"), mc::_("World"), mc::_("Pos"), mc::_("Health"), mc::_("Mode")]];
     $cnt = 0;
     foreach ($this->owner->getServer()->getOnlinePlayers() as $player) {
         if (!$player->isOnline() || $sender instanceof Player && !$sender->canSee($player)) {
             continue;
         }
         $pos = $player->getPosition();
         $j = count($tab);
         $mode = substr(MPMU::gamemodeStr($player->getGamemode()), 0, 4);
         $tab[] = [$player->getName(), $player->getLevel()->getName(), $pos->getFloorX() . "," . $pos->getFloorY() . "," . $pos->getFloorZ(), intval($player->getHealth()) . '/' . intval($player->getMaxHealth()), $mode];
         ++$cnt;
     }
     if (!$cnt) {
         $sender->sendMessage(TextFormat::RED . mc::_("Nobody is on-line at the moment"));
         return true;
     }
     $tab[0][0] = mc::_("Players: %1%", $cnt);
     $pageNumber = $this->getPageNumber($args);
     return $this->paginateTable($sender, $pageNumber, $tab);
 }
開發者ID:Gabriel865,項目名稱:pocketmine-plugins,代碼行數:25,代碼來源:CmdPlayers.php

示例8: onCommand

 public function onCommand(CommandSender $sender, Command $command, $label, array $args)
 {
     if ($sender instanceof Player) {
         $name = $sender->getName();
         if (strtolower($command->getName()) == 'heal') {
             if (count($args) > 0) {
                 $player = $args[0];
                 if ($this->getServer()->getPlayer($player)) {
                     $player = $this->getServer()->getPlayer($player);
                     $player->setHealth(20);
                     $sender->sendMessage(TextFormat::BLUE . "[Server] Player " . $player->getName() . " has been healed!");
                     $player->sendMessage(TextFormat::RED . "You have been healed!");
                     return;
                 } else {
                     $sender->sendMessage(TextFormat::BLUE . "[Server] {$player} isn't online at the moment. Please try again when he returns!");
                     return;
                 }
             } else {
                 $sender->setHealth(20);
                 $sender->sendMessage(TextFormat::RED . "You have been healed!");
                 return;
             }
         }
     }
 }
開發者ID:0-DevMatthew-0,項目名稱:RandomCommandsPlugin,代碼行數:25,代碼來源:heal.php

示例9: onCommand

 public function onCommand(CommandSender $sender, Command $command, $label, array $args)
 {
     switch ($command->getName()) {
         case "consoleclients":
             if (!$sender->hasPermission("pocketdockconsole.command.consoleclients")) {
                 $sender->sendMessage(TextFormat::RED . "[PDC] Get some permissions...");
                 return true;
             }
             $authedclients = explode(";", $this->thread->connectedips);
             if (count($authedclients) < 2) {
                 $sender->sendMessage("[PDC] There are no connected clients");
                 return true;
             }
             $sender->sendMessage("[PDC] Connected client(s) are: " . implode("; ", $authedclients));
             return true;
         case "killclient":
             if (!$sender->hasPermission("pocketdockconsole.command.killclient")) {
                 $sender->sendMessage(TextFormat::RED . "[PDC] Get some permissions...");
                 return true;
             }
             if (!isset($args[0])) {
                 $sender->sendMessage($command->getUsage());
                 return true;
             }
             $sender->sendMessage("[PDC] Killing client: " . $args[0]);
             $this->thread->clienttokill = $args[0];
             return true;
         default:
             return false;
     }
 }
開發者ID:brandon15811,項目名稱:PocketDockConsole,代碼行數:31,代碼來源:Main.php

示例10: onCommand

 public function onCommand(CommandSender $sender, Command $cmd, $label, array $args)
 {
     switch ($cmd->getName()) {
         case "banhammer":
             if ($args[0] == "edit") {
                 if ($args[1] == "type") {
                     if ($args[2] == "banip") {
                     } elseif ($args[2] == "ban") {
                     } elseif ($args[2] == "kick") {
                     } else {
                         $sender->sendMessage("Usage: /banhammer edit <type> <banip|ban|kick>");
                     }
                 }
             } elseif ($args[0] == "get") {
                 if ($sender->isOP) {
                     //I'll figure our the real way to do that later
                     //TODO Give BanHammer
                     return true;
                 } else {
                     $sender->sendMessage("[BanHammer] You do not have permission to obtain the BanHammer!");
                     return false;
                 }
             } elseif ($args[0] == "allow") {
                 //TODO Add $args[1] to a config
             } else {
                 $sender->sendMessage("Usage: /banhammer <get|edit|allow> [player]");
             }
             break;
     }
 }
開發者ID:craftyoyo,項目名稱:BanHammer,代碼行數:30,代碼來源:Main.php

示例11: onCommand

 public function onCommand(CommandSender $sender, Command $command, $label, array $args)
 {
     if (strtolower($command->getName()) === "tz") {
         $sender->sendMessage($this->colorlist[strtolower($this->getConfig()->get("color"))] . $this->getTime());
         return true;
     }
 }
開發者ID:HotFireyDeath,項目名稱:PM-Plugins,代碼行數:7,代碼來源:TimeZones.php

示例12: onCommand

 public function onCommand(CommandSender $sender, Command $command, $label, array $args)
 {
     $cmd = strtolower($command->getName());
     switch ($cmd) {
         case "social":
             if (!$sender instanceof Player) {
                 $sender->sendMessage(TEXTFORMAT::BLUE . "- " . $this->getConfig()->get("name"));
                 $sender->sendMessage(TEXTFORMAT::GOLD . "-  Our Website!");
                 $sender->sendMessage(TEXTFORMAT::GREEN . "-  Use /website");
                 $sender->sendMessage(TEXTFORMAT::GOLD . "-  Our Facebook!");
                 $sender->sendMessage(TEXTFORMAT::GREEN . "-  Use /facebook");
                 $sender->sendMessage(TEXTFORMAT::GOLD . "-  Our YouTube!");
                 $sender->sendMessage(TEXTFORMAT::GREEN . "-  Use /youtube");
                 $sender->sendMessage(TEXTFORMAT::GOLD . "-  Our GitHub!");
                 $sender->sendMessage(TEXTFORMAT::GREEN . "-  Use /github");
                 return true;
             }
             $player = $this->getServer()->getPlayer($sender->getName());
             if ($player->hasPermission("gamecraftpe.social")) {
                 $sender->sendMessage("§3 " . $this->getConfig->get("name"));
                 $sender->sendMessage("§2-  Our Website!");
                 $sender->sendMessage("§a-  Use /website");
                 $sender->sendMessage("§2-  Our Facebook!");
                 $sender->sendMessage("§a-  Use /facebook");
                 $sender->sendMessage("§2-  Our YouTube!");
                 $sender->sendMessage("§a-  Use /youtube");
                 $sender->sendMessage("§2-  Our GitHub!");
                 $sender->sendMessage("§a-  Use /github");
                 return true;
             }
             break;
     }
 }
開發者ID:xHFx,項目名稱:GCPESocial,代碼行數:33,代碼來源:Main.php

示例13: onCommand

 public function onCommand(CommandSender $sender, Command $cmd, $label, array $args)
 {
     if ($cmd->getName() != "entities") {
         return false;
     }
     if (count($args) == 0) {
         $args = ["ls"];
     }
     $scmd = strtolower(array_shift($args));
     switch ($scmd) {
         case "count":
             return $this->cmdCount($sender);
         case "nuke":
             return $this->cmdNuke($sender, $args);
         case "ls":
             return $this->cmdEtList($sender, $args);
         case "tiles":
         case "tile":
             return $this->cmdTileList($sender, $args);
         case "info":
         case "nbt":
             return $this->cmdEtInfo($sender, $args);
         case "rm":
             return $this->cmdEtRm($sender, $args);
         case "sign1":
         case "sign2":
         case "sign3":
         case "sign4":
             return $this->cmdEtSign($sender, $scmd, $args);
     }
     return false;
 }
開發者ID:kam187,項目名稱:pocketmine-plugins,代碼行數:32,代碼來源:CmdEntities.php

示例14: onCommand

 public function onCommand(CommandSender $sender, Command $command, $label, array $args)
 {
     if (strtolower($command->getName()) === "buyworld") {
         if (count($args) < 1 || count($args) > 4) {
             return false;
         }
         if (EconomyAPI::getInstance()->myMoney($sender->getName()) < 10000) {
             $sender->sendMessage(TextFormat::RED . "[HyperPlot] You don't have enought money. It cost \$10000");
             return true;
         }
         $world = array_shift($args);
         if (strlen($world) < 3) {
             $sender->sendMessage(TextFormat::RED . "[HyperPlot] Small World name");
             return true;
         }
         if ($this->getServer()->isLevelGenerated($world)) {
             $sender->sendMessage(TextFormat::RED . "[HyperPlot] A world named " . $world . " already exists");
             return true;
         }
         EconomyAPI::getInstance()->reduceMoney($sender->getName(), 10000);
         $this->getServer()->broadcastMessage($sender->sendMessage(TextFormat::RED . "[HyperPlot]  Creating level " . $sender->getName() . "-" . $world . "..."));
         $generator = Generator::getGenerator("ownworld");
         $this->getServer()->generateLevel($sender->getName() . "-" . $world, null, $generator, []);
         $this->getServer()->loadLevel($sender->getName() . "-" . $world);
         return true;
     }
     return false;
 }
開發者ID:Gumbrat,項目名稱:Pocketmine-Plugins,代碼行數:28,代碼來源:HyperPlotWorld.php

示例15: onCommand

 public function onCommand(CommandSender $sender, Command $cmd, $label, array $args)
 {
     if (!isset($args[0])) {
         return false;
     }
     if ($cmd->getName() == "gift") {
         if (($receiver = $this->owner->getServer()->getPlayer($args[0])) == null) {
             if (!MPMU::inGame($sender)) {
                 return true;
             }
             $receiver = $sender;
         } else {
             array_shift($args);
         }
     } else {
         if (!MPMU::inGame($sender)) {
             return true;
         }
         $receiver = $sender;
     }
     if ($receiver->isCreative()) {
         if ($receiver === $sender) {
             $receiver->sendMessage(mc::_("You are in creative mode"));
         } else {
             $sender->sendMessage(mc::_("%1% is in creative mode", $receiver->getDisplayName()));
         }
         return true;
     }
     if (count($args) > 1 && is_numeric($args[count($args) - 1])) {
         $amt = (int) array_pop($args);
     } else {
         $amt = -1;
     }
     $args = strtolower(implode("_", $args));
     if ($args == "more") {
         $item = clone $receiver->getInventory()->getItemInHand();
         if ($item->getId() == 0) {
             $sender->sendMessage(TextFormat::RED . mc::_("Must be holding something"));
             return true;
         }
     } else {
         $item = Item::fromString($args);
         if ($item->getId() == 0) {
             $sender->sendMessage(TextFormat::RED . mc::_("There is no item called %1%", $args));
             return true;
         }
     }
     if ($amt != -1) {
         $item->setCount($amt);
     } else {
         if (isset(self::$stacks[$item->getId()])) {
             $item->setCount(self::$stacks[$item->getId()]);
         } else {
             $item->setCount($item->getMaxStackSize());
         }
     }
     $receiver->getInventory()->addItem(clone $item);
     $this->owner->getServer()->broadcastMessage(mc::_("%1% got %2% of %3% (%4%:%5%)", $receiver->getDisplayName(), $item->getCount(), ItemName::str($item), $item->getId(), $item->getDamage()));
     return true;
 }
開發者ID:kam187,項目名稱:pocketmine-plugins,代碼行數:60,代碼來源:CmdGet.php


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