public function onCommand(CommandSender $sender, Command $cmd, $label, array $args) { $cfg = $this->getConfig(); $defgm = $cfg->get("Default-Game-Mode"); $tptosp = $cfg->get("Teleport-To-Spawn"); if (isset($args[0])) { switch ($args[0]) { case "on": $sender->setGamemode(3); $sender->sendMessage(TextFormat::GREEN . "You are now a Spectator!"); $this->getLogger()->info($sender->getName() . " Has changed his gamemode to Spectator"); return true; case "off": $sender->setGamemode($defgm); $sender->sendMessage(TextFormat::YELLOW . "You are no longer Espectator"); if ($tptosp === true) { $sender->teleport($this->getServer()->getDefaultLevel()->getSpawn()); } return true; } } return false; }
public function onCommand(CommandSender $sender, Command $cmd, $label, array $args) { switch ($cmd->getName()) { case "skywarshowto": if ($sender->hasPermission("skywars.command.howto") or $sender->hasPermission("skywars.command") or $sender->hasPermission("skywars")) { $sender->sendMessage("----How To Play skywars----"); $sender->sendMessage("/sk play = start a game"); $sender->sendMessage("/sk exit = exit from a game"); $sender->sendMessage("/sk stat [player] = get a player stats"); $sender->sendMessage("/sk skiptime = skip the waiting time"); return true; } else { $sender->sendMessage("You haven't the permission to run this command"); } case "skywars": case "sw": //same as setting aliases in plugin.yml, both cmds (skywars & sw) are usable //same as setting aliases in plugin.yml, both cmds (skywars & sw) are usable case "sk": switch ($args[0]) { case "play": if ($sender->hasPermission("skywars.command.play") or $sender->hasPermission("skywars.command") or $sender->hasPermission("skywars")) { if ($this->aplayers >= $this->getConfig()->get('neededplayers') and $this->skywarsstarted == false) { //if players in the world are more or equal as the max players $sender->sendMessage("The game is full"); // game full return true; } elseif ($this->aplayers < $this->getConfig()->get('neededplayers') and $this->skywarsstarted == false) { //if player number is less than the max. $spawn = $this->getConfig()->get('spawns')[$this->aplayers]; //no need to do + 1 on this, because arrays start counting form 0 // get the correct spawn place $sender->teleport(new Position($spawn[0], $spawn[1], $spawn[2], $this->getServer()->getLevelByName($this->getConfig()->get('aworld')))); //teleport to it $this->aplayers = $this->aplayers + 1; //then add a player to the array $sender->sendMessage("You have been teleported to the game world."); if ($this->aplayers == $this->getConfig()->get('neededplayers')) { //if the players became the same as neededplayers $this->startGame($this->getConfig() > get('aworld')); //start the game } return true; } elseif ($this->skywarsstarted == true) { //if the game is already started $sender->sendMessage("The game is already started"); return true; } } else { $sender->sendMessage("You haven't the permission to run this command."); return true; } break; case "exit": if ($sender->hasPermission("skywars.command.exit") or $sender->hasPermission("skywars.command") or $sender->hasPermission("skywars")) { if ($sender->getLevel()->getName() == $this->getConfig()->get('aworld')) { //if the level of the sender is a skywars one $this->aplayers = $this->aplayers - 1; //remove 1 to the array $sender->teleport($this->getServer()->getLevelByName($this->getConfig() > get('lobby'))->getSafeSpawn()); //teleport to the lobby $sender->sendMessage("You left the game."); if ($this->aplayers <= 1) { //if only 1 player is left foreach ($this->getServer()->getLevelByName($this->getConfig()->get('aworld'))->getPlayers() as $p) { //detects the winner if ($p->getGameMode() == 0) { $p->sendMessage("You won the match!"); $p->sendMessage("The game has finished, you will be teleported to the lobby."); $p->teleport($this->getServer()->getLevelByName($this->config->get('lobby'))->getSafeSpawn()); //teleport to the lobby $points = $this->points->get($p)[2] + $this->getConfig()->get('points-per-match'); //get points and add $deaths = $this->points->get($player)[0]; //get the victim's deaths, add one and store in a variable $kills = $this->points->get($player)[1]; //get the players kills and store in a var $this->getConfig()->set($p, array($deaths, $kills, $points)); } else { $p->sendMessage("The match has finished, thanks for watching."); $p->teleport($this->getServer()->getLevelByName($this->getConfig()->get('lobby'))->getSafeSpawn()); $p->setGameMode(0); } $this->stopGame($this->getConfig()->get('aworld')); //stop the game } } return true; } else { $sender->sendMessage("You are not in the SkyWars world."); return true; } } else { $sender->sendMessage("You haven't the permission to run this command."); return true; } break; case "stat": if ($sender->hasPermission("skywars.command.stat") or $sender->hasPermission("skywars.command") or $sender->hasPermission("skywars")) { if (!isset($args[1])) { $player = $sender->getName(); $deaths = $this->points->get($player)[0]; $kills = $this->points->get($player)[1]; $points = $this->points->get($player)[2]; $sender->sendMessage("You have " . $deaths . " deaths, " . $kills . " kills and " . $points . " points."); return true; } else { $player = $args[1]; $deaths = $this->points->get($player)[0]; $kills = $this->points->get($player)[1]; $points = $this->points->get($player)[2]; $sender->sendMessage($player . " has " . $deaths . " deaths, " . $kills . " kills and " . $points . " points."); return true; } } else { $sender->sendMessage("You haven't the permission to run this command."); return true; } break; case "spawnpos": if ($sender->hasPermission("skywars.command.pos") or $sender->hasPermission("skywars.command") or $sender->hasPermission("skywars")) { $x = $sender->getX(); $y = $sender->getY(); //get coordinates and store in variables $z = $sender->getZ(); $this->getConfig()->set('spawns', array($x, $y, $z)); $sender->sendMessage("Spawn position set to: " . $x . ", " . $y . ", " . $z . ", level: " . $sender->getLevel()->getName()); return true; } else { $sender->sendMessage("You haven't the permission to run this command."); return true; } break; case "skiptime": if ($sender->hasPermission("skywars.command.skiptime") or $sender->hasPermission("skywars.command") or $sender->hasPermission("skywars")) { if ($this->aplayers >= $this->getConfig()->get("minplayers")) { $this->startGame($sender->getLevel()->getName()); //start game on the sender level $sender->sendMessage("You started the game skipping the waiting time!"); return true; } else { $sender->sendMessage("There are less than 3 players, you can't start the game yet."); return true; } } else { $sender->sendMessage("You haven't the permission to run this command."); return true; } break; case "left": if ($sender->hasPermission("skywars.command.left") or $sender->hasPermission("skywars.command") or $sender->hasPermission("skywars")) { if ($sender->getLevel()->getName() == $this->getConfig()->get('aworld')) { $playersleft = $this->getConfig()->get('neededplayers') - $this->aplayers; $sender->sendMessage("Players left untill the game begin: " . $playersleft); return true; } else { $sender->sendMessage("You are not in a SkyWars world."); return true; } } else { $sender->sendMessage("You haven't the permission to run this command."); return true; } break; case "see": if ($sender->hasPermission("skywars.command.see") or $sender->hasPermission("skywars.command") or $sender->hasPermission("skywars")) { $sender->sendMessage("You will join a match as a spectator"); $sender->setGamemode(3); //Actually, this will crash mcpe I think. $spawn = $this->getConfig()->get('spectatorspawn'); $sender->teleport(new Position($spawn[0], $spawn[1], $spawn[2], $this->getServer()->getLevelByName($this->getConfig()->get('aworld')))); } else { $sender->sendMessage("You haven't the permission to run this command."); return true; } break; default: return false; } } }
public function onCommand(CommandSender $sender, Command $cmd, $label, array $args) { $name = $sender->getName(); switch ($cmd->getName()) { case "vote": if (!isset($args[0])) { $sender->sendMessage(MT::RED . 'Vote with /vote *arenanumber* (1-5)'); $this->getLogger()->info("{$name} benutzt vote befehl"); return true; } else { if ($args[0] == 1 || $args[0] == 2 || $args[0] == 3 || $args[0] == 4 || $args[0] == 5) { $sender->sendMessage(MT::RED . 'Thank u for voting the arena ' . MT::GREEN . $args[0]); $this->getLogger()->info("{$name} hat gevotet Arena {$args['0']}"); if ($args[0] == 1) { $this->arena1[$name] = 1; } if ($args[0] == 2) { $this->arena2[$name] = 1; } if ($args[0] == 3) { $this->arena3[$name] = 1; } if ($args[0] == 4) { $this->arena4[$name] = 1; } if ($args[0] == 5) { $this->arena5[$name] = 1; } return true; } else { $sender->sendMessage(MT::RED . 'Wrong arena number or arena not loaded'); return false; } } break; case "watch": $level = $sender->getLevel()->getName(); if ($level == $this->lobbyname) { if (isset($this->selectarena)) { $arenaname = $this->selectarena; if ($this->arena1name == $arenaname) { $pos111 = explode(",", $this->arena1areapos1); $pos222 = explode(",", $this->arena1areapos2); } if ($this->arena2name == $arenaname) { $pos111 = explode(",", $this->arena2areapos1); $pos222 = explode(",", $this->arena2areapos2); } if ($this->arena3name == $arenaname) { $pos111 = explode(",", $this->arena3areapos1); $pos222 = explode(",", $this->arena3areapos2); } if ($this->arena4name == $arenaname) { $pos111 = explode(",", $this->arena4areapos1); $pos222 = explode(",", $this->arena4areapos2); } if ($this->arena5name == $arenaname) { $pos111 = explode(",", $this->arena5areapos1); $pos222 = explode(",", $this->arena5areapos2); } $randx = rand($pos111[0], $pos222[0]); $randz = rand($pos111[2], $pos222[2]); $randy = rand($pos111[1], $pos222[1]); $sender->teleport($this->getServer()->getLevelByName($this->selectarena)->getSafeSpawn(new Position($randx, $randy, $randz))); $sender->setGamemode(3); return true; } else { $sender->sendMessage(MT::RED . 'Round isnt started yet!'); return false; } } else { $name = $sender->getName(); if (in_array($name, $this->players)) { $sender->sendMessage(MT::RED . 'Your are not in Lobby and playing!'); } else { $sender->teleport($this->getServer()->getLevelByName($this->lobbyname)->getSafeSpawn()); $sender->setGamemode(0); } return false; } break; case "playerspawn": $level = $sender->getLevel()->getName(); if ($sender->isOp()) { if (isset($args[0])) { $config = $this->config->getAll(); $ppos = $config["PlayerspawnPos"]; $ppos2 = $config["PlayerspawnPos2"]; $ppos3 = $config["PlayerspawnPos3"]; $ppos4 = $config["PlayerspawnPos4"]; $ppos5 = $config["PlayerspawnPos5"]; if ($args[0] == "add") { if (isset($args[1])) { if ($this->arena1name == $level) { $commandpos = $args[1]; if (!in_array($commandpos, $ppos)) { if (!is_array($ppos)) { $ppos = array($commandpos); return true; } else { $ppos[] = $commandpos; $sender->sendMessage(MT::GREEN . "Position setted " . $commandpos); $config["PlayerspawnPos"] = $ppos; $this->config->setAll($config); $this->config->save(); return true; } } else { $sender->sendMessage(MT::RED . "Position exist"); return false; } } if ($this->arena2name == $level) { $commandpos = $args[1]; if (!in_array($commandpos, $ppos2)) { if (!is_array($ppos2)) { $ppos2 = array($commandpos); return true; } else { $ppos2[] = $commandpos; $sender->sendMessage(MT::GREEN . "Position setted " . $commandpos); $config["PlayerspawnPos2"] = $ppos2; $this->config->setAll($config); $this->config->save(); return true; } } else { $sender->sendMessage(MT::RED . "Position exist"); return false; } } if ($this->arena3name == $level) { $commandpos = $args[1]; if (!in_array($commandpos, $ppos3)) { if (!is_array($ppos3)) { $ppos3 = array($commandpos); return true; } else { $ppos3[] = $commandpos; $sender->sendMessage(MT::GREEN . "Position setted " . $commandpos); $config["PlayerspawnPos3"] = $ppos3; $this->config->setAll($config); $this->config->save(); return true; } } else { $sender->sendMessage(MT::RED . "Position exist"); return false; } } if ($this->arena4name == $level) { $commandpos = $args[1]; if (!in_array($commandpos, $ppos4)) { if (!is_array($ppos4)) { $ppos4 = array($commandpos); return true; } else { $ppos4[] = $commandpos; $sender->sendMessage(MT::GREEN . "Position setted " . $commandpos); $config["PlayerspawnPos4"] = $ppos4; $this->config->setAll($config); $this->config->save(); return true; } } else { $sender->sendMessage(MT::RED . "Position exist"); return false; } } if ($this->arena5name == $level) { $commandpos = $args[1]; if (!in_array($commandpos, $ppos5)) { if (!is_array($ppos5)) { $ppos5 = array($commandpos); return true; } else { $ppos5[] = $commandpos; $sender->sendMessage(MT::GREEN . "Position setted " . $commandpos); $config["PlayerspawnPos5"] = $ppos5; $this->config->setAll($config); $this->config->save(); return true; } } else { $sender->sendMessage(MT::RED . "Position exist"); return false; } } } else { $sender->sendMessage(MT::RED . "Please select a position \nexample : /playerspawn add 10,5,25"); return false; } } if ($args[0] == "dell") { if (isset($args[1])) { $commandpos = $args[1]; if ($this->arena1name == $level) { if (in_array($commandpos, $ppos)) { $key = array_search($commandpos, $ppos); unset($ppos[$key]); $sender->sendMessage(MT::GREEN . "Position deleted " . $commandpos); $config["PlayerspawnPos"] = $ppos; $this->config->setAll($config); $this->config->save(); return true; } else { $sender->sendMessage(MT::RED . "Position dont exist"); return false; } } if ($this->arena2name == $level) { if (in_array($commandpos, $ppos2)) { $key = array_search($commandpos, $ppos2); unset($ppos2[$key]); $sender->sendMessage(MT::GREEN . "Position deleted " . $commandpos); $config["PlayerspawnPos2"] = $ppos2; $this->config->setAll($config); $this->config->save(); return true; } else { $sender->sendMessage(MT::RED . "Position dont exist"); return false; } } if ($this->arena3name == $level) { if (in_array($commandpos, $ppos3)) { $key = array_search($commandpos, $ppos3); unset($ppos3[$key]); $sender->sendMessage(MT::GREEN . "Position deleted " . $commandpos); $config["PlayerspawnPos3"] = $ppos3; $this->config->setAll($config); $this->config->save(); return true; } else { $sender->sendMessage(MT::RED . "Position dont exist"); return false; } } if ($this->arena4name == $level) { if (in_array($commandpos, $ppos4)) { $key = array_search($commandpos, $ppos4); unset($ppos4[$key]); $sender->sendMessage(MT::GREEN . "Position deleted " . $commandpos); $config["PlayerspawnPos4"] = $ppos4; $this->config->setAll($config); $this->config->save(); return true; } else { $sender->sendMessage(MT::RED . "Position dont exist"); return false; } } if ($this->arena5name == $level) { if (in_array($commandpos, $ppos5)) { $key = array_search($commandpos, $ppos5); unset($ppos5[$key]); $sender->sendMessage(MT::GREEN . "Position deleted " . $commandpos); $config["PlayerspawnPos5"] = $ppos5; $this->config->setAll($config); $this->config->save(); return true; } else { $sender->sendMessage(MT::RED . "Position dont exist"); return false; } } } else { $sender->sendMessage(MT::RED . "Please select a position \nexample : /playerspawn dell 10,5,25"); return false; } } if ($args[0] == "list") { $sender->sendMessage(MT::GREEN . "Playerspawns: " . implode(", ", $ppos)); return true; } } else { $sender->sendMessage(MT::RED . 'add / dell / list'); return true; } } else { $sender->sendMessage(MT::RED . 'Only for Operators'); return false; } break; case "chestspawn": $level = $sender->getLevel()->getName(); if ($sender->isOp()) { if (isset($args[0])) { $config = $this->config->getAll(); $ppos = $config["ChestspawnPos"]; $ppos2 = $config["ChestspawnPos2"]; $ppos3 = $config["ChestspawnPos3"]; $ppos4 = $config["ChestspawnPos4"]; $ppos5 = $config["ChestspawnPos5"]; if ($args[0] == "add") { if (isset($args[1])) { $commandpos = $args[1]; if ($this->arena1name == $level) { if (!in_array($commandpos, $ppos)) { if (!is_array($ppos)) { $ppos = array($commandpos); return true; } else { $ppos[] = $commandpos; $sender->sendMessage(MT::GREEN . "Position setted " . $commandpos); $config["ChestspawnPos"] = $ppos; $this->config->setAll($config); $this->config->save(); return true; } } else { $sender->sendMessage(MT::RED . "Position exist"); return false; } } if ($this->arena2name == $level) { if (!in_array($commandpos, $ppos2)) { if (!is_array($ppos2)) { $ppos2 = array($commandpos); return true; } else { $ppos2[] = $commandpos; $sender->sendMessage(MT::GREEN . "Position setted " . $commandpos); $config["ChestspawnPos2"] = $ppos2; $this->config->setAll($config); $this->config->save(); return true; } } else { $player->sendMessage(MT::RED . "Position exist"); return false; } } if ($this->arena3name == $level) { if (!in_array($commandpos, $ppos3)) { if (!is_array($ppos3)) { $ppos3 = array($commandpos); return true; } else { $ppos3[] = $commandpos; $sender->sendMessage(MT::GREEN . "Position setted " . $commandpos); $config["ChestspawnPos3"] = $ppos3; $this->config->setAll($config); $this->config->save(); return true; } } else { $sender->sendMessage(MT::RED . "Position exist"); return false; } } if ($this->arena4name == $level) { if (!in_array($commandpos, $ppos4)) { if (!is_array($ppos4)) { $ppos4 = array($commandpos); return true; } else { $ppos4[] = $commandpos; $sender->sendMessage(MT::GREEN . "Position setted " . $commandpos); $config["ChestspawnPos4"] = $ppos4; $this->config->setAll($config); $this->config->save(); return true; } } else { $sender->sendMessage(MT::RED . "Position exist"); return false; } } if ($this->arena5name == $level) { if (!in_array($commandpos, $ppos5)) { if (!is_array($ppos5)) { $ppos = array($commandpos); return true; } else { $ppos5[] = $commandpos; $sender->sendMessage(MT::GREEN . "Position setted " . $commandpos); $config["ChestspawnPos5"] = $ppos5; $this->config->setAll($config); $this->config->save(); return true; } } else { $sender->sendMessage(MT::RED . "Position exist"); return false; } } } else { $sender->sendMessage(MT::RED . "Please select a position \nexample : /playerspawn add 10,5,25"); return false; } } if ($args[0] == "dell") { if (isset($args[1])) { $commandpos = $args[1]; if ($this->arena1name == $level) { if (in_array($commandpos, $ppos)) { $key = array_search($commandpos, $ppos); unset($ppos[$key]); $sender->sendMessage(MT::GREEN . "Position deleted " . $commandpos); $config["ChestspawnPos"] = $ppos; $this->config->setAll($config); $this->config->save(); return true; } else { $sender->sendMessage(MT::RED . "Position dont exist"); return false; } } if ($this->arena2name == $level) { if (in_array($commandpos, $ppos2)) { $key = array_search($commandpos, $ppos2); unset($ppos2[$key]); $sender->sendMessage(MT::GREEN . "Position deleted " . $commandpos); $config["ChestspawnPos2"] = $ppos2; $this->config->setAll($config); $this->config->save(); return true; } else { $sender->sendMessage(MT::RED . "Position dont exist"); return false; } } if ($this->arena3name == $level) { if (in_array($commandpos, $ppos3)) { $key = array_search($commandpos, $ppos3); unset($ppos3[$key]); $sender->sendMessage(MT::GREEN . "Position deleted " . $commandpos); $config["ChestspawnPos"] = $ppos3; $this->config->setAll($config); $this->config->save(); return true; } else { $sender->sendMessage(MT::RED . "Position dont exist"); return false; } } if ($this->arena4name == $level) { if (in_array($commandpos, $ppos4)) { $key = array_search($commandpos, $ppos4); unset($ppos4[$key]); $sender->sendMessage(MT::GREEN . "Position deleted " . $commandpos); $config["ChestspawnPos4"] = $ppos4; $this->config->setAll($config); $this->config->save(); return true; } else { $sender->sendMessage(MT::RED . "Position dont exist"); return false; } } if ($this->arena5name == $level) { if (in_array($commandpos, $ppos5)) { $key = array_search($commandpos, $ppos5); unset($ppos5[$key]); $sender->sendMessage(MT::GREEN . "Position deleted " . $commandpos); $config["ChestspawnPos5"] = $ppos5; $this->config->setAll($config); $this->config->save(); return true; } else { $sender->sendMessage(MT::RED . "Position dont exist"); return false; } } } else { $sender->sendMessage(MT::RED . "Please select a position \nexample : /playerspawn dell 10,5,25"); return false; } } if ($args[0] == "list") { $sender->sendMessage(MT::GREEN . "Playerspawns: " . implode(", ", $ppos)); return true; } } else { $sender->sendMessage(MT::RED . 'add / dell / list'); return true; } } else { $sender->sendMessage(MT::RED . 'Only for Operators'); return false; } break; } }