示例#1
0
 public function execute(CommandSender $sender, $lbl, array $args)
 {
     if ($sender instanceof Player) {
         if (!$this->getPlugin()->getSessions()->getSession($sender)->isMod()) {
             $sender->sendMessage($this->getPermissionMessage());
             return true;
         }
     }
     if (!isset($args[2])) {
         return false;
     }
     $target = $this->getPlugin()->getSessions()->getSession($name = array_shift($args));
     if (!$target instanceof Session) {
         $sender->sendMessage(TextFormat::RED . "Cannot find player \"{$name}\".");
         return true;
     }
     $duration = (int) ((double) array_shift($args) * 60);
     if ($duration === 0) {
         return false;
     }
     $issue = new MuteIssue();
     $issue->issuer = $ip = $sender->getName();
     $issue->target = $target->getPlayer()->getAddress();
     $issue->reason = implode(" ", $args);
     $issue->from = time();
     $issue->duration = MUtils::time_secsToString($duration);
     $issue->till = time() + $duration;
     $target->tell(TextFormat::BLACK . str_repeat("~", 20));
     $target->tell($issue->notify("you", TextFormat::YELLOW));
     $target->tell(TextFormat::BLACK . str_repeat("~", 20));
     $this->getPlugin()->getServer()->broadcast($issue->notify($target->getRealName(), TextFormat::DARK_GREEN), Server::BROADCAST_CHANNEL_ADMINISTRATIVE);
     $this->getPlugin()->getSessions()->mutedIps[$ip] = $issue;
     return true;
 }
 protected function run(Session $ses, array $args)
 {
     if (!$ses->canActivateGrindCoins($secs)) {
         return TextFormat::RED . "You need to wait for at least " . MUtils::time_secsToString($secs) . " to activate coins grinding again.";
     }
     if (!$ses->wannaGrind) {
         $ses->wannaGrind = true;
         $ses->tell(TextFormat::AQUA . "After enabling coins grinding, coins you received will be multiplied by %s times. This doesn't apply to spending coins.", TextFormat::LIGHT_PURPLE . Settings::coinsFactor($ses, true) . TextFormat::AQUA);
         $ses->tell(TextFormat::AQUA . "It will last for %s each time, and you can't enable it again %s after activation.", TextFormat::LIGHT_PURPLE . MUtils::time_secsToString(Settings::getGrindDuration($ses)) . TextFormat::AQUA, TextFormat::LIGHT_PURPLE . MUtils::time_secsToString(Settings::getGrindActivationWaiting($ses)) . TextFormat::AQUA);
         return TextFormat::AQUA . "Run /grindcoin again to confirm enabling coins grinding.";
     }
     $ses->wannaGrind = false;
     $ses->getMysqlSession()->data["lastgrind"] = time();
     return TextFormat::GREEN . "You have activated coins grinding. You will receive an extra of " . TextFormat::LIGHT_PURPLE . (Settings::coinsFactor($ses) * 100 - 100) . "%" . TextFormat::GREEN . " coins for those you earn in the following " . TextFormat::LIGHT_PURPLE . MUtils::time_secsToString(Settings::getGrindDuration($ses)) . TextFormat::GREEN . ".";
 }
示例#3
0
 public function onSlap(Session $session)
 {
     $data = $this->game->getPlayerData($session);
     $oldLevel = $data->getBowLevel();
     $newLevel = $oldLevel + 1;
     list($upgradePrice, $name, $description, $damage, $fireTicks, $knockback, $minImportance) = Settings::kitpvp_getBowInfo($newLevel);
     $rank = $session->getRank();
     if (($rank & Settings::RANK_SECTOR_IMPORTANCE) < $minImportance) {
         $session->tell("Upgrade your account to get more advanced bows!");
         return;
     }
     if ($upgradePrice === PHP_INT_MAX) {
         $session->tell("More bow upgrades coming soon!");
         return;
     }
     if ($data->isGoingToBuy === null or $data->isGoingToBuy["column"] !== "bow" or $data->isGoingToBuy["timestamp"] + 5 < microtime(true)) {
         $session->tell("Upgrade your bow to \"%s\".", $name);
         $session->tell($description);
         $session->tell("%s deals %f hearts of damage to victims.", $name, $damage / 2);
         if ($fireTicks > 0) {
             $session->tell("It also sets them on fire for %f seconds", $fireTicks / 20);
         }
         if ($knockback > 0) {
             $session->tell("An extra knockback of {$knockback}%% will also be casted.");
         }
         $session->tell("This upgrade costs you %g coins.", $upgradePrice);
         if ($upgradePrice > $session->getCoins()) {
             $session->tell("You need at least %g more coins to upgrade your bow!", $upgradePrice - $session->getCoins());
         } else {
             $session->tell("Click me within 5 seconds to confirm the purchase.");
             $data->isGoingToBuy = ["column" => "bow", "timestamp" => microtime(true)];
         }
     } else {
         $data->isGoingToBuy = null;
         if ($upgradePrice > $session->getCoins()) {
             $session->tell("You need at least %d more coins to upgrade your bow!", $upgradePrice - $session->getCoins());
             return;
         }
         $session->setCoins($coins = $session->getCoins() - $upgradePrice);
         $data->setBowLevel($newLevel);
         MUtils::word_addSingularArticle($name);
         $session->tell("Your bow is now {$name}! You have %d coins left.", $coins);
         $session->tell("Triple-click a model to toggle sword or bow.");
     }
 }
