本文整理汇总了PHP中pocketmine\command\Command::getUsage方法的典型用法代码示例。如果您正苦于以下问题:PHP Command::getUsage方法的具体用法?PHP Command::getUsage怎么用?PHP Command::getUsage使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pocketmine\command\Command
的用法示例。
在下文中一共展示了Command::getUsage方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: onCommand
public function onCommand(CommandSender $sender, Command $command, $label, array $args)
{
if ($label === "transfer") {
if (count($args) < 2 or count($args) > 3 or count($args) === 2 and !$sender instanceof Player) {
$sender->sendMessage(new TranslationContainer("commands.generic.usage", [$command->getUsage()]));
return true;
}
/** @var Player $target */
$target = $sender;
if (count($args) === 3) {
$target = $sender->getServer()->getPlayer($args[0]);
$address = $args[1];
$port = (int) $args[2];
} else {
$address = $args[0];
$port = (int) $args[1];
}
if ($target === null) {
$sender->sendMessage(new TranslationContainer(TextFormat::RED . "%commands.generic.player.notFound"));
return true;
}
$sender->sendMessage("Transferring player " . $target->getDisplayName() . " to {$address}:{$port}");
if (!$this->transferPlayer($target, $address, $port)) {
$sender->sendMessage(TextFormat::RED . "An error occurred during the transfer");
}
return true;
}
return false;
}
示例2: onCommand
public function onCommand(CommandSender $sender, Command $command, $label, array $args)
{
if ($label === "server") {
if (count($args) < 2 or count($args) > 3 or count($args) === 2 and !$sender instanceof Player) {
$sender->sendMessage(new TranslationContainer("commands.generic.usage", [$command->getUsage()]));
return true;
}
/** @var Player $target */
$target = $sender;
if (count($args) === 3) {
$target = $sender->getServer()->getPlayer($args[0]);
$address = $args[1];
$port = (int) $args[2];
} else {
$address = $args[0];
$port = (int) $args[1];
}
if ($target === null) {
$sender->sendMessage(new TranslationContainer(TextFormat::RED . "%commands.generic.player.notFound"));
return true;
}
$sender->sendMessage("[Knot] Working...\n[Knot] Done!");
if (!$this->transferPlayer($target, $address, $port)) {
$sender->sendMessage("[Knot] Working...\n[Knot] ERR: Unknown");
}
return true;
}
return false;
}
示例3: 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;
}
}
示例4: onCommand
public function onCommand(CommandSender $sender, Command $command, $label, array $args)
{
switch ($command->getName()) {
case "explode":
if (count($args) === 1) {
$player = $args[0];
$this->explodePlayer($player, $sender, 2);
return true;
} elseif (count($args) === 2) {
$player = $args[0];
$force = (int) $args[1];
if ($force > 20) {
$sender->sendMessage("§cForce too strong!");
return true;
} else {
if ($force < 1) {
$sender->sendMessage("§cForce too weak!");
return true;
} else {
$this->explodePlayer($player, $sender, $force);
return true;
}
}
} else {
$sender->sendMessage("§cUsage: §f" . $command->getUsage());
return true;
}
}
}
示例5: onCommand
public function onCommand(CommandSender $sender, Command $command, $label, array $args)
{
if ($command->getName() == "survivalgames") {
if (!isset($args[0]) || trim($args[0]) == "") {
$args[0] = "help";
}
if (isset($this->commandMap[$args[0]])) {
$displayUsage = !$this->commandMap[$args[0]]->execute($sender, $args[0], array_slice($args, 1));
if ($displayUsage) {
$sender->sendMessage("Usage: " . str_replace("sg", $label, $command->getUsage()));
}
}
}
}
示例6: sendUsage
/**
* Function to give different type of usages, switching from "Console" and "Player" executors of a command.
* This function can be overridden to fit any command needs...
*
* @param CommandSender $sender
* @param string $alias
*/
public function sendUsage(CommandSender $sender, $alias)
{
$message = TextFormat::RED . "Usage: " . TextFormat::GRAY . "/{$alias} ";
if (!$sender instanceof Player) {
if (is_string($this->consoleUsageMessage)) {
$message .= $this->consoleUsageMessage;
} elseif (!$this->consoleUsageMessage) {
$message = TextFormat::RED . "[Error] Please run this command in-game";
} else {
$message .= str_replace("[player]", "<player>", parent::getUsage());
}
} else {
$message .= parent::getUsage();
}
$sender->sendMessage($message);
}
示例7: onCommand
public function onCommand(CommandSender $sender, Command $command, $label, array $args)
{
switch ($command->getName()) {
case "greenify":
if (count($args) !== 0) {
$sender->sendMessage(TextFormat::RED . "Usage: " . $command->getUsage());
return true;
}
$sender->sendMessage("Prepare for a lag spike!");
$level = $sender->getLevel();
$playerX = $sender->getFloorX();
$playerZ = $sender->getFloorZ();
for ($x = $playerX - 100; $x <= $playerX + 100; $x++) {
for ($z = $playerZ - 100; $z <= $playerZ + 100; $z++) {
$level->setBiomeColor($x, $z, 127, 169, 76);
}
}
return true;
}
}
示例8: onCommand
public function onCommand(CommandSender $sender, Command $command, $label, array $args)
{
switch ($command->getName()) {
case "alias":
if (!isset($args[0])) {
$sender->sendMessage(TextFormat::RED . "Usage: " . $command->getUsage() . "");
return true;
}
$name = strtolower($args[0]);
$player = $this->getServer()->getPlayer($name);
if ($player instanceof Player) {
$ip = $player->getPlayer()->getAddress();
$file = new Config($this->getDataFolder() . "players/ip/" . $ip[0] . "/" . $ip . ".txt");
$names = $file->getAll(true);
$names = implode(', ', $names);
$sender->sendMessage(TextFormat::GREEN . "[Alias] Showing alias of " . $name . "...");
$sender->sendMessage(TextFormat::BLUE . "[Alias] " . $names . "");
return true;
} else {
if (!is_file($this->getDataFolder() . "players/lastip/" . $name[0] . "/" . $name . ".yml")) {
$sender->sendMessage(TextFormat::YELLOW . "[Alias] Error: Player does not exist!");
return true;
} else {
$lastip = new Config($this->getDataFolder() . "players/lastip/" . $name[0] . "/" . $name . ".yml");
$ip = $lastip->get("lastip");
$file = new Config($this->getDataFolder() . "players/ip/" . $ip[0] . "/" . $ip . ".txt");
$names = $file->getAll(true);
if ($names == null) {
$sender->sendMessage(TextFormat::YELLOW . "[Alias] Error: Player does not exist!");
break;
} else {
$names = implode(', ', $names);
$sender->sendMessage(TextFormat::GREEN . "[Alias] Showing alias of " . $name . "...");
$sender->sendMessage(TextFormat::BLUE . "[Alias] " . $names . "");
return true;
}
}
}
return true;
}
}
示例9: onCommand
public function onCommand(CommandSender $sender, Command $command, $label, array $args)
{
if (strtolower($command->getName()) === "pm") {
if (!$sender instanceof Player) {
$sender->sendMessage("Please run this command in game");
return true;
}
if (!$sender->hasPermission("pm.command")) {
$sender->sendMessage("Yout dont have permissions to write a PM");
return true;
}
if (!isset($args[0])) {
$sender->sendMessage($command->getUsage());
return true;
}
$playerName = $sender->getName();
$text = chop(trim(implode(" ", $args)));
$message = json_encode(array("playerName" => $playerName, "message" => $text, "datetime" => date("Y-m-d H:i:s")));
$this->saveMessage($message);
$sender->sendMessage("PM written. OP will read it later");
}
return true;
}
示例10: onCommand
//.........这里部分代码省略.........
$auction = array_shift($params);
if (trim($auction) === "" and !$sender instanceof Player) {
$sender->sendMessage("Usage: /auction stop <player>");
break;
} elseif (trim($auction) === "" and $sender instanceof Player) {
$auction = $sender->getName();
} else {
$player = $this->getServer()->getPlayer($auction);
if ($player instanceof Player) {
$auction = $player->getName();
}
}
$auction = strtolower($auction);
if (!isset($this->auctions[$auction])) {
$sender->sendMessage((strtolower($sender->getName()) === $auction ? "You have" : "{$auction} has") . " no ongoing auction");
break;
}
$this->quitAuction($auction);
$sender->sendMessage((strtolower($sender->getName()) === $auction ? "Your" : "{$auction}'s") . " auction has successfully stopped.");
break;
case "time":
if (!$sender instanceof Player) {
$sender->sendMessage("Please run this command in-game.");
return true;
}
$item = array_shift($params);
$count = array_shift($params);
$startPrice = array_shift($params);
$time = array_shift($params);
if (trim($item) === "" or !is_numeric($count) or !is_numeric($startPrice) or !is_numeric($time)) {
$sender->sendMessage("Usage: /auction time <item> <count> <start price> <time>");
break;
}
$e = explode(":", $item);
if (!is_numeric($e[0])) {
$e[0] = 1;
}
if (!isset($e[1]) or !is_numeric($e[1])) {
$e[1] = 0;
}
$e = array((int) $e[0], (int) $e[1]);
$cnt = 0;
foreach ($sender->getInventory()->getContents() as $i) {
if ($i->getID() === $e[0] and $i->getDamage() === $e[1]) {
++$cnt;
}
if ($count <= $cnt) {
break;
}
}
if ($count <= $cnt) {
$sender->getInventory()->removeItem(new Item($e[0], $e[1], $count));
$id = $this->getServer()->getScheduler()->scheduleDelayedTask(new QuitAuctionTask($this, $sender->getName()), $time * 20)->getTaskId();
$this->auctions[strtolower($sender->getName())] = array($e[0], $e[1], (int) $count, (int) $startPrice, null, (int) $startPrice, $time, time(), $id);
$this->getServer()->broadcastMessage($sender->getName() . "'s auction has just started.");
} else {
$sender->sendMessage("You don't have enough items");
}
break;
case "bid":
if (!$sender instanceof Player) {
$sender->sendMessage("Please run this command in-game.");
break;
}
$player = array_shift($params);
$price = array_shift($params);
if (trim($player) === "" or trim($price) === "") {
$sender->sendMessage("Usage: /auction bid <player> <price>");
break;
}
if (!isset($this->auctions[$player])) {
$sender->sendMessage("Auction by \"{$player}\" does not exist");
break;
}
if ($price > (int) $this->auctions[$player][5]) {
$this->auctions[$player][5] = $price;
$this->auctions[$player][4] = $sender->getName();
$sender->sendMessage("You have bid " . EconomyAPI::getInstance()->getMonetaryUnit() . "{$price} to auction by \"{$player}\"");
} else {
$sender->sendMessage("Current price is bigger than you have tried to bid");
}
break;
case "list":
$output = "Auctions list:\n";
foreach ($this->auctions as $player => $data) {
$price = $data[5] === null ? $data[3] : $data[5];
$p = $data[4] === null ? "No player" : $data[4];
$output .= "##" . $player . " | " . EconomyAPI::getInstance()->getMonetaryUnit() . "{$price} | " . $data[2] . " of " . $data[0] . ":" . $data[1] . " | {$p}\n";
}
$output = substr($output, 0, -1);
$sender->sendMessage($output);
break;
default:
$sender->sendMessage("Usage: " . $command->getUsage());
}
return true;
default:
return true;
}
}
示例11: onCommand
//.........这里部分代码省略.........
}
if (!is_numeric($landnum)) {
$sender->sendMessage($this->getMessage("land-num-must-numeric", array($landnum, "%2", "%3")));
return true;
}
$info = $this->db->getLandById($landnum);
if ($info === false) {
$sender->sendMessage($this->getMessage("no-land-found", array($landnum, "%2", "%3")));
return true;
} elseif ($info["owner"] !== $sender->getName()) {
$sender->sendMessage($this->getMessage("not-your-land", array($landnum, "%2", "%3")));
return true;
} else {
if (preg_match('#^[a-zA-Z0-9_]{3,16}$#', $player) == 0) {
$sender->sendMessage($this->getMessage("invalid-invitee", [$player, "%2", "%3"]));
return true;
}
$result = $this->db->addInviteeById($landnum, $player);
if ($result === false) {
$sender->sendMessage($this->getMessage("already-invitee", array($player, "%2", "%3")));
return true;
}
$sender->sendMessage($this->getMessage("success-invite", array($player, $landnum, "%3")));
}
return true;
case "kick":
if (!$sender->hasPermission("economyland.command.land.invite.remove")) {
$sender->sendMessage($this->getMessage("no-permission-command"));
return true;
}
$landnum = array_shift($param);
$player = array_shift($param);
if (trim($player) === "") {
$sender->sendMessage(TextFormat::RED . "Usage: " . $command->getUsage());
return true;
}
if (!is_numeric($landnum)) {
$sender->sendMessage($this->getMessage("land-num-must-numeric", array($landnum, "%2", "%3")));
return true;
}
$info = $this->db->getLandById($landnum);
if ($info === false) {
$sender->sendMessage($this->getMessage("no-land-found", array($landnum, "%2", "%3")));
return true;
}
if ($sender->hasPermission("economyland.command.land.invite.remove.others") and $info["owner"] !== $sender->getName() or $info["owner"] === $sender->getName()) {
$result = $this->db->removeInviteeById($landnum, $player);
if ($result === false) {
$sender->sendMessage($this->getMessage("not-invitee", array($player, $landnum, "%3")));
return true;
}
$sender->sendMessage($this->getMessage("removed-invitee", array($player, $landnum, "%3")));
}
return true;
case "invitee":
$landnum = array_shift($param);
if (trim($landnum) == "" or !is_numeric($landnum)) {
$sender->sendMessage("Usage: /land invitee <land number>");
return true;
}
$info = $this->db->getInviteeById($landnum);
if ($info === false) {
$sender->sendMessage($this->getMessage("no-land-found", array($landnum, "%2", "%3")));
return true;
}
$output = "Invitee of land #{$landnum} : \n";
示例12: onCommand
public function onCommand(CommandSender $sender, Command $command, $label, array $args)
{
switch ($command->getName()) {
case "bw":
if ($sender instanceof Player) {
if (count($args) !== 0) {
$sender->sendMessage(TextFormat::RED . "Usage: " . $command->getUsage());
return true;
}
if ($this->game && ($Team = $this->game->getTeamByPlayer($sender))) {
if ($this->game->Status == 0) {
array_splice($Team->Players, array_search($sender, $Team->Players), 1);
$Msg = $this->getMessage("bedwars.team.quited", $sender->getName());
foreach ($Team->Players as $Player) {
$Player->sendMessage($Msg);
}
$this->game->updateTeams();
} else {
$sender->sendMessage(TextFormat::RED . $this->getMessage("bw.nouse"));
return true;
}
}
$this->load_lobby();
if ($Inv = $sender->getInventory()) {
$Inv->clearAll();
}
if ($sender->getGamemode() != Player::SURVIVAL) {
$sender->setGamemode(Player::SURVIVAL);
}
$sender->removeAllEffects();
$sender->setDataFlag(Entity::DATA_FLAGS, Entity::DATA_FLAG_INVISIBLE, false);
$sender->teleport($this->lobby->getSafeSpawn());
$sender->teleport($this->lobby_spawn);
foreach ($this->lobby->getEntities() as $Entity) {
$Entity->spawnTo($sender);
}
return true;
} else {
$sender->sendMessage(TextFormat::RED . "This command only works in-game.");
return true;
}
case "bwvote":
if ($sender instanceof Player) {
if (count($args) !== 0) {
$sender->sendMessage(TextFormat::RED . "Usage: " . $command->getUsage());
return true;
}
if ($sender->getLevel() != $this->game->Level) {
$sender->sendMessage(TextFormat::RED . $this->getMessage("bwvote.nouse"));
return true;
}
if ($this->game->Status == 1) {
$sender->sendMessage(TextFormat::RED . $this->getMessage("bwvote.notime"));
return true;
}
if (in_array(strtolower($sender->getName()), $this->Votes)) {
$sender->sendMessage(TextFormat::RED . $this->getMessage("bwvote.used"));
return true;
}
$this->Votes[] = strtolower($sender->getName());
if (intval(count($this->game->Level->getPlayers()) / 1.5) <= count($this->Votes)) {
if (count($this->game->Level->getPlayers()) <= 1) {
$this->game->Stop();
return true;
}
$this->game->Start();
}
return true;
} else {
$sender->sendMessage(TextFormat::RED . "This command only works in-game.");
return true;
}
break;
case "bwstart":
if (count($args) !== 0) {
$sender->sendMessage(TextFormat::RED . "Usage: " . $command->getUsage());
return true;
}
if ($this->game->Status == 1) {
$sender->sendMessage(TextFormat::RED . $this->getMessage("bwstart.notime"));
return true;
}
$this->StartTime = time() - 1;
return true;
break;
case "bwstop":
if (count($args) !== 0) {
$sender->sendMessage(TextFormat::RED . "Usage: " . $command->getUsage());
return true;
}
if ($this->game->Status == 0) {
$sender->sendMessage(TextFormat::RED . $this->getMessage("bwstop.notime"));
return true;
}
$this->game->Stop();
return true;
break;
}
return false;
}
示例13: onCommand
public function onCommand(CommandSender $sender, Command $command, $label, array $params)
{
switch ($command->getName()) {
case "exchange":
if (!$sender instanceof Player) {
$sender->sendMessage("[ExchangeItem] Please run this command in-game.");
return true;
}
$player = array_shift($params);
if (trim($player) === "") {
$sender->sendMessage("[ExchangeItem] Usage: " . $command->getUsage());
return true;
}
if (count($params) === 0) {
switch ($player) {
case "accept":
if (isset($this->acception[$sender->getName()])) {
$requester = $this->getServer()->getPlayerExact($this->acception[$sender->getName()]["requester"]);
if ($requester === null) {
$sender->sendMessage("[ExchangeItem] The requester is currently offline.");
} else {
$item = $this->acception[$sender->getName()]["item"];
$exchange = $this->acception[$sender->getName()]["exchange"];
$i = Item::get($item[0], $item[1], $item[2]);
$e = Item::get($exchange[0], $exchange[1], $exchange[2]);
if ($e->getId() !== 0 and !$sender->getInventory()->contains($e)) {
$requester->sendMessage("[ExchangeItem] Target player doesn't have enough item. Request cancelled.");
$sender->sendMessage("[ExchangeItem] You don't have enough item. Request cancelled.");
// TODO cancel request
return true;
}
if ($i->getId() !== 0 and !$requester->getInventory()->contains($i)) {
$sender->sendMessage("[ExchangeItem] Requester doesn't have enough item. Request cancelled.");
$requester->sendMessage("[ExchangeItem] You don't have enough item to exchange. Request cancelled.");
return true;
}
$sender->getInventory()->addItem($i);
$requester->getInventory()->removeItem($i);
$sender->getInventory()->removeItem($e);
$requester->getInventory()->addItem($e);
$requester->sendMessage("[ExchangeItem] You have exchanged the item with " . $sender->getName());
$sender->sendMessage("[ExchangeItem] You have exchanged the item with " . $requester->getName());
}
} else {
$sender->sendMessage("[ExchangeItem] You have no request to accept.");
return true;
}
return true;
case "decline":
if (isset($this->acception[$sender->getName()])) {
unset($this->acception[$sender->getName()]);
unset($this->request[$this->acception[$sender->getName()]["target"]]);
$sender->sendMessage("[ExchangeItem] Your request have been cancelled.");
} else {
$sender->sendMessage("[ExchangeItem] You have no request to decline.");
return true;
}
case "cancel":
if (isset($this->request[$sender->getName()])) {
unset($this->acception[$this->request[$sender->getName()]]);
unset($this->request[$sender->getName()]);
$sender->sendMessage("[ExchangeItem] You have cancelled the request.");
return true;
} else {
$sender->sendMessage("[ExchangeItem] You have no request to cancel.");
return true;
}
case "item":
if (isset($this->acception[$sender->getName()])) {
$item = $this->acception[$sender->getName()]["item"];
$exchange = $this->acception[$sender->getName()]["exchange"];
$i = Item::get($item[0], $item[1], $item[2]);
$e = Item::get($exchange[0], $exchange[1], $exchange[2]);
$sender->sendMessage("You have requested exchange to " . $this->acception[$sender->getName()]["target"] . "\nYou have to give " . $i->getCount() . " of " . $i->getName() . "\nExchanging with " . $e->getCount() . " of " . $e->getName());
} elseif (isset($this->request[$sender->getName()])) {
$item = $this->acception[$sender->getName()]["item"];
$exchange = $this->acception[$sender->getName()]["exchange"];
$i = Item::get($item[0], $item[1], $item[2]);
$e = Item::get($exchange[0], $exchange[1], $exchange[2]);
$sender->sendMessage("You have got an request from " . $this->acception[$sender->getName()]["target"] . "\nYou have to give : " . $e->getCount() . " of " . $e->getName() . "\nExchanging with " . $i->getCount() . " of " . $i->getName());
} else {
$sender->sendMessage("[ExchangeItem] You don't have any request.");
}
break;
default:
$sender->sendMessage("[ExchangeItem] Usage: " . $command->getUsage());
return true;
}
}
$item = array_shift($params);
$count = array_shift($params);
if (trim($item) === "" or !is_numeric($count)) {
$sender->sendMessage("[ExchangeItem] Usage: /exchange <player> <item> <count>");
}
if (isset($this->request[$sender->getName()])) {
$sender->sendMessage("[ExchangeItem] You already have a request ongoing.");
return true;
}
$playerInst = $this->getServer()->getPlayer($player);
if ($playerInst === null) {
//.........这里部分代码省略.........
示例14: onCommand
//.........这里部分代码省略.........
$amount = array_shift($params);
if (trim($item) === "" or !is_numeric($amount)) {
usage:
$sender->sendMessage("Usage: /itemcloud upload <item ID[:item damage]> <count>");
break;
}
$amount = (int) $amount;
$item = Item::fromString($item);
$item->setCount($amount);
$count = 0;
foreach ($sender->getInventory()->getContents() as $i) {
if ($i->getID() == $item->getID() and $i->getDamage() == $item->getDamage()) {
$count += $i->getCount();
}
}
if ($amount <= $count) {
$this->clouds[strtolower($sender->getName())]->addItem($item->getID(), $item->getDamage(), $amount, true);
$sender->sendMessage("[ItemCloud] Uploaded your item to ItemCloud account.");
} else {
$sender->sendMessage("[ItemCloud] You don't have enough item to upload.");
}
break;
case "download":
if (!$sender->hasPermission("itemcloud.command.download")) {
$sender->sendMessage(TextFormat::RED . "You don't have permission to use this command.");
return true;
}
$name = strtolower($sender->getName());
if (!isset($this->clouds[$name])) {
$sender->sendMessage("[ItemCloud] Please register to the ItemCloud first.");
break;
}
$item = array_shift($params);
$amount = array_shift($params);
if (trim($item) === "" or !is_numeric($amount)) {
usage2:
$sender->sendMessage("Usage: /itemcloud download <item ID[:item damage]> <count>");
break;
}
$amount = (int) $amount;
$item = Item::fromString($item);
$item->setCount($amount);
if (!$this->clouds[$name]->itemExists($item->getID(), $item->getDamage(), $amount)) {
$sender->sendMessage("[ItemCloud] You don't have enough item in your account.");
break;
}
if ($sender->getInventory()->canAddItem($item)) {
$this->clouds[$name]->removeItem($item->getID(), $item->getDamage(), $amount);
$sender->getInventory()->addItem($item);
$sender->sendMessage("[ItemCloud] You have downloaded items from the ItemCloud account.");
} else {
$sender->sendMessage("[ItemCloud] You have no space to download items.");
}
break;
case "list":
if (!$sender->hasPermission("itemcloud.command.list")) {
$sender->sendMessage(TextFormat::RED . "You don't have permission to use this command.");
return true;
}
$name = strtolower($sender->getName());
if (!isset($this->clouds[$name])) {
$sender->sendMessage("[ItemCloud] Please register to the ItemCloud first.");
break;
}
$output = "[ItemCloud] Item list : \n";
foreach ($this->clouds[$name]->getItems() as $item => $count) {
$output .= "{$item} : {$count}\n";
}
$sender->sendMessage($output);
break;
case "count":
if (!$sender->hasPermission("itemcloud.command.count")) {
$sender->sendMessage(TextFormat::RED . "You don't have permission to use this command.");
return true;
}
$name = strtolower($sender->getName());
if (!isset($this->clouds[$name])) {
$sender->sendMessage("[ItemCloud] Please register to the ItemCloud first.");
return true;
}
$item = array_shift($params);
if (trim($item) === "") {
$sender->sendMessage("Usage: /itemcloud count <item>");
return true;
}
$item = Item::fromString($item);
if (($count = $this->clouds[$name]->getCount($item->getID(), $item->getDamage())) === false) {
$sender->sendMessage("[ItemCloud] There are no " . $item->getName() . " in your account.");
break;
} else {
$sender->sendMessage("[ItemCloud] Count of " . $item->getName() . " = " . $count);
}
break;
default:
$sender->sendMessage("[ItemCloud] Usage: " . $command->getUsage());
}
return true;
}
return false;
}
示例15: onCommand
public function onCommand(CommandSender $sender, Command $command, $label, array $params)
{
switch ($command->getName()) {
case "timerban":
$sub = array_shift($params);
switch ($sub) {
case "add":
$player = array_shift($params);
$after = array_shift($params);
$reason = implode(" ", $params);
if (trim($player) === "" or !is_numeric($after)) {
$sender->sendMessage("[TimerBan] Usage: /timerban add <player> <time> [reason..]");
break;
}
$after = round($after, 2);
$secAfter = $after * 3600;
$due = $secAfter + time();
$this->banList->set(strtolower($player), $due);
$this->banList->save();
$sender->sendMessage("[TimerBan] {$player} has been banned for {$after} hour(s).");
if (($player = $this->getServer()->getPlayer($player)) instanceof Player) {
$player->kick("You have been banned for {$after} hour(s).");
}
break;
case "remove":
case "pardon":
$player = array_shift($params);
if (trim($player) === "") {
$sender->sendMessage("[TimerBan] Usage: /timerban remove <player>");
break;
}
if (!$this->banList->exists($player)) {
$sender->sendMessage("[TimerBan] There is no player named \"{$player}\"");
break;
}
$this->banList->remove($player);
$this->banList->save();
$sender->sendMessage("[TimerBan] \"{$player}\" have been removed from the ban list.");
break;
case "list":
$list = $this->banList->getAll();
$output = "Ban list : \n";
foreach ($list as $key => $due) {
$output .= $key . ", ";
}
$output = substr($output, 0, -2);
$sender->sendMessage($output);
break;
default:
$sender->sendMessage("[TimerBan] Usage: " . $command->getUsage());
}
break;
case "timerbanip":
$sub = array_shift($params);
switch ($sub) {
case "add":
$ip = array_shift($params);
$after = array_shift($params);
$reason = implode(" ", $params);
if (trim($ip) === "" or !is_numeric($after)) {
$sender->sendMessage("[TimerBan] Usage: /timerban <player> <time> [reason..]");
break;
}
$after = round($after, 2);
$secAfter = $after * 3600;
if (filter_var($ip, FILTER_VALIDATE_IP)) {
foreach ($this->getServer()->getOnlinePlayers() as $player) {
if ($player->getAddress() === $ip) {
$player->kick("You have been banned for {$after} hour(s).");
break;
}
}
} else {
$player = $this->getServer()->getPlayer($ip);
if ($player instanceof Player) {
$ip = $player->getAddress();
$player->kick("You have been banned for {$after} hour(s).");
}
}
$due = $secAfter + time();
$this->ipBanList->set($ip, $due);
$this->ipBanList->save();
$sender->sendMessage("[TimerBan] {$ip} has been banned for {$after} hours.");
break;
case "remove":
case "pardon":
$player = array_shift($params);
if (trim($player) === "") {
$sender->sendMessage("[TimerBan] Usage: /timerban remove <player>");
break;
}
if (!$this->ipBanList->exists($player)) {
$sender->sendMessage("[TimerBan] There is no player with IP \"{$player}\"");
break;
}
$this->ipBanList->remove($player);
$this->ipBanList->save();
$sender->sendMessage("[TimerBan] \"{$player}\" have been removed from the ban list.");
break;
case "list":
//.........这里部分代码省略.........