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 . "."; }
public function tick() { if ($this->state) { // playing $this->ticks--; $this->broadcastTime(); if ($this->ticks === 0) { if (($cnt = count($this->players)) > 1) { $this->broadcast("The match has ended. There are no winners."); $this->broadcastSpecs("The {$cnt} survivors will share the award of 20 coins."); $mean = 20 / $cnt; foreach ($this->players as $player) { $get = round($mean * Settings::coinsFactor($player->getSession()), 2); $player->getSession()->setCoins($coins = $player->getSession()->getCoins() + $get); $player->getSession()->tell("You are awarded with {$get} coins. You now have {$coins} coins."); $player->addDraw(); } $this->game->getDefaultChatChannel()->broadcast("Match in {$this} ended with a draw with {$cnt} survivors!"); } $this->reset(); return; } foreach ($this->players as $player) { if ($player->getSession()->getPlayer()->getFloorY() < $this->config->lowestY - 1) { $this->kick($player, "you fell out of the arena"); $this->broadcast("{$player->getSession()} has fallen!"); $player->addLoss(); } if (count($this->players) === 0) { $this->reset(); return; // not sure what will happen. ConcurrentModificationException? } } } elseif (count($this->players) > 1) { $this->ticks--; $this->broadcastTime(); if ($this->ticks === 0) { $this->broadcast("The match now starts!"); $this->startMatch(); } } }
public function onBlockTouch(PlayerInteractEvent $event) { $session = $this->main->getSessions()->getSession($p = $event->getPlayer()); if (isset($this->data[$session->getUID()])) { $data = $this->data[$session->getUID()]; $sign = Settings::parkour_checkpoint_signs($event->getBlock()); if ($sign === -1) { if (is_array($coords = Settings::parkour_teleportSign($event->getBlock(), $session->getPlayer()))) { foreach ($coords as $c) { $p->teleport($c); } } return; } if ($sign === $data->getProgress()) { $session->tell("Checkpoint unchanged."); return; } if ($sign === 0) { if (microtime(true) - $data->lastClaimCoins < 10) { $session->tell("Don't spam the sign!"); return; } $coins = 15; $tmpFalls = $data->getTmpFalls(); $tmpFalls = max(min($tmpFalls, 50), 0); $tmpFalls /= 5; $award = round(($coins - $tmpFalls) * Settings::coinsFactor($session), 2); $session->tell("You have completed parkour! You are awarded with %d coins!", $award); $coins = $session->getCoins() + $award; $session->setCoins($coins); $session->tell("You now have {$coins} coins!"); $data->setCompletions($data->getCompletions() + 1); $data->setProgress(0); $data->resetTmpFalls(); if ($data->race instanceof ParkourRace) { $data->race->broadcastProgress($data->getSession(), 0); } } else { $session->tell("You reached checkpoint {$sign}!"); $data->setProgress($sign); if ($data->race instanceof ParkourRace) { $data->race->broadcastProgress($data->getSession(), 0); } } $session->getPlayer()->setSpawn($pos = Settings::parkour_checkpoint_startPos($sign, $this->getMain()->getServer())); if ($data->getProgress() === 0) { $session->teleport($pos); } $event->setCancelled(); } }
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; } }
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); } }