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; }
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; }
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; } }
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; } } }
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())); } } } }
/** * 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); }
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; } }
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; } }
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; }
public function onCommand(CommandSender $sender, Command $command, $label, array $params) { switch ($command->getName()) { case "auction": $sub = array_shift($params); switch ($sub) { case "start": if (!$sender instanceof Player) { $sender->sendMessage("Please run this command in-game."); break; } if (isset($this->auctions[$sender->getName()])) { $sender->sendMessage("You already have ongoing auction"); break; } $tax = $this->getConfig()->get("auction-tax"); if ($tax > EconomyAPI::getInstance()->myMoney($sender)) { $sender->sendMessage("You don't have enough money to start auction. Auction tax : " . $tax); break; } $item = array_shift($params); $count = (int) array_shift($params); $startPrice = array_shift($params); if (trim($item) === "" or trim($count) === "" or trim($startPrice) === "") { $sender->sendMessage("Usage: /auction start <item> <count> <start price>"); 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 += $i->getCount(); if ($count <= $cnt) { break; } } } if ($count <= $cnt) { $sender->getInventory()->removeItem(new Item($e[0], $e[1], $count)); $this->auctions[strtolower($sender->getName())] = array($e[0], $e[1], (int) $count, (int) $startPrice, null, (int) $startPrice, null, null); $this->getServer()->broadcastMessage(TextFormat::GREEN . $sender->getName() . TextFormat::RESET . "'s auction has just started."); EconomyAPI::getInstance()->reduceMoney($sender, $tax); } else { $sender->sendMessage("You don't have enough items"); } break; case "stop": $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; } }
public function onCommand(CommandSender $sender, Command $cmd, $label, array $param) { switch ($cmd->getName()) { case "startp": if (!$sender instanceof Player) { $sender->sendMessage($this->getMessage("run-cmd-in-game")); return true; } $x = floor($sender->x); $z = floor($sender->z); $level = $sender->getLevel()->getFolderName(); $this->start[$sender->getName()] = array("x" => $x, "z" => $z, "level" => $level); $sender->sendMessage($this->getMessage("first-position-saved")); return true; case "endp": if (!$sender instanceof Player) { $sender->sendMessage($this->getMessage("run-cmd-in-game")); return true; } if (!isset($this->start[$sender->getName()])) { $sender->sendMessage($this->getMessage("set-first-position")); return true; } if ($sender->getLevel()->getFolderName() !== $this->start[$sender->getName()]["level"]) { $sender->sendMessage($this->getMessage("cant-set-position-in-different-world")); return true; } $startX = $this->start[$sender->getName()]["x"]; $startZ = $this->start[$sender->getName()]["z"]; $endX = floor($sender->x); $endZ = floor($sender->z); $this->end[$sender->getName()] = array("x" => $endX, "z" => $endZ); if ($startX > $endX) { $temp = $endX; $endX = $startX; $startX = $temp; } if ($startZ > $endZ) { $temp = $endZ; $endZ = $startZ; $startZ = $temp; } $startX--; $endX++; $startZ--; $endZ++; $price = ($endX - $startX - 1) * ($endZ - $startZ - 1) * $this->config->get("price-per-y-axis"); $sender->sendMessage($this->getMessage("confirm-buy-land", array($price, "%2", "%3"))); return true; case "land": $sub = array_shift($param); switch ($sub) { case "buy": if (!$sender->hasPermission("economyland.command.land.buy")) { $sender->sendMessage($this->getMessage("no-permission-command")); return true; } if (!$sender instanceof Player) { $sender->sendMessage($this->getMessage("run-cmd-in-game")); return true; } if (in_array($sender->getLevel()->getFolderName(), $this->config->get("buying-disallowed-worlds"))) { $sender->sendMessage($this->getMessage("not-allowed-to-buy")); return true; } $cnt = count($this->db->getLandsByOwner($sender->getName())); if (is_numeric($this->config->get("player-land-limit"))) { if ($cnt >= $this->config->get("player-land-limit")) { $sender->sendMessage($this->getMessage("land-limit", array($cnt, $this->config->get("player-land-limit"), "%3", "%4"))); return true; } } if (!isset($this->start[$sender->getName()])) { $sender->sendMessage($this->getMessage("set-first-position")); return true; } elseif (!isset($this->end[$sender->getName()])) { $sender->sendMessage($this->getMessage("set-second-position")); return true; } $l = $this->start[$sender->getName()]; $endp = $this->end[$sender->getName()]; $startX = floor($l["x"]); $endX = floor($endp["x"]); $startZ = floor($l["z"]); $endZ = floor($endp["z"]); if ($startX > $endX) { $backup = $startX; $startX = $endX; $endX = $backup; } if ($startZ > $endZ) { $backup = $startZ; $startZ = $endZ; $endZ = $backup; } $result = $this->db->checkOverlap($startX, $endX, $startZ, $endZ, $sender->getLevel()->getFolderName()); if ($result) { $sender->sendMessage($this->getMessage("land-around-here", array($result["owner"], $result["ID"], "%3"))); return true; } $price = ($endX + 1 - ($startX - 1) - 1) * ($endZ + 1 - ($startZ - 1) - 1) * $this->config->get("price-per-y-axis"); if (EconomyAPI::getInstance()->reduceMoney($sender, $price, true, "EconomyLand") === EconomyAPI::RET_INVALID) { $sender->sendMessage($this->getMessage("no-money-to-buy-land")); return true; } $this->db->addLand($startX, $endX, $startZ, $endZ, $sender->getLevel()->getFolderName(), $price, $sender->getName()); unset($this->start[$sender->getName()], $this->end[$sender->getName()]); $sender->sendMessage($this->getMessage("bought-land", array($price, "%2", "%3"))); break; case "list": if (!$sender->hasPermission("economyland.command.land.list")) { $sender->sendMessage($this->getMessage("no-permission-command")); return true; } $page = isset($param[0]) ? (int) $param[0] : 1; $land = $this->db->getAll(); $output = ""; $max = ceil(count($land) / 5); $pro = 1; $page = (int) $page; $output .= $this->getMessage("land-list-top", array($page, $max, "")); $current = 1; foreach ($land as $l) { $cur = (int) ceil($current / 5); if ($cur > $page) { continue; } if ($pro == 6) { break; } if ($page === $cur) { $output .= $this->getMessage("land-list-format", array($l["ID"], ($l["endX"] + 1 - ($l["startX"] - 1) - 1) * ($l["endZ"] + 1 - ($l["startZ"] - 1) - 1), $l["owner"])); $pro++; } $current++; } $sender->sendMessage($output); break; case "whose": if (!$sender->hasPermission("economyland.command.land.whose")) { $sender->sendMessage($this->getMessage("no-permission-command")); return true; } $player = array_shift($param); $alike = true; if (str_replace(" ", "", $player) === "") { $player = $sender->getName(); $alike = false; } if ($alike) { $lands = $this->db->getLandsByKeyword($player); } else { $lands = $this->db->getLandsByOwner($player); } $sender->sendMessage("Results from query : {$player}\n"); foreach ($lands as $info) { $sender->sendMessage($this->getMessage("land-list-format", array($info["ID"], ($info["endX"] + 1 - ($info["startX"] - 1) - 1) * ($info["endZ"] + 1 - ($info["startZ"] - 1) - 1), $info["owner"]))); } break; case "move": if (!$sender instanceof Player) { $sender->sendMessage($this->getMessage("run-cmd-in-game")); return true; } if (!$sender->hasPermission("economyland.command.land.move")) { $sender->sendMessage($this->getMessage("no-permission-command")); return true; } $num = array_shift($param); if (trim($num) == "") { $sender->sendMessage("Usage: /land move <land num>"); return true; } if (!is_numeric($num)) { $sender->sendMessage("Usage: /land move <land num>"); return true; } $info = $this->db->getLandById($num); if ($info === false) { $sender->sendMessage($this->getMessage("no-land-found", array($num, "", ""))); return true; } if ($info["owner"] !== $sender->getName()) { if (!$sender->hasPermission("economyland.land.move.others")) { $sender->sendMessage($this->getMessage("no-permission-move", [$info["ID"], $info["owner"], "%3"])); return true; } } $level = $this->getServer()->getLevelByName($info["level"]); if (!$level instanceof Level) { $sender->sendMessage($this->getMessage("land-corrupted", array($num, $info["level"], ""))); return true; } $x = (int) ($info["startX"] + ($info["endX"] - $info["startX"]) / 2); $z = (int) ($info["startZ"] + ($info["endZ"] - $info["startZ"]) / 2); $cnt = 0; for ($y = 128;; $y--) { $vec = new Vector3($x, $y, $z); if ($level->getBlock($vec)->isSolid()) { $y++; break; } if ($cnt === 5) { break; } if ($y <= 0) { ++$cnt; ++$x; --$z; $y = 128; continue; } } $sender->teleport(new Position($x + 0.5, $y + 0.1, $z + 0.5, $level)); $sender->sendMessage($this->getMessage("success-moving", array($num, "", ""))); return true; case "give": if (!$sender instanceof Player) { $sender->sendMessage($this->getMessage("run-cmd-in-game")); return true; } if (!$sender->hasPermission("economyland.command.land.give")) { $sender->sendMessage($this->getMessage("no-permission-command")); return true; } $player = array_shift($param); $landnum = array_shift($param); if (trim($player) == "" or trim($landnum) == "" or !is_numeric($landnum)) { $sender->sendMessage("Usage: /{$cmd} give <player> <land number>"); return true; } $username = $player; $player = $this->getServer()->getPlayer($username); if (!$player instanceof Player) { $sender->sendMessage($this->getMessage("player-not-connected", [$username, "%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->getName() !== $info["owner"] and !$sender->hasPermission("economyland.land.give.others")) { $sender->sendMessage($this->getMessage("not-your-land", array($landnum, "%2", "%3"))); } else { if ($sender->getName() === $player->getName()) { $sender->sendMessage($this->getMessage("cannot-give-land-myself")); } else { if (is_numeric($this->config->get("player-land-limit"))) { $cnt = count($this->db->getLandsByOwner($player->getName())); if ($cnt >= $this->config->get("player-land-limit")) { $sender->sendMessage($this->getMessage("give-land-limit", array($player->getName(), $cnt, $this->config->get("player-land-limit"), "%4"))); return true; } } $this->db->setOwnerById($info["ID"], $player->getName()); $sender->sendMessage($this->getMessage("gave-land", array($landnum, $player->getName(), "%3"))); $player->sendMessage($this->getMessage("got-land", array($sender->getName(), $landnum, "%3"))); } } return true; case "invite": if (!$sender->hasPermission("economyland.command.land.invite")) { $sender->sendMessage($this->getMessage("no-permission-command")); return true; } $landnum = array_shift($param); $player = array_shift($param); if (trim($player) == "" or trim($landnum) == "") { $sender->sendMessage("Usage : /land <invite> <land number> <[r:]player>"); 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; } 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"; $output .= implode(", ", $info); $sender->sendMessage($output); return true; case "here": if (!$sender instanceof Player) { $sender->sendMessage($this->getMessage("run-cmd-in-game")); return true; } $x = $sender->x; $z = $sender->z; $info = $this->db->getByCoord($x, $z, $sender->getLevel()->getFolderName()); if ($info === false) { $sender->sendMessage($this->getMessage("no-one-owned")); return true; } $sender->sendMessage($this->getMessage("here-land", array($info["ID"], $info["owner"], "%3"))); return true; default: $sender->sendMessage("Usage: " . $cmd->getUsage()); } return true; case "landsell": $id = array_shift($param); switch ($id) { case "here": if (!$sender instanceof Player) { $sender->sendMessage($this->getMessage("run-cmd-in-game")); return true; } $x = $sender->getX(); $z = $sender->getZ(); $info = $this->db->getByCoord($x, $z, $sender->getLevel()->getFolderName()); if ($info === false) { $sender->sendMessage($this->getMessage("no-one-owned")); return true; } if ($info["owner"] !== $sender->getName() and !$sender->hasPermission("economyland.landsell.others")) { $sender->sendMessage($this->getMessage("not-my-land")); } else { EconomyAPI::getInstance()->addMoney($sender, $info["price"] / 2); $sender->sendMessage($this->getMessage("sold-land", array($info["price"] / 2, "%2", "%3"))); //$this->land->exec("DELETE FROM land WHERE ID = {$info["ID"]}"); $this->db->removeLandById($info["ID"]); } return true; default: $p = $id; if (is_numeric($p)) { $info = $this->db->getLandById($p); if ($info === false) { $sender->sendMessage($this->getMessage("no-land-found", array($p, "%2", "%3"))); return true; } if ($info["owner"] === $sender->getName() or $sender->hasPermission("economyland.landsell.others")) { EconomyAPI::getInstance()->addMoney($sender, $info["price"] / 2, true, "EconomyLand"); $sender->sendMessage($this->getMessage("sold-land", array($info["price"] / 2, "", ""))); $this->db->removeLandById($p); } else { $sender->sendMessage($this->getMessage("not-your-land", array($p, $info["owner"], "%3"))); } } else { $sender->sendMessage("Usage: /landsell <here|land number>"); } } return true; } return false; }
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; }
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) { $sender->sendMessage("[ExchangeItem] Your requested player is not online."); return true; } $exchange = Item::fromString($item); if ($exchange->getId() == 0) { $sender->sendMessage("[ExchangeItem] There's no item called " . $item); return true; } $count = (int) $count; $exchange->setCount($count); if (!$playerInst->getInventory()->contains($exchange)) { $sender->sendMessage($playerInst->getName() . " doesn't have requested item."); return true; } $this->request[$sender->getName()] = $playerInst->getName(); $item = $sender->getInventory()->getItemInHand(); $this->acception[$playerInst->getName()] = ["item" => [$item->getId(), $item->getDamage(), $item->getCount()], "exchange" => [$exchange->getId(), $exchange->getDamage(), $exchange->getCount()], "requester" => $sender->getName()]; $sender->sendMessage("[ExchangeItem] You have sent an exchange request to " . $playerInst->getName()); $playerInst->sendMessage("[ExchangeItem] You have got an item exchange request from " . $sender->getName() . "\nItem :" . $item->getCount() . " of " . $item->getName() . "\nExchanging with " . $exchange->getCount() . " of " . $exchange->getName()); return true; } }
public function onCommand(CommandSender $sender, Command $command, $label, array $params) { switch ($command->getName()) { case "itemcloud": if (!$sender instanceof Player) { $sender->sendMessage("Please run this command in-game"); return true; } $sub = array_shift($params); switch ($sub) { case "register": if (!$sender->hasPermission("itemcloud.command.register")) { $sender->sendMessage(TextFormat::RED . "You don't have permission to use this command."); return true; } if (isset($this->clouds[strtolower($sender->getName())])) { $sender->sendMessage("[ItemCloud] You already have your ItemCloud account"); break; } $this->clouds[strtolower($sender->getName())] = new ItemCloud([], $sender->getName()); $sender->sendMessage("[ItemCloud] Registered to the ItemCloud account"); break; case "upload": if (!$sender->hasPermission("itemcloud.command.upload")) { $sender->sendMessage(TextFormat::RED . "You don't have permission to use this command."); return true; } if (!isset($this->clouds[strtolower($sender->getName())])) { $sender->sendMessage("[ItemCloud] Please register to the ItemCloud service first."); break; } $item = array_shift($params); $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; }
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": $list = $this->ipBanList->getAll(); $output = "IP 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()); } } return true; }
public function onCommand(CommandSender $sender, Command $command, $label, array $args) { switch ($command->getName()) { case "login": if ($sender instanceof Player) { if (!$this->isPlayerRegistered($sender) or ($data = $this->provider->getPlayer($sender)) === null) { $sender->sendMessage(TextFormat::RED . $this->getMessage("login.error.registered")); return true; } if (count($args) !== 1) { $sender->sendMessage(TextFormat::RED . "사용법: " . $command->getUsage()); return true; } $password = implode(" ", $args); if (hash_equals($data["hash"], $this->hash(strtolower($sender->getName()), $password)) and $this->authenticatePlayer($sender)) { return true; } else { $this->tryAuthenticatePlayer($sender); $sender->sendMessage(TextFormat::RED . $this->getMessage("login.error.password")); return true; } } else { $sender->sendMessage(TextFormat::RED . "이 명령어는 게임 내에서만 작동합니다."); return true; } break; case "register": if ($sender instanceof Player) { if ($this->isPlayerRegistered($sender)) { $sender->sendMessage(TextFormat::RED . $this->getMessage("register.error.registered")); return true; } $password = implode(" ", $args); if (strlen($password) < $this->getConfig()->get("minPasswordLength")) { $sender->sendMessage($this->getMessage("register.error.password")); return true; } if ($this->registerPlayer($sender, $password) and $this->authenticatePlayer($sender)) { return true; } else { $sender->sendMessage(TextFormat::RED . $this->getMessage("register.error.general")); return true; } } else { $sender->sendMessage(TextFormat::RED . "이 명령어는 게임 내에서만 작동합니다."); return true; } break; } return false; }
public function onCommand(CommandSender $sender, Command $cmd, $label, array $param) { switch ($cmd->getName()) { case "startp": if (!$sender instanceof Player) { $sender->sendMessage("Please run this command in-game."); return true; } $x = (int) $sender->x; $z = (int) $sender->z; $level = $sender->getLevel()->getFolderName(); $this->start[$sender->getName()] = array("x" => $x, "z" => $z, "level" => $level); $sender->sendMessage($this->getMessage("first-position-saved")); return true; case "endp": if (!$sender instanceof Player) { $sender->sendMessage("Please run this command in-game."); return true; } if (!isset($this->start[$sender->getName()])) { $sender->sendMessage($this->getMessage("set-first-position")); return true; } if ($sender->getLevel()->getFolderName() !== $this->start[$sender->getName()]["level"]) { $sender->sendMessage($this->getMessage("cant-set-position-in-different-world")); return true; } $startX = $this->start[$sender->getName()]["x"]; $startZ = $this->start[$sender->getName()]["z"]; $endX = (int) $sender->x; $endZ = (int) $sender->z; $this->end[$sender->getName()] = array("x" => $endX, "z" => $endZ); if ($startX > $endX) { $temp = $endX; $endX = $startX; $startX = $temp; } if ($startZ > $endZ) { $temp = $endZ; $endZ = $startZ; $startZ = $temp; } $startX--; $endX++; $startZ--; $endZ++; $price = ($endX - $startX - 1) * ($endZ - $startZ - 1) * $this->config->get("price-per-y-axis"); $sender->sendMessage($this->getMessage("confirm-buy-land", array($price, "%2", "%3"))); return true; case "land": $sub = array_shift($param); switch ($sub) { case "buy": if (!$sender->hasPermission("economyland.command.land.buy")) { return true; } if (!$sender instanceof Player) { $sender->sendMessage("Please run this command in-game."); return true; } if (in_array($sender->getLevel()->getFolderName(), $this->config->get("buying-disallowed-worlds"))) { $sender->sendMessage($this->getMessage("not-allowed-to-buy")); return true; } // $result = $this->land->query("SELECT * FROM land WHERE owner = '{$sender->getName()}'"); $cnt = count($this->db->getLandsByOwner($sender->getName())); if (is_numeric($this->config->get("player-land-limit"))) { if ($cnt >= $this->config->get("player-land-limit")) { $sender->sendMessage($this->getMessage("land-limit", array($cnt, $this->config->get("player-land-limit"), "%3", "%4"))); return true; } /* while($result->fetchArray(SQLITE3_ASSOC) !== false){ ++$cnt; if($cnt >= $this->config->get("player-land-limit")){ $sender->sendMessage($this->getMessage("land-limit", array($cnt, $this->config->get("player-land-limit")))); return true; } }*/ } if (!isset($this->start[$sender->getName()])) { $sender->sendMessage($this->getMessage("set-first-position")); return true; } elseif (!isset($this->end[$sender->getName()])) { $sender->sendMessage($this->getMessage("set-second-position")); return true; } $l = $this->start[$sender->getName()]; $endp = $this->end[$sender->getName()]; $startX = (int) $l["x"]; $endX = (int) $endp["x"]; $startZ = (int) $l["z"]; $endZ = (int) $endp["z"]; if ($startX > $endX) { $backup = $startX; $startX = $endX; $endX = $backup; } if ($startZ > $endZ) { $backup = $startZ; $startZ = $endZ; $endZ = $backup; } /*$result = $this->land->query("SELECT * FROM land WHERE startX <= $endX AND endX >= $endX AND startZ <= $endZ AND endZ >= $endZ AND level = '{$sender->getLevel()->getFolderName()}'")->fetchArray(SQLITE3_ASSOC); if(!is_bool($result)){ $sender->sendMessage($this->getMessage("land-around-here", array($result["owner"], "", ""))); return true; }*/ $result = $this->db->checkOverlap($startX, $endX, $startZ, $endZ, $sender->getLevel()->getFolderName()); if ($result) { $sender->sendMessage($this->getMessage("land-around-here", array($result["owner"], "%2", "%3"))); return true; } $price = ($endX + 1 - ($startX - 1) - 1) * ($endZ + 1 - ($startZ - 1) - 1) * $this->config->get("price-per-y-axis"); if (EconomyAPI::getInstance()->reduceMoney($sender, $price, true, "EconomyLand") === EconomyAPI::RET_INVALID) { $sender->sendMessage($this->getMessage("no-money-to-buy-land")); return true; } // $this->land->exec("INSERT INTO land (startX, endX, startZ, endZ, owner, level, price, invitee) VALUES ($startX, $endX, $startZ, $endZ, '{$sender->getName()}', '{$this->start[$sender->getName()]["level"]}', $price, ',')"); $this->db->addLand($startX, $endX, $startZ, $endZ, $sender->getLevel()->getFolderName(), $price, $sender->getName()); unset($this->start[$sender->getName()], $this->end[$sender->getName()]); $sender->sendMessage($this->getMessage("bought-land", array($price, "%2", "%3"))); break; case "list": if (!$sender->hasPermission("economyland.command.land.list")) { return true; } $page = isset($param[0]) ? (int) $param[0] : 1; $land = $this->db->getAll(); $output = ""; $max = ceil(count($land) / 5); $pro = 1; $page = (int) $page; $output .= $this->getMessage("land-list-top", array($page, $max, "")); $current = 1; foreach ($land as $l) { $cur = (int) ceil($current / 5); if ($cur > $page) { continue; } if ($pro == 6) { break; } if ($page === $cur) { $output .= $this->getMessage("land-list-format", array($l["ID"], ($l["endX"] - $l["startX"]) * ($l["endZ"] - $l["startZ"]), $l["owner"])); $pro++; } $current++; } $sender->sendMessage($output); break; case "whose": if (!$sender->hasPermission("economyland.command.land.whose")) { return true; } $player = array_shift($param); $alike = true; if (str_replace(" ", "", $player) === "") { $player = $sender->getName(); $alike = false; } /// $result = $this->land->query("SELECT * FROM land WHERE owner ".($alike ? "LIKE '%".$player."%'" : "= '".$player."'")); if ($alike) { $lands = $this->db->getLandsByKeyword($player); } else { $lands = $this->db->getLandsByOwner($player); } $sender->sendMessage("Results from query : {$player}\n"); // while(($info = $result->fetchArray(SQLITE3_ASSOC)) !== false){ foreach ($lands as $info) { $sender->sendMessage($this->getMessage("land-list-format", array($info["ID"], ($info["endX"] - $info["startX"]) * ($info["endZ"] - $info["startZ"]), $info["owner"]))); } //} break; case "move": if (!$sender instanceof Player) { $sender->sendMessage("Please run this command in-game."); return true; } if (!$sender->hasPermission("economyland.command.land.move")) { return true; } $num = array_shift($param); if (trim($num) == "") { $sender->sendMessage("Usage: /land move <land num>"); return true; } if (!is_numeric($num)) { $sender->sendMessage("Usage: /land move <land num>"); return true; } //$result = $this->land->query("SELECT * FROM land WHERE ID = $num"); // $info = $result->fetchArray(SQLITE3_ASSOC); $info = $this->db->getLandById($num); if ($info === false) { $sender->sendMessage($this->getMessage("no-land-found", array($num, "", ""))); return true; } if ($info["owner"] !== $sender->getName()) { if (!$sender->hasPermission("economyland.land.move.others")) { $sender->sendMessage($this->getMessage("no-permission-move", [$info["ID"], $info["owner"], "%3"])); return true; } } $level = $this->getServer()->getLevelByName($info["level"]); if (!$level instanceof Level) { $sender->sendMessage($this->getMessage("land-corrupted", array($num, "", ""))); return true; } $x = (int) $info["startX"] + ($info["endX"] - $info["startX"]) / 2; $z = (int) $info["startZ"] + ($info["endZ"] - $info["startZ"]) / 2; $cnt = 0; for ($y = 1;; $y++) { if ($level->getBlock(new Vector3($x, $y, $z))->getID() === 0) { break; } if ($cnt === 5) { break; } if ($y > 255) { ++$cnt; ++$x; --$z; $y = 1; continue; } } $sender->teleport(new Position($x, $y, $z, $level)); $sender->sendMessage($this->getMessage("success-moving", array($num, "", ""))); return true; case "give": if (!$sender instanceof Player) { $sender->sendMessage("Please run this command in-game."); return true; } if (!$sender->hasPermission("economyland.command.land.give")) { return true; } $player = array_shift($param); $landnum = array_shift($param); if (trim($player) == "" or trim($landnum) == "" or !is_numeric($landnum)) { $sender->sendMessage("Usage: /{$cmd} give <player> <land number>"); return true; } $username = $player; $player = $this->getServer()->getPlayer($username); if (!$player instanceof Player) { $sender->sendMessage($this->getMessage("player-not-connected", [$username, "%2", "%3"])); return true; } // $info = $this->land->query("SELECT * FROM land WHERE ID = $landnum")->fetchArray(SQLITE3_ASSOC); $info = $this->db->getLandById($landnum); if ($info === false) { $sender->sendMessage($this->getMessage("no-land-found", array($landnum, "%2", "%3"))); return true; } if ($sender->getName() !== $info["owner"] and !$sender->hasPermission("economyland.land.give.others")) { $sender->sendMessage($this->getMessage("not-your-land", array($landnum, "%2", "%3"))); } else { if ($sender->getName() === $player->getName()) { $sender->sendMessage($this->getMessage("cannot-give-land-myself")); } else { // $this->land->exec("UPDATE land SET owner = '{$player->getName()}' WHERE ID = {$info["ID"]}"); $this->db->setOwnerById($info["ID"], $player->getName()); $sender->sendMessage($this->getMessage("gave-land", array($landnum, $player->getName(), "%3"))); $player->sendMessage($this->getMessage("got-land", array($sender->getName(), $landnum, "%3"))); } } return true; case "invite": if (!$sender->hasPermission("economyland.command.land.invite")) { $sender->sendMessage("You don't have permissions to use this command."); return true; } $landnum = array_shift($param); $player = array_shift($param); if (trim($player) == "" or trim($landnum) == "") { $sender->sendMessage("Usage : /land <invite> <land number> <[r:]player>"); return true; } if (!is_numeric($landnum)) { $sender->sendMessage($this->getMessage("land-num-must-numeric", array($landnum, "%2", "%3"))); return true; } //$result = $this->land->query("SELECT * FROM land WHERE ID = $landnum"); //$info = $result->fetchArray(SQLITE3_ASSOC); $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; } elseif (substr($player, 0, 2) === "r:") { if (!$sender->hasPermission("economyland.command.land.invite.remove")) { $sender->sendMessage("You don't have permissions to use this command."); return true; } $player = substr($player, 2); //$this->land->exec("UPDATE land SET invitee = '".str_replace($player.",", "", $info["invitee"])."' WHERE ID = {$info["ID"]};"); $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"))); } else { /*if(strpos($info["invitee"], ",".$player.",") !== false){ $sender->sendMessage($this->getMessage("already-invitee", array($player, "", ""))); return true; } $this->land->exec("UPDATE land SET invitee = '".$info["invitee"].$player.",' WHERE ID = {$info["ID"]};");*/ 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 "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"; $output .= implode(", ", $info); $sender->sendMessage($output); return true; case "here": if (!$sender instanceof Player) { $sender->sendMessage("Please run this command in-game."); return true; } $x = $sender->x; $z = $sender->z; $info = $this->db->getByCoord($x, $z, $sender->getLevel()->getFolderName()); if ($info === false) { $sender->sendMessage($this->getMessage("no-one-owned")); return true; } $sender->sendMessage($this->getMessage("here-land", array($info["ID"], $info["owner"], "%3"))); return true; default: $sender->sendMessage("Usage: " . $cmd->getUsage()); } return true; case "landsell": $id = array_shift($param); switch ($id) { case "here": if (!$sender instanceof Player) { $sender->sendMessage("Please run this command in-game."); return true; } $x = $sender->getX(); $z = $sender->getZ(); //$result = $this->land->query("SELECT * FROM land WHERE (startX < $x AND endX > $x) AND (startZ < $z AND endZ > $z) AND level = '{$sender->getLevel()->getFolderName()}'"); //$info = $result->fetchArray(SQLITE3_ASSOC); $info = $this->db->getByCoord($x, $z, $sender->getLevel()->getFolderName()); if ($info === false) { $sender->sendMessage($this->getMessage("no-one-owned")); return true; } if ($info["owner"] !== $sender->getName() and !$sender->hasPermission("economyland.landsell.others")) { $sender->sendMessage($this->getMessage("not-my-land")); } else { EconomyAPI::getInstance()->addMoney($sender, $info["price"] / 2); $sender->sendMessage($this->getMessage("sold-land", array($info["price"] / 2, "%2", "%3"))); //$this->land->exec("DELETE FROM land WHERE ID = {$info["ID"]}"); $this->db->removeLandById($info["ID"]); } return true; default: $p = $id; if (is_numeric($p)) { //$info = $this->land->query("SELECT * FROM land WHERE ID = $p")->fetchArray(SQLITE3_ASSOC); $info = $this->db->getLandById($p); if ($info === false) { $sender->sendMessage($this->getMessage("no-land-found", array($p, "%2", "%3"))); return true; } if ($info["owner"] === $sender->getName() or $sender->hasPermission("economyland.landsell.others")) { EconomyAPI::getInstance()->addMoney($sender, $info["price"] / 2, true, "EconomyLand"); $sender->sendMessage($this->getMessage("sold-land", array($info["price"] / 2, "", ""))); //$this->land->exec("DELETE FROM land WHERE ID = $p"); $this->db->removeLandById($p); } else { $sender->sendMessage($this->getMessage("not-your-land", array($p, $info["owner"], "%3"))); } } else { $sender->sendMessage("Usage: /landsell <here|land number>"); } } return true; } return false; }
public function onCommand(CommandSender $sender, Command $command, $label, array $params) { switch ($command->getName()) { case "casino": $sub = array_shift($params); switch ($sub) { case "start": if (!$sender instanceof Player) { $sender->sendMessage("Please run this command in-game."); break; } if (!$sender->hasPermission("economycasino.command.casino.start")) { return true; } if ($this->config->get("max-game") <= count($this->casino)) { $sender->sendMessage("There are too many games in progress. Please join the other games."); break; } if (isset($this->casino[$sender->getName()])) { $sender->sendMessage("You already have joined casino."); return true; } else { foreach ($this->casino as $player => $casino) { if (isset($casino["players"][$sender->getName()])) { $sender->sendMessage("You already have joined casino."); return true; } } } $this->casino[$sender->getName()] = array("players" => array($sender->getName() => true)); $this->getServer()->broadcastMessage("[EconomyCasino] Casino of " . $sender->getName() . " has just started."); break; case "stop": if (!$sender instanceof Player) { $sender->sendMessage("Please run this command in-game."); break; } if (!$sender->hasPermission("economycasino.command.casino.stop")) { return true; } if ($sender instanceof Player and !$sender->isOp()) { if (isset($this->casino[$sender->getName()])) { foreach ($this->casino[$sender->getName()]["players"] as $player => $v) { $this->getServer()->getPlayerExact($player)->sendMessage("[EconomyCasino] You have left the casino due to stop."); } unset($this->casino[$sender->getName()]); $sender->sendMessage("You have stopped your casino."); } else { $sender->sendMessage("You don't have any casino game to quit."); } } else { $player = array_shift($params); if (trim($player) === "") { $sender->sendMessage("Usage: /casino stop <player>"); break; } if (isset($this->casino[$player])) { foreach ($this->casino[$player]["players"] as $player => $v) { $this->getServer()->getPlayerExact($player)->sendMessage("[EconomyCasino] You have left the casino game due to stop."); } $sender->sendMessage("[EconomyCasino] The game by \"{$player}\" has successfully stopped."); unset($this->casino[$player]); } } break; case "join": if (!$sender instanceof Player) { $sender->sendMessage("Please run this command in-game."); break; } if (!$sender->hasPermission("economycasino.command.casino.join")) { return true; } $player = array_shift($params); if (trim($player) === "") { $sender->sendMessage("Usage: /casino join <player>"); break; } if (isset($this->casino[$player])) { foreach ($this->casino[$player]["players"] as $player => $v) { if (($p = $this->getServer()->getPlayerExact($player)) instanceof Player) { $p->sendMessage("[EconomyCasino] " . $sender->getName() . " has joined the game."); } } $this->casino[$player]["players"][$sender->getName()] = true; $sender->sendMessage("You've joined the casino."); } else { $sender->sendMessage("There's no casino where are looking for."); } break; case "leave": if (!$sender instanceof Player) { $sender->sendMessage("Please run this command in-game."); break; } if (!$sender->hasPermission("economycasino.command.casino.leave")) { return true; } foreach ($this->casino as $player => $casino) { if (isset($casino["players"][$sender->getName()])) { unset($this->casino[$player]["players"][$sender->getName()]); foreach ($casino["players"] as $p => $v) { $this->getServer()->getPlayerExact($p)->sendMessage("[EconomyCasino] " . $sender->getName() . " left the game."); } break; } } $sender->sendMessage("[EconomyCasino] You have no casino game to leave."); break; case "list": if (!$sender->hasPermission("economycasino.command.casino.list")) { return true; } $player = array_shift($params); if (trim($player) === "") { list_general: $output = "[EconomyCasino] Game list : \n"; foreach ($this->casino as $player => $casino) { $output .= "{$player} : " . count($this->casino[$player]["players"]) . " \n"; } $output = substr($output, 0, -2); $sender->sendMessage($output); } else { if (isset($this->casino[$player])) { $output = "[EconomyCasino] Player list of casino game by : {$player} \n"; foreach ($this->casino[$player]["players"] as $p) { $output .= "{$p}, "; } $output = substr($output, 0, -2); } else { goto list_general; } } break; case "gamble": if (!$sender instanceof Player) { $sender->sendMessage("Please run this command in-game."); break; } if (!$sender->hasPermission("economycasino.command.casino.gamble")) { return true; } $money = array_shift($params); if (!is_numeric($money)) { $sender->sendMessage("Usage: /casino gamble <money>"); break; } $money = (int) $money; if ($this->api->myMoney($sender) < $money) { $sender->sendMessage("You don't have money to gamble " . $this->api->getMonetaryUnit() . "{$money}"); break; } if (isset($this->casino[$sender->getName()])) { $all = 0; foreach ($this->casino[$sender->getName()]["players"] as $player => $v) { $tmp = min($money, $this->api->myMoney($player)); $this->api->reduceMoney($player, $tmp); $all += $tmp; } $got = array_rand($this->casino[$sender->getName()]["players"]); $this->api->addMoney($got, $all, true, "EconomyCasino"); foreach ($this->casino[$sender->getName()]["players"] as $p => $v) { if ($got === $p) { $this->getServer()->getPlayerExact($p)->sendMessage("You've win " . $this->api->getMonetaryUnit() . "{$all}!"); } else { $this->getServer()->getPlayerExact($p)->sendMessage("You've lost " . $this->api->getMonetaryUnit() . "{$money}"); } } } else { foreach ($this->casino as $player => $casino) { if (isset($casino["players"][$sender->getName()])) { $all = 0; foreach ($this->casino[$player]["players"] as $p => $true) { $tmp = min($this->api->myMoney($p), $money); $this->api->reduceMoney($p, $tmp); $all += $tmp; } $got = array_rand($this->casino[$player]["players"]); $this->api->addMoney($got, $all, true, "EconomyCasino"); foreach ($this->casino[$player]["players"] as $p => $v) { if ($got === $p) { $this->getServer()->getPlayerExact($p)->sendMessage("You've win " . $this->api->getMonetaryUnit() . "{$all}!"); } else { $this->getServer()->getPlayerExact($p)->sendMessage("You've lost " . $this->api->getMonetaryUnit() . "{$money}"); } } } } } break; default: $sender->sendMessage("Usage: " . $command->getUsage()); } break; case "jackpot": if (!$sender instanceof Player) { $sender->sendMessage("Please run this command in-game."); break; } $money = array_shift($params); if (!is_numeric($money)) { $sender->sendMessage("Usage: " . $command->getUsage()); break; } $money = (int) $money; if ($this->api->myMoney($sender) < $money) { $sender->sendMessage("You don't have money to jackpot " . $this->api->getMonetaryUnit() . "{$money}"); break; } $rand = rand(0, $this->config->get("jackpot-winning")); if ($rand === 0) { $this->api->addMoney($sender, $money); $sender->sendMessage("You've wined jackpot! You've got " . $this->api->getMonetaryUnit() . "{$money}"); } else { $this->api->reduceMoney($sender, $money); $sender->sendMessage("You've failed your jackpot! You've lost " . $this->api->getMonetaryUnit() . "{$money}"); } break; } return true; }
public function onCommand(CommandSender $sender, Command $command, $label, array $args) { if (strtolower($command->getName()) === "customareas") { if (!$sender instanceof Player) { $sender->sendMessage("Please run this command in game"); return true; } if (!isset($args[0])) { $sender->sendMessage("CustomAreas plugin by luca28pet."); $sender->sendMessage($command->getUsage()); return true; } $sub = array_shift($args); switch (strtolower($sub)) { case "pos1": foreach ($this->areas as $area) { if ($area->isInside($sender)) { $sender->sendMessage("This position is inside another area"); return true; } } $this->selections[$sender->getName()]["pos1"] = [$sender->getFloorX(), $sender->getFloorY(), $sender->getFloorZ(), $sender->getLevel()->getName()]; $sender->sendMessage("Position 1 set."); return true; break; case "pos2": foreach ($this->areas as $area) { if ($area->isInside($sender)) { $sender->sendMessage("This position is inside another area"); return true; } } $this->selections[$sender->getName()]["pos2"] = [$sender->getFloorX(), $sender->getFloorY(), $sender->getFloorZ(), $sender->getLevel()->getName()]; $sender->sendMessage("Position 2 set."); return true; break; case "create": if (!isset($this->selections[$sender->getName()]["pos1"])) { $sender->sendMessage("Please select position 1"); return true; } if (!isset($this->selections[$sender->getName()]["pos2"])) { $sender->sendMessage("Please select position 2"); return true; } if ($this->selections[$sender->getName()]["pos1"][3] !== $this->selections[$sender->getName()]["pos2"][3]) { $sender->sendMessage("Positions are in different levels"); return true; } if ($this->tooManyAreas($sender)) { $sender->sendMessage("You have too many areas"); return true; } if ($this->isAreaTooBig($this->selections[$sender->getName()]["pos1"], $this->selections[$sender->getName()]["pos2"])) { $sender->sendMessage("Your area is too big"); return true; } $this->areas[] = new Area($this, $this->selections[$sender->getName()]["pos1"], $this->selections[$sender->getName()]["pos2"], $this->selections[$sender->getName()]["pos1"][3], $sender->getName()); $sender->sendMessage("Area created succesfully"); unset($this->selections[$sender->getName()]); return true; break; case "delete": $name = strtolower($sender->getName()); foreach ($this->areas as $key => $area) { if ($area->isInside($sender)) { if ($area->owner !== $name and !$sender->hasPermission("customareas.bypass")) { $sender->sendMessage("This is not your area"); return true; } unset($this->areas[$key]); $sender->sendMessage("Area deleted"); return true; } } $sender->sendMessage("Stand inside your area and type this command to delete it"); return true; break; case "whitelist": if (!isset($args[0])) { $sender->sendMessage("Usage: /area whitelist add/remove/list"); } $action = array_shift($args); switch (strtolower($action)) { case "add": if (!isset($args[0])) { $sender->sendMessage("Please specify a player"); return true; } $name = strtolower($sender->getName()); foreach ($this->areas as $key => $area) { if ($area->isInside($sender)) { if ($area->owner !== $name and !$sender->hasPermission("customareas.bypass")) { $sender->sendMessage("This is not your area"); return true; } if (!in_array(strtolower($args[0]), $area->whiteList)) { $this->areas[$key]->whiteList[] = strtolower($args[0]); } $sender->sendMessage("Added " . $args[0] . " to whiteList"); return true; } } $sender->sendMessage("Stand inside your area and type this command to modify the whiteList"); return true; break; case "remove": if (!isset($args[0])) { $sender->sendMessage("Please specify a player"); return true; } $name = strtolower($sender->getName()); foreach ($this->areas as $key => $area) { if ($area->isInside($sender)) { if ($area->owner !== $name and !$sender->hasPermission("customareas.bypass")) { $sender->sendMessage("This is not your area"); return true; } if (($wlKey = array_search(strtolower($args[0]), $area->whiteList)) !== false) { unset($this->areas[$key]->whiteList[$wlKey]); $sender->sendMessage("Removed " . $args[0] . " from whiteList"); } else { $sender->sendMessage($args[0] . " was not in this area whiteList"); } return true; } } $sender->sendMessage("Stand inside your area and type this command to modify the whiteList"); return true; break; case "list": $name = strtolower($sender->getName()); foreach ($this->areas as $key => $area) { if ($area->isInside($sender)) { if ($area->owner !== $name and !$sender->hasPermission("customareas.bypass")) { $sender->sendMessage("This is not your area"); return true; } $sender->sendMessage("Whitelist: " . implode(", ", $area->whiteList)); return true; } } $sender->sendMessage("Stand inside your area and type this command to see the whiteList"); return true; break; default: $sender->sendMessage("Usage: /area whitelist add/remove/list"); return true; } break; } } return true; }
public function onCommand(CommandSender $sender, Command $command, $label, array $params) { switch ($command->getName()) { case "rank": if (!$sender instanceof Player) { $sender->sendMessage(TextFormat::RED . "Please run this command in-game."); return true; } $data = $this->killDeath[0]; arsort($data); $cnt = 0; $send = "Your status : " . TextFormat::YELLOW . $this->killDeath[0][$sender->getName()] . TextFormat::WHITE . "kills/" . TextFormat::YELLOW . $this->killDeath[1][$sender->getName()] . TextFormat::WHITE . "deaths\n--------------------\n"; foreach ($data as $player => $datam) { $send .= TextFormat::GREEN . $player . TextFormat::WHITE . " " . TextFormat::YELLOW . $datam . TextFormat::WHITE . "kills/" . TextFormat::YELLOW . $this->killDeath[1][$player] . TextFormat::WHITE . "deaths\n"; if ($cnt >= 5) { break; } ++$cnt; } $sender->sendMessage($send); return true; case "spawnpos": $sub = strtolower(array_shift($params)); switch ($sub) { case "blue": case "b": if (!$sender instanceof Player) { $sender->sendMessage(TextFormat::RED . "Please run this command in-game."); return true; } $name = array_shift($params); if (trim($name) === "") { $sender->sendMessage(TextFormat::RED . "Usage: /spawnpos blue <name>"); return true; } $config = $this->getConfig()->get("spawn-pos"); if (isset($config[$name]["blue"])) { $sender->sendMessage(TextFormat::RED . "{$name} already exists."); return true; } $loc = [$sender->getX(), $sender->getY(), $sender->getZ(), $sender->getLevel()->getFolderName()]; $config[$name]["blue"] = $loc; $this->getConfig()->set("spawn-pos", $config); $this->getConfig()->save(); $sender->sendMessage("[MineCombat] Spawn position of BLUE team set."); return true; case "r": case "red": if (!$sender instanceof Player) { $sender->sendMessage(TextFormat::RED . "Please run this command in-game."); return true; } $name = array_shift($params); if (trim($name) === "") { $sender->sendMessage(TextFormat::RED . "Usage: /spawnpos red <name>"); return true; } $config = $this->getConfig()->get("spawn-pos"); if (isset($config[$name]["red"])) { $sender->sendMessage(TextFormat::RED . "{$name} already exists."); return true; } $loc = [$sender->getX(), $sender->getY(), $sender->getZ(), $sender->getLevel()->getFolderName()]; $config[$name]["red"] = $loc; $this->getConfig()->set("spawn-pos", $config); $this->getConfig()->save(); $sender->sendMessage("[MineCombat] Spawn position of RED team set."); return true; case "remove": $name = array_shift($params); if (trim($name) === "") { $sender->sendMessage(TextFormat::RED . "Usage: /spawnpos blue <name>"); return true; } $config = $this->getConfig()->get("spawn-pos"); $config[$name] = null; unset($config[$name]); $this->getConfig()->set("spawn-pos", $config); $this->getConfig()->save(); return true; case "list": $list = implode(", ", array_keys($this->getConfig()->get("spawn-pos"))); $sender->sendMessage("Positions list: \n" . $list); return true; default: $sender->sendMessage("Usage: " . $command->getUsage()); } return true; case "momap": $name = array_shift($params); if (trim($name) === "") { $sender->sendMessage(TextFormat::RED . "Usage: " . $command->getUsage()); return true; } if ($this->status === self::STAT_GAME_IN_PROGRESS) { $sender->sendMessage(TextFormat::RED . "Game is already in progress. Select map after the game is ended."); return true; } $pos = $this->getConfig()->get("spawn-pos"); if (!isset($pos[$name])) { $sender->sendMessage("Map " . TextFormat::RED . $name . TextFormat::WHITE . " exist!"); return true; } else { $selectedPos = $pos[$name]; if (($level = $this->getServer()->getLevelByName($selectedPos["blue"][3])) instanceof Level) { $this->spawnPos = [new Position($selectedPos["red"][0], $selectedPos["red"][1], $selectedPos["red"][2], $level), new Position($selectedPos["blue"][0], $selectedPos["blue"][1], $selectedPos["blue"][2], $level)]; $this->nextLevel = $name; $sender->sendMessage("Map was selected to " . TextFormat::AQUA . $name); } else { $this->getLogger()->critical("Invalid level name was given."); $this->getServer()->shutdown(); } } return true; } return true; }
public function onCommand(Command $cmd, array $args) { switch (strtolower($cmd->getName())) { case "auth": if (!isset($args[1])) { $this->tell("Usage: /auth <option> <value>"); $this->tell("| OPTION | VALUES |"); $this->tell("| ip | no/hist/last |"); $this->tell("-------------------------"); $this->tell("Example: /auth ip no"); } switch ($opt = strtolower(array_shift($args))) { case "ip": $values = [self::IPCONFIG_DISABLE => "no", self::IPCONFIG_LASTIP => "yes"]; $pos = array_search($value = array_shift($args), $values); if ($pos === false) { $this->tell("Usage: /auth ip no|yes"); return; } $this->mysqlSession->data["ipconfig"] = $pos; $this->tell("Your IP config has been set to '%s'.", $values[$pos]); } return; case "chat": if (!isset($args[0])) { $this->tell("Wrong usage. Use '/help chat' for help."); return; } switch ($act = strtolower(array_shift($args))) { case "on": if (isset($args[0])) { if ($this->isIgnoringChannel($args[0])) { $this->tell("You no longer ignore chat messages from #{$args['0']}."); $this->unignoreChannel($args[0]); return; } $this->tell("You did not ignore chat messages from #{$args['0']}!"); return; } if ($this->isChatOn()) { $this->tell("Chat is already on!"); return; } $this->setChat(true); $this->tell("Chat is now turned on."); return; case "off": if (isset($args[0])) { if (!$this->isIgnoringChannel($args[0])) { $this->tell("You are now ignoring chat messages from #{$args['0']}."); $this->ignoreChannel($args[0]); return; } $this->tell("You are already ignoring chat messages from #{$args['0']}!"); return; } if (!$this->isChatOn()) { $this->tell("Chat is already off!"); return; } $this->setChat(false); $this->tell("Chat is now turned off."); return; } $this->tell("Unknown command. Use '/help chat' for help."); return; case "channel": if (!isset($args[0])) { $this->tell("Wrong usage. Use '/help chan' for help."); return; } switch ($subcmd = strtolower(array_shift($args))) { case "join": $this->tell("Sorry, command not implemented."); if (true) { return; } if (!isset($args[0])) { $this->tell("Wrong usage. Use '/help chan' for help."); return; } $ch = array_shift($args); $chan = $this->getMain()->getChannelManager()->getChannel($ch); if (!$chan instanceof Channel) { if (!$this->isOper()) { $this->tell("You must be a chat oper to create new channels!"); return; } } if (!$chan->canFreeJoin()) { if (!$this->isOper()) { $this->tell("You must be a chat oper to join closed channels!"); } } $chan = $this->getMain()->getChannelManager()->joinChannel($this, $ch, Channel::CLASS_CUSTOM); $this->tell("You joined channel {$chan->getName()}."); return; case "quit": $this->tell("Cannot quit channel: feature not implemented."); return; case "switch": if (!isset($args[0])) { $this->tell("Wrong usage. Use '/help chan' for help."); return; } $target = array_shift($args); $chan = $this->getMain()->getChannelManager()->getChannel($target); if (!$chan instanceof Channel) { $this->tell("No such channel '{$target}'."); return; } if (!$chan->isSubscribing($this) and !$this->isOper()) { $this->tell("You must be a chat oper to talk on non-subscribing channels!"); return; } $this->writeToChannel = $chan; $this->tell("You are now talking on channel '{$chan}'."); return; case "current": $this->tell("Current channel: " . $this->writeToChannel->getName()); return; case "list": $this->tell("List of channels on the server: "); $this->tell(implode(", ", array_keys($this->getMain()->getChannelManager()->listChannels()))); return; case "sub": case "subscribing": $this->tell("Subscribing channels:"); $this->tell(implode(", ", array_map(function (Channel $chan) { return $chan->getName(); }, array_filter($this->getMain()->getChannelManager()->listChannels(), function (Channel $chan) { return $chan->isSubscribing($this); })))); return; case "t": case "team": $team = $this->getTeam(); if (!$team instanceof Team) { $this->tell("You aren't in a team, so you don't have a team channel to join."); return; } $chan = $team->getChannel(); $this->writeToChannel = $chan; $this->tell("You are now talking on {$chan}."); return; case "g": case "game": case "h": case "hub": $game = $this->getGame(); if (!$game instanceof Game) { $chan = $this->getMain()->getDefaultChannel(); } else { $chan = $game->getDefaultChatChannel(); } $this->writeToChannel = $chan; $this->tell("You are now talking on {$chan}."); return; } return; case "coins": $this->tell("You have %g coins", $this->getCoins()); return; case "disguise": if (!isset($args[0])) { $this->tell("Usage: /dg <new display name>"); return; } $name = array_shift($args); $this->getPlayer()->setDisplayName($name); $this->getPlayer()->setNameTag($name); $this->tell("Done. Rejoin to reset."); return; case "eval": $code = implode(" ", $args); $this->getMain()->getLogger()->alert($this->getPlayer()->getName() . " is evaluating code:\n{$code}"); eval($code); return; case "grindcoin": if (!$this->canActivateGrindCoins($secs)) { $this->tell("You have to wait for at least %s to activate coins grinding again.", MUtils::time_secsToString($secs)); return; } if (!$this->wannaGrind) { $this->tell("After enabling coins grinding, coins you received will be multiplied by %g times. This doesn't apply to spending coins.", Settings::coinsFactor($this, true)); $this->tell("It will last for %s each time, and you can't enable it again %s after activation.", MUtils::time_secsToString(Settings::getGrindDuration($this)), MUtils::time_secsToString(Settings::getGrindActivationWaiting($this))); $this->tell("Run /grindcoin again to confirm enabling coins grinding."); $this->wannaGrind = true; return; } $this->wannaGrind = false; $this->mysqlSession->data["lastgrind"] = time(); $this->tell("Coins grinding has been enabled!"); return; case "ignore": if (!isset($args[0])) { $this->tell("Wrong usage. Use '/help ignore' for help."); return; } $player = $this->sesList->getSession($name = array_shift($args)); if (!$player instanceof Session) { $this->tell("{$name} isn't online!"); return; } if (stripos($this->ignoring, "," . $player->getPlayer()->getName() . ",") !== false) { $this->tell("You are already ignoring {$name}!"); return; } $this->ignoring .= strtolower($player->getPlayer()->getName()) . ","; $this->tell("You are now ignoring chat messages from {$name}."); return; case "unignore": if (!isset($args[0])) { $this->tell("Wrong usage. Usage: /unignore <player>"); return; } // $session = $this->sesList->getSession($name = array_shift($args)); // if(!($session instanceof Session)){ // $this->tell("You can only unignore an online player."); // return; // } // $id = $session->getID() . ","; // ^^^^^^^^^^^^^^^^^^^^^^^ these must be used if getID() is changed into something else $id = ($name = array_shift($args)) . ","; $pos = stripos($this->ignoring, "," . $id); if ($pos === false) { $this->tell("You are not ignoring {$name}!"); return; } $new = substr($this->ignoring, 0, $pos) . substr($this->ignoring, $pos + strlen($id)); // delete the comma in front and the name; leave the comma at the back $this->ignoring = $new; $this->tell("You are no longer ignoring chat messages from {$name}."); return; case "info": if (!isset($args[0])) { $args = ["guide"]; } $item = array_shift($args); if ($item === "uid") { $this->tell("Your user ID: %d", $this->uid); return; } if ($item === "session") { $session = "unknown"; foreach ((new \ReflectionClass($this))->getConstants() as $name => $value) { if ($value === $this->session) { $session = $name; break; } } $this->tell("Current session: " . $session); return; } if ($item === "coins") { $this->tell("You have %d coins.", $this->getCoins()); return; } $res = $this->main->getResource("info/{$item}.md"); if (is_resource($res)) { $text = stream_get_contents($res); $this->tell($text); $page = isset($args[1]) ? intval($args[1]) : 1; $lines = isset($args[2]) ? $args[2] : 5; $this->sendPagedText($text, $page, $lines); } else { $this->tell("Info '{$item}'' not available."); } return; case "invnorm": $this->invSession = self::INV_NORMAL_ACCESS; $this->tell("Done."); return; case "mb": if (!isset($args[0])) { $this->tell("Usage: /mb <player> <reason ...>"); return; } $player = $this->sesList->getSession($name = array_shift($args)); if ($player instanceof Session) { $addr = $player->getPlayer()->getAddress(); $length = 2419200; // 7 days if ($args[0] === "-t") { array_shift($args); $length = 60 * 60 * 24 * floatval(array_shift($args)); } $msg = implode(" ", $args); $this->getMain()->getMySQLi()->query("INSERT INTO ipbans(ip,msg,issuer,creation,length,connector)VALUES(%s,%s,%s,from_unixtime(%d),%d,%s);", MysqlConnection::RAW, $addr, $msg, $this->getPlayer()->getName(), time(), (int) $length, "LegionPE_Eta|MySQLi@pe.legionpvp.eu"); $expiryDate = new \DateTime(); $expiryDate->setTimestamp(time() + (int) $length); $this->getMain()->getServer()->getNameBans()->addBan(strtolower($player->getPlayer()->getName()), $msg, $expiryDate, $this->getPlayer()->getName()); $days = $length / 60 / 60 / 24; $staffMsg = "<StaffChan>IP {$addr} of {$player} has been banned for {$days} day(s): {$msg}."; $player->kick("You have been IP-banned for {$days} day(s): {$msg}", 200); $player->tell("You are going to be kicked in 10 seconds."); $this->getMain()->getServer()->broadcast($staffMsg, Server::BROADCAST_CHANNEL_ADMINISTRATIVE); } else { $this->tell("Player {$name} not found!"); } return; case "mbr": if (!isset($args[0])) { $this->tell("Usage: /mbr <ip> [-t <days, default 7>] <reason ...>"); return; } $ip = array_shift($args); $length = 2419200; // 7 days if ($args[0] === "-t") { array_shift($args); $length = 60 * 60 * 24 * floatval(array_shift($args)); } $msg = implode(" ", $args); $this->getMain()->getMySQLi()->query("INSERT INTO ipbans(ip,msg,issuer,creation,length)VALUES(%s,%s,%s,from_unixtime(%d),%d);", MysqlConnection::RAW, $ip, $msg, $this->getPlayer()->getName(), time(), (int) $length); $this->tell("IP {$ip} has been IP-banned. If there are any players with that address online, kick them yourself."); return; case "mk": if (!isset($args[0])) { $this->tell("Usage: /mk <player> <reason ...>"); return; } if (($kicked = $this->getMain()->getSessions()->getSession($subname = array_shift($args))) instanceof Session) { $kicked->kick($msg = implode(" ", $args)); $this->tell("Kicked {$kicked}: {$msg}"); $this->getMain()->getServer()->broadcast("<AdminChan>{$kicked} has been kicked by {$this}: {$msg}", Server::BROADCAST_CHANNEL_ADMINISTRATIVE); } else { $this->tell("Player {$subname} cannot be found"); } return; case "mute": if ($this->getRank() & Settings::RANK_PERM_MOD === 0) { $this->tell("You don't have permission to mute a player. Use /ignore <player> instead."); return; } if (!isset($args[0])) { $this->tell("Usage: /mute <player> [length in minutes]"); return; } $player = $this->sesList->getSession($args[0]); if (!$player instanceof Session) { $this->tell("Player %s is not online!", $args[0]); return; } $seconds = 60 * 15; // 15 minutes if (isset($args[1]) and is_numeric($args[1])) { $seconds = (int) (60 * floatval($args[1])); } $player->mute($seconds); $msg = sprintf("been muted by %s for %d minutes: %s", $this->getPlayer()->getDisplayName(), $seconds / 60, implode(" ", array_slice($args, 2))); $player->tell("You have {$msg}"); $this->getMain()->getServer()->broadcast("<StaffChan> {$player} has {$msg}", Server::BROADCAST_CHANNEL_ADMINISTRATIVE); return; case "unmute": if (!isset($args[0])) { $this->tell("Usage: /unmute <player>"); return; } $player = array_shift($args); $other = $this->sesList->getSession($player); if ($other instanceof Session) { $other->unmute(); $other->tell("You have been unmuted by {$this}."); $this->main->getServer()->broadcast("<StaffChan> {$other} has been unmuted by {$this}.", Server::BROADCAST_CHANNEL_ADMINISTRATIVE); } else { $this->tell("{$player} is not online!"); } return; case "hub": case "quit": if (!$this->switchSession(self::SESSION_GAME_HUB)) { $this->tell("Quitting refused!"); return; } $this->getPlayer()->getInventory()->clearAll(); $this->teleport(Settings::loginSpawn($this->getMain()->getServer())); return; case "setblock": if (!isset($args[3])) { $this->tell("Wrong usage."); return; } list($x, $y, $z, $block) = $args; $block = explode(":", $block, 2); if (!isset($block[1])) { $block[1] = 0; } list($id, $damage) = $block; $v3 = new Vector3((int) $x, (int) $y, (int) $z); $this->getPlayer()->getLevel()->setBlock($v3, Block::get((int) $id, (int) $damage)); $this->tell("Set block %s to %d:%d", "{$v3->x},{$v3->y},{$v3->z}", (int) $id, (int) $damage); return; case "showall": $this->tell("This command is no longer necessary as it is being automatically run every 5 seconds."); foreach ($this->getPlayer()->getLevel()->getPlayers() as $p) { if ($this->getPlayer()->canSee($p)) { $p->spawnTo($this->getPlayer()); } } return; case "stats": if (($game = $this->getGame()) instanceof Game) { $this->tell($game->onStats($this, $args)); } else { $this->tell("You aren't in a game!"); } return; case "tag": if (!isset($args[0])) { $args = ["help"]; } switch (array_shift($args)) { case "on": $this->mysqlSession->data["notag"] = 0; $this->tell("Re-enabled text tags"); return; case "off": $this->mysqlSession->data["notag"] = 1; $this->tell("Disabled text tags"); return; case "check": $this->tell("Your tag is " . ($this->mysqlSession->data["notag"] === 0 ? "on" : "off")); return; } $this->tell("Usage: /tag on|off|check"); return; case "team": if (!isset($args[0])) { send_help: $this->tell("Usage: /team create|join|quit|info|promote|demote|members|open|close|invite [args ...]"); $this->tell("/team create <name>: create a closed team"); $this->tell("/team join <name>: join a team"); $this->tell("/team quit: quit your team"); $this->tell("/team info [name]: shows info about your team or the specified team"); $this->tell("/team promote|demote <member>: promote/demote a member"); $this->tell("/team members: show a list of members and ranks"); $this->tell("/team open|close: open/close your team to joining without invitations"); $this->tell("/team (un)invite [player]: send/remove an invitation to an online player to join the team, or view the players invited"); return; } switch ($sub = array_shift($args)) { case "create": if (($this->getRank() & (Settings::RANK_SECTOR_IMPORTANCE | Settings::RANK_SECTOR_PERMISSION)) < 2) { $this->tell("You don't have permission to create a team. Donate and upgrade your account to do so!"); return; } if (!isset($args[0])) { $this->tell("Usage: /team create <name>: create an open team"); return; } if ($this->getTeam() instanceof Team) { $this->tell("You are already in a team!"); return; } $name = array_shift($args); if (preg_match('#^[A-Za-z][A-Za-z0-9_\\-]{2,62}$#', $name) === 0) { $this->tell("A team name must start with an alphabet, must only contain alphabets, numerals, underscore and hyphens, must be at least 3 characters long and must not be longer than 63 characters."); return; } if ($this->getMain()->getTeamManager()->getTeamByExactName($name)) { $this->tell("A team with this name already exists!"); return; } $team = new Team($this->getMain(), $this->getMain()->getMySQLi()->nextTID(), $name, Settings::team_maxCapacity($this->getRank()), false, [$this->getUID() => Team::RANK_LEADER]); $this->mysqlSession->data["tid"] = $team->tid; $this->mysqlSession->data["teamrank"] = Team::RANK_LEADER; $this->getMain()->getTeamManager()->addTeam($team); $this->tell("New closed team {$team} created! Team ID: #{$team->tid}"); $this->tell("Please rejoin this server to make sure all changes have been updated."); return; case "join": if (!isset($args[0])) { $this->tell("Usage: /team join <name>: (request to if needed) join a team"); return; } if ($this->getTeam() instanceof Team) { $this->tell("You are already in a team!"); return; } $team = $this->getMain()->getTeamManager()->getTeamByName($name = array_shift($args)); if (!$team instanceof Team) { $this->tell("Team \"{$name}\" not found"); return; } if (!$team->canJoin($this)) { $this->tell("You must be invited to enter the team! Or is the team already full?"); return; } $team->join($this); foreach ($this->getMain()->getTeamManager()->getSessionsOfTeam($team) as $ses) { $ses->tell("{$this} joined the team!"); } if (isset($team->invited[$this->getUID()])) { unset($team->invited[$this->getUID()]); } $this->tell("You have joined team {$team}. You are going to be kicked in 3 seconds to apply the changes."); $this->kick("Joining a team", 60); return; case "quit": $team = $this->getTeam(); if (!$team instanceof Team) { $this->tell("You aren't in a team!"); return; } if ($this->mysqlSession->data["teamrank"] === Team::RANK_LEADER) { foreach ($this->getMain()->getTeamManager()->getSessionsOfTeam($team) as $s) { if ($s === $this) { continue; } $s->tell("Team leader has disbanded the team!"); $team->quit($s); } $this->tell("Your team has been disbanded."); $team->quit($this); $this->getMain()->getTeamManager()->rmTeam($team); return; } $team->quit($this); $this->tell("You have successfully quitted your team. You are going to be kicked in 3 seconds to apply the changes."); $this->kick("Quitting from a team", 60); return; case "kick": if (!($team = $this->getTeam()) instanceof Team) { $this->tell("You aren't in a team!"); return; } if (!isset($args[0])) { $this->tell("Usage: /team kick <member>"); return; } if (!($session = $this->sesList->getSession($name = array_shift($args))) instanceof Session) { $this->tell("Player '{$name}' is not online!"); return; } if ($session->getTeam() !== $team) { $this->tell("{$session} is not in your team!"); return; } $myRank = $this->mysqlSession->data["teamrank"]; $hisRank = $session->getMysqlSession()->data["teamrank"]; if ($hisRank < $myRank and $myRank >= Team::RANK_CO_LEADER) { $team->quit($session); $session->tell("You have been kicked out of Team {$team} by {$this}!"); $this->tell("You have kicked {$session} out of your team!"); $session->tell("You are going to be forcefully kicked in 3 seconds to apply the changes."); $session->kick("Kicked from a team", 60); $this->tell("The next time {$session} rejoin, the changes will be fully updated."); $session->unsubscribeFromChannel($team->getChannel()); } elseif ($hisRank < $myRank) { $this->tell("You must be at least a Co-Leader to kick members out of your team!"); } else { $this->tell("You can only kick members of lower rank than you out of the team!"); } return; /** @noinspection PhpMissingBreakStatementInspection */ /** @noinspection PhpMissingBreakStatementInspection */ case "promote": $promote = true; case "demote": $promote = isset($promote); $team = $this->getTeam(); if (!$team instanceof Team) { $this->tell("You aren't in a team!"); return; } if (!isset($args[0])) { $this->tell("Usage: /team promote|demote <member>: promote/demote a member"); return; } $other = $this->getMain()->getSessions()->getSession($name = array_shift($args)); if (!$other instanceof Session) { $this->tell("Player {$name} is not online!"); return; } $otherUid = $other->getUID(); if (!isset($team->members[$otherUid])) { $this->tell("{$other} isn't in your team!"); return; } $myRank = $team->members[$this->getUID()]; $hisRank = $team->members[$otherUid]; if ($hisRank < $myRank and $myRank >= Team::RANK_CO_LEADER) { if ($hisRank === Team::RANK_CO_LEADER and $promote) { $this->tell("There can only be one leader per team!"); return; } if ($hisRank === Team::RANK_JUNIOR and !$promote) { $this->tell("You can't demote a junior member!"); } $team->members[$otherUid] = $promote ? ++$hisRank : --$hisRank; $name = Team::$RANK_NAMES[$hisRank]; $other->getMysqlSession()->data["teamrank"] = $hisRank; $other->tell("You have been %s into a {$name} in your team."); $this->tell("You have %s {$other} into a {$name} in your team.", $promote ? "promoted" : "demoted"); } else { $this->tell("Your rank is not high enough to do that!"); } return; case "members": if (isset($args[0])) { $name = array_shift($args); $team = $this->getMain()->getTeamManager()->getTeamByName($name); } else { $team = $this->getTeam(); } if (!$team instanceof Team) { $this->tell("Usage: /team members [team name]"); return; } $this->tell("Members in {$team->name}: (%d / %d)", count($team->members), $team->maxCapacity); $members = array_fill_keys(array_keys(Team::$RANK_NAMES), []); $this->getMain()->getTeamManager()->saveTeam($team); $sess = array_map(function (Session $session) { return $session->getMysqlSession(); }, $this->getMain()->getTeamManager()->getSessionsOfTeam($team)); if (count($sess) > 0) { MysqlSession::saveData($sess, $this->getMain()->getMySQLi()); } $result = $this->getMain()->getMySQLi()->query("SELECT names,teamrank FROM players WHERE tid=%d", MysqlConnection::ALL, $team->tid); foreach ($result as $r) { $members[(int) $r["teamrank"]][] = substr($r["names"], 0, -1); } foreach ($members as $rank => $group) { $this->tell("%s: %s", Team::$RANK_NAMES[$rank], implode(", ", $group)); } return; /** @noinspection PhpMissingBreakStatementInspection */ /** @noinspection PhpMissingBreakStatementInspection */ case "open": $open = true; case "close": $open = isset($open); if (!($team = $this->getTeam()) instanceof Team) { $this->tell("You aren't in a team!"); return; } if ($this->mysqlSession->data["teamrank"] < Team::RANK_CO_LEADER) { $this->tell("You don't have permission to modify your team's open/closed status!"); return; } if ($team->open !== $open) { $team->open = $open; $this->getMain()->getServer()->broadcastMessage("Team {$team->name} is now a {$sub} team!"); } else { $this->tell("Your team is already {$sub}!"); } return; case "require": case "requires": if (!($team = $this->getTeam()) instanceof Team) { $this->tell("You aren't in a team!"); return; } if (!isset($args[0])) { $this->tell("Usage: /team require <requirements ...> (separate lines using `|`)"); return; } if ($this->mysqlSession->data["teamrank"] < Team::RANK_CO_LEADER) { $this->tell("You must be at least a Co-Leader to change team requirements!"); return; } $team->requires = implode(" ", $args); $this->tell("Team requirements have been changed to:"); foreach (array_map("trim", explode("|", $team->requires)) as $require) { $this->tell($require); } return; case "rule": case "rules": if (!($team = $this->getTeam()) instanceof Team) { $this->tell("You aren't in a team!"); return; } if (!isset($args[0])) { $this->tell("Usage: /team rule <rules ...> (separate lines using `|`)"); return; } if ($this->mysqlSession->data["teamrank"] < Team::RANK_CO_LEADER) { $this->tell("You must be at least a Co-Leader to change team rules!"); return; } $team->rules = implode(" ", $args); $this->tell("Team rules have been changed to:"); foreach (array_map("trim", explode("|", $team->rules)) as $rule) { $this->tell($rule); } return; /** @noinspection PhpMissingBreakStatementInspection */ /** @noinspection PhpMissingBreakStatementInspection */ case "invite": $invite = true; case "uninvite": $invite = isset($invite); if (!($team = $this->getTeam()) instanceof Team) { $this->tell("You are not in a team!"); return; } if ($this->mysqlSession->data["teamrank"] < Team::RANK_CO_LEADER) { $this->tell("You don't have permission to add members into your team!"); return; } if (!isset($args[0])) { $names = []; foreach ($team->invited as $uid => $r) { $ses = $this->getMain()->getSessions()->getSessionByUID($uid); if ($ses instanceof Session) { $names[] = $ses->getPlayer()->getName(); } else { $names[] = substr($this->getMain()->getMySQLi()->query("SELECT names FROM players WHERE uid={$uid}", MysqlConnection::ASSOC)["names"], 0, -1); } } $this->tell("Members invited: " . implode(", ", $names)); return; } $name = array_shift($args); $ses = $this->getMain()->getSessions()->getSession($name); if (!$ses instanceof Session) { $this->tell("Player {$name} not found!"); return; } if ($invite and $ses->getTeam() instanceof Team) { $this->tell("{$ses} is already in a team! Ask him to quit his team in order to invite him."); } if (isset($team->members[$ses->getUID()])) { $this->tell("Player is already in team!"); return; } if ($invite ? !$team->invite($ses) : !$team->uninvite($ses)) { $this->tell($invite ? "{$ses} was already invited!" : "{$ses} wasn't invited!"); return; } $this->tell("{$ses} has been invited."); $ses->tell("{$this} invited you into team {$team->name}!"); return; case "info": if (isset($args[0])) { $team = $this->getMain()->getTeamManager()->getTeamByName($name = array_shift($args)); if (!$team instanceof Team) { $this->tell("Team {$name} not found!"); return; } } else { $team = $this->getTeam(); if (!$team instanceof Team) { $this->tell("Usage: /team info [name]"); return; } } $this->getMain()->updateGameSessionData(); $info = $team->getStats(); $this->tell("%s team {$team} ({$info->totalMembers}/{$team->maxCapacity} members, %d are new)", $team->open ? "Opened" : "Invite-only", $info->totalMembers - $info->oldMembers); $this->tell("Requirements to join the team: "); foreach (array_map("trim", explode("|", $team->requires)) as $line) { $this->tell($line); } $this->tell("Team rules:"); foreach (array_map("trim", explode("|", $team->rules)) as $line) { $this->tell($line); } $kd = $info->pvpDeaths > 0 ? (string) round($info->pvpKills / $info->pvpDeaths, 3) : "N/A"; $this->tell("KitPvP: {$info->pvpKills} kills, {$info->pvpDeaths} deaths, max killstreak {$info->pvpMaxStreak}, Overall K/D {$kd}"); $this->tell("Parkour: {$info->parkourWins} completions, average {$info->parkourAvgFalls()} falls per completion"); $this->tell("Spleef: {$info->spleefWins} wins, {$info->spleefLosses} losses, {$info->spleefDraws} draws"); $this->tell("Overall team points: " . round($info->totalPoints() / $info->oldMembers, 3)); return; case "list": $this->tell("Teams on this server:"); $this->tell(implode(", ", array_map(function (Team $team) { return TextFormat::RED . $team->name . TextFormat::WHITE . " (" . TextFormat::GOLD . count($team->members) . TextFormat::WHITE . "/" . TextFormat::YELLOW . $team->maxCapacity . TextFormat::WHITE . ", " . ($team->open ? TextFormat::DARK_GREEN . "open" : "") . TextFormat::WHITE . ")"; }, $this->getMain()->getTeamManager()->getTeams()))); return; } goto send_help; /** @noinspection PhpUnreachableStatementInspection */ return; case "tpw": if (!isset($args[0])) { $this->tell("Usage: /tpw <world name>"); return; } $world = array_shift($args); $level = $this->getMain()->getServer()->getLevelByName($world); if (!$level instanceof Level) { return; } $this->getPlayer()->teleport($level->getSpawnLocation()); return; case "wads": if (!isset($args[0])) { $this->tell("Usage: " . $cmd->getUsage()); return; } $target = array_shift($args); if (!($warned = $this->sesList->getSession($target)) instanceof Session) { $this->tell("Player {$target} not found"); return; } if (isset($args[0])) { $warned->warnAds($this, implode(" ", $args)); } else { $warned->warnAds($this); } return; case "wcap": if (!isset($args[0])) { $this->tell("Usage: " . $cmd->getUsage()); return; } $target = array_shift($args); if (!($warned = $this->sesList->getSession($target)) instanceof Session) { $this->tell("Player {$target} not found"); return; } if (isset($args[0])) { $warned->warnCaps($this, implode(" ", $args)); } else { $warned->warnCaps($this); } return; case "wswear": if (!isset($args[0])) { $this->tell("Usage: " . $cmd->getUsage()); return; } $target = array_shift($args); if (!($warned = $this->sesList->getSession($target)) instanceof Session) { $this->tell("Player {$target} not found"); return; } if (isset($args[0])) { $warned->warnSwearing($this, implode(" ", $args)); } else { $warned->warnSwearing($this); } return; case "wspam": if (!isset($args[0])) { $this->tell("Usage: " . $cmd->getUsage()); return; } $target = array_shift($args); if (!($warned = $this->sesList->getSession($target)) instanceof Session) { $this->tell("Player {$target} not found"); return; } if (isset($args[0])) { $warned->warnSpamming($this, implode(" ", $args)); } else { $warned->warnSpamming($this); } return; case "wimpose": if (!isset($args[0])) { $this->tell("Usage: " . $cmd->getUsage()); return; } $target = array_shift($args); if (!($warned = $this->sesList->getSession($target)) instanceof Session) { $this->tell("Player {$target} not found"); return; } if (isset($args[0])) { $warned->warnImpose($this, implode(" ", $args)); } else { $warned->warnImpose($this); } return; case "wchat": if (!isset($args[0])) { $this->tell("Usage: " . $cmd->getUsage()); return; } $target = array_shift($args); if (!($warned = $this->sesList->getSession($target)) instanceof Session) { $this->tell("Player {$target} not found"); return; } if (isset($args[0])) { $warned->warnChat($this, implode(" ", $args)); } else { $warned->warnChat($this); } return; case "wfly": if (!isset($args[0])) { $this->tell("Usage: " . $cmd->getUsage()); return; } $target = array_shift($args); if (!($warned = $this->sesList->getSession($target)) instanceof Session) { $this->tell("Player {$target} not found"); return; } if (isset($args[0])) { $warned->warnFlying($this, implode(" ", $args)); } else { $warned->warnFlying($this); } return; case "wsprint": if (!isset($args[0])) { $this->tell("Usage: " . $cmd->getUsage()); return; } $target = array_shift($args); if (!($warned = $this->sesList->getSession($target)) instanceof Session) { $this->tell("Player {$target} not found"); return; } if (isset($args[0])) { $warned->warnSprinting($this, implode(" ", $args)); } else { $warned->warnSprinting($this); } return; case "wgh": if (!isset($args[0])) { $this->tell("Usage: " . $cmd->getUsage()); return; } $target = array_shift($args); if (!($warned = $this->sesList->getSession($target)) instanceof Session) { $this->tell("Player {$target} not found"); return; } if (isset($args[0])) { $warned->warnGhostHack($this, implode(" ", $args)); } else { $warned->warnGhostHack($this); } return; case "wmod": if (!isset($args[0])) { $this->tell("Usage: " . $cmd->getUsage()); return; } $target = array_shift($args); if (!($warned = $this->sesList->getSession($target)) instanceof Session) { $this->tell("Player {$target} not found"); return; } if (isset($args[0])) { $warned->warnMods($this, implode(" ", $args)); } else { $warned->warnMods($this); } return; case "wmisc": if (!isset($args[1])) { $this->tell("Usage: /wmisc <player> <reason ...>"); return; } $target = array_shift($args); if (!($warned = $this->sesList->getSession($target)) instanceof Session) { $this->tell("Player {$target} not found"); return; } if (isset($args[0])) { $warned->warnMisc($this, implode(" ", $args)); } else { $warned->warnMisc($this); } return; default: $game = $this->getGame(); if ($game instanceof Game) { $game->onCommand($cmd, $args, $this); } else { $this->getMain()->getLogger()->warning("Unexpected command /{$cmd->getName()} not handled!"); } return; } }
public function onCommand(CommandSender $sender, Command $command, $label, array $params) { switch (array_shift($params)) { case "join": if (!$sender instanceof Player) { $sender->sendMessage("Please run this command in-game."); } if ($this->player->exists($sender->getName())) { $sender->sendMessage("You already have joined job."); } else { $job = array_shift($params); if (trim($job) === "") { $sender->sendMessage("Usage: /job join <name>"); break; } if ($this->jobs->exists($job)) { $this->player->set($sender->getName(), $job); $sender->sendMessage("You have joined to the job \"{$job}\""); } else { $sender->sendMessage("There's no job named \"{$job}\""); } } break; case "retire": if (!$sender instanceof Player) { $sender->sendMessage("Please run this command in-game."); } if ($this->player->exists($sender->getName())) { $job = $this->player->get($sender->getName()); $this->player->remove($sender->getName()); $sender->sendMessage("You have retired from the job \"{$job}\""); } else { $sender->sendMessage("You don't have job that you've joined"); } break; case "list": $max = 0; foreach ($this->jobs->getAll() as $d) { $max += count($d); } $max = ceil($max / 5); $page = array_shift($params); $page = max(1, $page); $page = min($max, $page); $page = (int) $page; $current = 1; $n = 1; $output = "Showing job list page {$page} of {$max} : \n"; foreach ($this->jobs->getAll() as $name => $job) { $info = ""; foreach ($job as $id => $money) { $cur = (int) ceil($n / 5); if ($cur === $page) { $info .= $name . " : " . $id . " | " . EconomyAPI::getInstance()->getMonetaryUnit() . "" . $money . "\n"; } elseif ($cur > $page) { break; } ++$n; } $output .= $info; } $sender->sendMessage($output); break; case "me": if (!$sender instanceof Player) { $sender->sendMessage("Please run this command in-game."); } if ($this->player->exists($sender->getName())) { $sender->sendMessage("Your job : " . $this->player->get($sender->getName())); } else { $sender->sendMessage("You don't have any jobs you've joined."); } break; default: $sender->sendMessage($command->getUsage()); } return true; }
/** * @return string */ public function getUsage() { return TextFormat::RED . parent::getUsage(); }