示例#4
0
 public function broadcastProgress(Session $session, $progress)
 {
     if (isset($this->won[$session->getUID()])) {
         return;
     }
     $diff = microtime(true) - $this->startTime;
     $time = MUtils::time_secsToString($diff);
     $this->broadcast("{$session} arrive at %s, spending %s!", $progress === 0 ? "the end" : "checkpoint {$progress}", substr($time, 0, -2));
     if ($progress === 0) {
         $this->won[$session->getUID()] = true;
     }
     if (count($this->won) === count($this->players)) {
         $this->broadcast("All players have finished. Race has ended.");
     }
 }
示例#5
0
 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;
     }
 }
示例#6
0
 private function i_onKill(Player $killer, Player $victim, $isFall = false, $isLadder = false, $isArrow = false)
 {
     $killerSession = $this->main->getSessions()->getSession($killer);
     $killerData = $this->playerData[$killerSession->getUID()];
     $killerData->incrementKills();
     if ($isFall) {
         $action = $isArrow ? "shot" : "knocked";
         if ($isLadder) {
             $killerSession->tell("%s was {$action} off a ladder by you and fell to death! Your number of kills: %d", $victim->getDisplayName(), $killerData->getKills());
             $victim->sendMessage("You were {$action} off a ladder by {$killerSession} and fell to death!");
         } else {
             $killerSession->tell("%s was {$action} to a deadly fall by you! Your number of kills: %d", $victim->getDisplayName(), $killerData->getKills());
             $victim->sendMessage("You were {$action} to a deadly fall by {$killerSession}!");
         }
     } else {
         $action = $isArrow ? "shot" : "killed";
         $kills = $killerData->getKills();
         $ord = MUtils::num_getOrdinal($kills);
         $killerSession->tell("%s is your {$kills}{$ord} kill!", $victim->getDisplayName());
         $victim->sendMessage("You were {$action} by {$killerSession}!");
     }
     $factor = Settings::coinsFactor($killerSession);
     $killerSession->setCoins($killerSession->getCoins() + $factor);
     Settings::kitpvp_killHeal($killerSession);
     $killerSession->tell("Your coins +{$factor} => {$killerSession->getCoins()} coins");
     $killerData->setStreakCnt($streak = $killerData->getStreakCnt() + 1);
     if ($streak % 5 === 0) {
         $this->pvpChannel->broadcast(sprintf("%s has a continuous streak of %d kills, totally getting %d kills!", $killerSession->getPlayer()->getDisplayName(), $streak, $killerData->getKills()));
         $more = (4 + $streak / 5) * $factor;
         $killerSession->setCoins($killerSession->getCoins() + $more);
         $killerSession->tell("You got {$more} extra coins for a killstreak!");
     }
     if (mt_rand(0, 99) === 0) {
         $bonus = mt_rand(25, 50);
     } elseif (mt_rand(0, 499) === 0) {
         $bonus = mt_rand(150, 300);
     } elseif (mt_rand(0, 749) === 0) {
         $bonus = mt_rand(250, 500);
     }
     if (isset($bonus)) {
         $this->getDefaultChatChannel()->broadcast("{$killerSession} received a bonus of {$bonus} coins!");
         $killerSession->setCoins($killerSession->getCoins() + $bonus);
     }
 }
示例#7
0
 public function notify($ipOf, $normColor = TextFormat::AQUA)
 {
     return $normColor . "IP " . TextFormat::LIGHT_PURPLE . $this->target . $normColor . " (IP of {$ipOf}) has been muted by " . TextFormat::LIGHT_PURPLE . $this->issuer . $normColor . " for a period of " . TextFormat::LIGHT_PURPLE . $this->duration . " " . MUtils::time_secsToString(time() - $this->from) . " ago" . $normColor . " for reason: " . TextFormat::LIGHT_PURPLE . $this->reason . "{$normColor}.";
 }