php pocketmine-command-Command类(方法)实例源码

下面列出了php pocketmine-command-Command 类(方法)源码代码实例,从而了解它的用法。

作者:organizatio    项目:XcelNgie   
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;
 }

作者:DWW    项目:pocketmine-plugin   
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;
 }

作者:Blubberboy33    项目:NotifySound   
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;
                 }
             }
         }
     }
 }

作者:edwinyoo4    项目:pocketmine-plugin   
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;
 }

作者:applqpa    项目:WarnPlaye   
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;
             }
         }
     }
 }

作者:sarhatabao    项目:ChatCenso   
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;
             }
     }
 }

作者:Gabriel86    项目:pocketmine-plugin   
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);
 }

作者:0-DevMatthew-    项目:RandomCommandsPlugi   
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;
             }
         }
     }
 }

作者:brandon1581    项目:PocketDockConsol   
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;
     }
 }

作者:craftyoy    项目:BanHamme   
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;
     }
 }

作者:HotFireyDeat    项目:PM-Plugin   
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;
     }
 }

作者:xHF    项目:GCPESocia   
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;
     }
 }

作者:kam18    项目:pocketmine-plugin   
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;
 }

作者:Gumbra    项目:Pocketmine-Plugin   
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;
 }

作者:kam18    项目:pocketmine-plugin   
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;
 }

作者:Gabriel86    项目:pocketmine-plugin   
public function onCommand(CommandSender $sender, Command $cmd, $label, array $args)
 {
     if ($cmd->getName() != "servicemode") {
         return false;
     }
     if (count($args) == 0) {
         if ($this->mode !== false) {
             $sender->sendMessage(TextFormat::RED . mc::_("In Service Mode: %1%", $this->mode));
         } else {
             $sender->sendMessage(TextFormat::GREEN . mc::_("In Normal operating mode"));
         }
         return true;
     }
     if (in_array(strtolower(array_shift($args)), ["on", "up", "true", 1])) {
         $msg = implode(" ", $args);
         if (!$msg) {
             $msg = mc::_("Scheduled maintenance");
         }
         $this->owner->getServer()->broadcastMessage(TextFormat::RED . mc::_("ATTENTION: Entering service mode"));
         $this->owner->getServer()->broadcastMessage(TextFormat::YELLOW . " - " . $msg);
     } else {
         $msg = false;
         $this->owner->getServer()->broadcastMessage(TextFormat::GREEN . mc::_("ATTENTION: Leaving service mode"));
     }
     $this->mode = $msg;
     return true;
 }

作者:DWW    项目:pocketmine-plugin   
public function onCommand(CommandSender $sender, Command $cmd, $label, array $args)
 {
     if ($cmd->getName() != "manyworlds") {
         return false;
     }
     return $this->dispatchSCmd($sender, $cmd, $args);
 }

作者:Skull3    项目:C4-Explosio   
public function onCommand(CommandSender $sender, Command $command, $label, array $args)
 {
     if ($command->getName() === "boom") {
         if (count($args)) {
             if (!isset($args[1])) {
                 $sender->sendMessage("Usage: /boom <radius> true|false");
                 return false;
             }
             if (is_numeric($args[0])) {
                 $sender->sendMessage(TextFormat::YELLOW . "Boom!");
                 $e = new Explosion($sender, $args[0]);
                 switch ($args[1]) {
                     case "true":
                         $e->explodeA();
                         $e->explodeB();
                         break;
                     case "false":
                         $e->explodeB();
                         break;
                 }
             } else {
                 $sender->sendMessage(TextFormat::RED . "Select radius in numeric value!");
                 return;
             }
         }
     }
 }

作者:RedstoneAlmeid    项目:MyPlugin   
public function onCommand(CommandSender $sender, Command $command, $label, array $args)
 {
     $cmd = strtolower($command->getName());
     if ($cmd === "helper") {
         $line1 = $this->getConfig()->get("line1");
         $line2 = $this->getConfig()->get("line2");
         $line3 = $this->getConfig()->get("line3");
         $line4 = $this->getConfig()->get("line4");
         $line5 = $this->getConfig()->get("line5");
         $line6 = $this->getConfig()->get("line6");
         $line7 = $this->getConfig()->get("line7");
         $line8 = $this->getConfig()->get("line8");
         $line9 = $this->getConfig()->get("line9");
         $line10 = $this->getConfig()->get("line10");
         $sender->sendMessage("{$line1}");
         $sender->sendMessage("{$line2}");
         $sender->sendMessage("{$line3}");
         $sender->sendMessage("{$line4}");
         $sender->sendMessage("{$line5}");
         $sender->sendMessage("{$line6}");
         $sender->sendMessage("{$line7}");
         $sender->sendMessage("{$line8}");
         $sender->sendMessage("{$line9}");
         $sender->sendMessage("{$line10}");
         return true;
     }
 }

作者:0-DevMatthew-    项目:pocketmine-plugin   
public function onCommand(CommandSender $sender, Command $cmd, $label, array $args)
 {
     if ($cmd->getName() != "top") {
         return false;
     }
     switch (count($args)) {
         case 0:
             if (!MPMU::inGame($sender)) {
                 return true;
             }
             $pl = $sender;
             break;
         case 1:
             if (!MPMU::access($sender, "gb.cmd.top.others")) {
                 return true;
             }
             $pl = $this->owner->getServer()->getPlayer($args[0]);
             if (!$pl) {
                 $sender->sendMessage(mc::_("%1% not found", $args[0]));
                 return true;
             }
             break;
         default:
             return false;
     }
     $y = $pl->getLevel()->getHighestBlockAt($pl->getX(), $pl->getZ()) + 1;
     $pl->teleport(new Vector3($pl->getX(), $y, $pl->getZ()));
     return true;
 }


问题


面经


文章

微信
公众号

扫码关注公众号