Andre\SurvivalGames\Main::onCommand PHP Method

onCommand() public method

public onCommand ( pocketmine\command\CommandSender $sender, Command $command, $label, array $args )
$sender pocketmine\command\CommandSender
$command pocketmine\command\Command
$args array
    public function onCommand(CommandSender $sender, Command $command, $label, array $args)
    {
        if ($command->getName() == "lobby") {
            if ($this->gameStatus >= 2) {
                $sender->sendMessage("[{$this->getConfig()->get("prefix")}] {$Already_Playing}");
                return;
            }
            if (isset($this->players[$sender->getName()])) {
                unset($this->players[$sender->getName()]);
                $sender->setLevel($this->signlevel);
                $sender->teleport($this->signlevel->getSpawnLocation());
                $sender->sendMessage(TextFormat::GREEN . "[{$this->getConfig()->get("prefix")}] Teleporting to lobby...");
                $this->getServer()->broadcastMessage(TextFormat::RED . "[{$this->getConfig()->get("prefix")}]Player " . $sender->getName() . " left the match.");
                $this->changeStatusSign();
                if ($this->gameStatus == 1 && count($this->players) < 2) {
                    $this->gameStatus = 0;
                    $this->lastTime = 0;
                    $event->getPlayer()->sendMessage("[{$this->getConfig()->get("prefix")}] {$Arena}");
                    /*foreach($this->players as $pl)
                    		{
                    			$p=$this->getServer()->getPlayer($pl["id"]);
                    			$p->setLevel($this->signlevel);
                    			$p->teleport($this->signlevel->getSpawnLocation());
                    			unset($p,$pl);
                    		}*/
                }
            } else {
                $sender->sendMessage(TextFormat::RED . "[{$this->getConfig()->get("prefix")}] {$Not_In_Match}");
            }
            return true;
        }
        if (!isset($args[0])) {
            unset($sender, $cmd, $label, $args);
            return false;
        }
        switch ($args[0]) {
            case "help":
                if ($sender->hasPermission("sg.command.help") or $sender->hasPermission("sg.command") or $sender->hasPermission("sg")) {
                    $sender->sendMessage("§d§o-------SurvivalGames Help-------");
                    $sender->sendMessage("§d§oUse §e/sg stats - View your stats");
                    $sender->sendMessage("§d§oUse §e/sg set - Set up an arena");
                    $sender->sendMessage("§d§oUse §e/sg remove - Remove a arena");
                    $sender->sendMessage("§d§oUse §e/sg start - Force start a match");
                    $sender->sendMessage("§d§oUse §e/sg reload - Reload the spawn positions");
                    $sender->sendMessage("§d§o--------------------------------");
                    return true;
                }
                break;
            case "stats":
                if ($sender instanceof Player) {
                    if ($sender->hasPermission("sg.command.stats") or $sender->hasPermission("sg.command") or $sender->hasPermission("sg")) {
                        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(TextFormat::RED . "[{$this->getConfig()->get("prefix")}] ---------------");
                            $sender->sendMessage(TextFormat::RED . "[{$this->getConfig()->get("prefix")}] §bYou're stats");
                            $sender->sendMessage(TextFormat::RED . "[{$this->getConfig()->get("prefix")}] §lDeaths: §9{$deaths}");
                            $sender->sendMessage(TextFormat::RED . "[{$this->getConfig()->get("prefix")}] §lKills: §9{$kills}");
                            $sender->sendMessage(TextFormat::RED . "[{$this->getConfig()->get("prefix")}] ---------------");
                            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(TextFormat::RED . "[{$this->getConfig()->get("prefix")}] ---------------");
                            $sender->sendMessage(TextFormat::RED . "[{$this->getConfig()->get("prefix")}] §bPlayer: §9{$player} Stats");
                            $sender->sendMessage(TextFormat::RED . "[{$this->getConfig()->get("prefix")}] §lDeaths: §9{$deaths}");
                            $sender->sendMessage(TextFormat::RED . "[{$this->getConfig()->get("prefix")}] §lKills: §9{$kills}");
                            $sender->sendMessage(TextFormat::RED . "[{$this->getConfig()->get("prefix")}] ---------------");
                            return true;
                        }
                    } else {
                        $sender->sendMessage("{$No_Permission}");
                        return true;
                    }
                } else {
                    $sender->sendMessage(TextFormat::RED . "That command can only be used in-game!");
                    return true;
                }
                break;
            case "set":
                if ($sender instanceof Player) {
                    if ($this->config->exists("lastpos")) {
                        $sender->sendMessage("Seems like you have already setup an arena");
                    } else {
                        $name = $sender->getName();
                        $this->SetStatus[$name] = 0;
                        $sender->sendMessage("Tap a sign to set it as join sign!");
                    }
                } else {
                    $sender->sendMessage(TextFormat::RED . "You may only use ths command in-game!");
                    return true;
                }
                break;
            case "remove":
                $this->config->remove("sign");
                $this->config->remove("pos1");
                $this->config->remove("pos2");
                $this->config->remove("pos3");
                $this->config->remove("pos4");
                $this->config->remove("pos5");
                $this->config->remove("pos6");
                $this->config->remove("pos7");
                $this->config->remove("pos8");
                $this->config->remove("pos9");
                $this->config->remove("pos10");
                $this->config->remove("pos11");
                $this->config->remove("pos12");
                $this->config->remove("pos13");
                $this->config->remove("pos14");
                $this->config->remove("pos15");
                $this->config->remove("pos16");
                $this->config->remove("pos17");
                $this->config->remove("pos18");
                $this->config->remove("pos19");
                $this->config->remove("pos20");
                $this->config->remove("pos21");
                $this->config->remove("pos22");
                $this->config->remove("pos23");
                $this->config->remove("pos24");
                $this->config->remove("lastpos");
                $this->config->save();
                unset($this->sign, $this->pos1, $this->pos2, $this->pos3, $this->pos4, $this->pos5, $this->pos6, $this->pos7, $this->pos8, $this->pos9, $this->pos10, $this->pos11, $this->pos12, $this->pos13, $this->pos14, $this->pos15, $this->pos16, $this->pos17, $this->pos18, $this->pos19, $this->pos20, $this->pos21, $this->pos22, $this->pos23, $this->pos24, $this->lastpos);
                $sender->sendMessage(TextFormat::GREEN . "Game settings successfully removed.");
                break;
            case "start":
                $this->getServer()->broadcastMessage(TextFormat::BLUE . "{$Force_Start}");
                $this->gameStatus = 1;
                $this->lastTime = 5;
                break;
            case "reload":
                @mkdir($this->getDataFolder(), 0777, true);
                $this->config = new Config($this->getDataFolder() . "config.yml", Config::YAML, array());
                if ($this->config->exists("lastpos")) {
                    $this->sign = $this->config->get("sign");
                    $this->pos1 = $this->config->get("pos1");
                    $this->pos2 = $this->config->get("pos2");
                    $this->pos3 = $this->config->get("pos3");
                    $this->pos4 = $this->config->get("pos4");
                    $this->pos5 = $this->config->get("pos5");
                    $this->pos6 = $this->config->get("pos6");
                    $this->pos7 = $this->config->get("pos7");
                    $this->pos8 = $this->config->get("pos8");
                    $this->pos9 = $this->config->get("pos9");
                    $this->pos10 = $this->config->get("pos10");
                    $this->pos11 = $this->config->get("pos11");
                    $this->pos12 = $this->config->get("pos12");
                    $this->pos13 = $this->config->get("pos13");
                    $this->pos14 = $this->config->get("pos14");
                    $this->pos15 = $this->config->get("pos15");
                    $this->pos16 = $this->config->get("pos16");
                    $this->pos17 = $this->config->get("pos17");
                    $this->pos18 = $this->config->get("pos18");
                    $this->pos19 = $this->config->get("pos19");
                    $this->pos20 = $this->config->get("pos20");
                    $this->pos21 = $this->config->get("pos21");
                    $this->pos22 = $this->config->get("pos22");
                    $this->pos23 = $this->config->get("pos23");
                    $this->pos24 = $this->config->get("pos24");
                    $this->lastpos = $this->config->get("lastpos");
                    $this->signlevel = $this->getServer()->getLevelByName($this->config->get("sign")["level"]);
                    $this->sign = new Vector3($this->sign["x"], $this->sign["y"], $this->sign["z"]);
                    $this->pos1 = new Vector3($this->pos1["x"] + 0.5, $this->pos1["y"], $this->pos1["z"] + 0.5);
                    $this->pos2 = new Vector3($this->pos2["x"] + 0.5, $this->pos2["y"], $this->pos2["z"] + 0.5);
                    $this->pos3 = new Vector3($this->pos3["x"] + 0.5, $this->pos3["y"], $this->pos3["z"] + 0.5);
                    $this->pos4 = new Vector3($this->pos4["x"] + 0.5, $this->pos4["y"], $this->pos4["z"] + 0.5);
                    $this->pos5 = new Vector3($this->pos5["x"] + 0.5, $this->pos5["y"], $this->pos5["z"] + 0.5);
                    $this->pos6 = new Vector3($this->pos6["x"] + 0.5, $this->pos6["y"], $this->pos6["z"] + 0.5);
                    $this->pos7 = new Vector3($this->pos7["x"] + 0.5, $this->pos7["y"], $this->pos7["z"] + 0.5);
                    $this->pos8 = new Vector3($this->pos8["x"] + 0.5, $this->pos8["y"], $this->pos8["z"] + 0.5);
                    $this->pos9 = new Vector3($this->pos9["x"] + 0.5, $this->pos9["y"], $this->pos9["z"] + 0.5);
                    $this->pos10 = new Vector3($this->pos10["x"] + 0.5, $this->pos10["y"], $this->pos10["z"] + 0.5);
                    $this->pos11 = new Vector3($this->pos11["x"] + 0.5, $this->pos11["y"], $this->pos11["z"] + 0.5);
                    $this->pos12 = new Vector3($this->pos12["x"] + 0.5, $this->pos12["y"], $this->pos12["z"] + 0.5);
                    $this->pos13 = new Vector3($this->pos13["x"] + 0.5, $this->pos13["y"], $this->pos13["z"] + 0.5);
                    $this->pos14 = new Vector3($this->pos14["x"] + 0.5, $this->pos14["y"], $this->pos14["z"] + 0.5);
                    $this->pos15 = new Vector3($this->pos15["x"] + 0.5, $this->pos15["y"], $this->pos15["z"] + 0.5);
                    $this->pos16 = new Vector3($this->pos16["x"] + 0.5, $this->pos16["y"], $this->pos16["z"] + 0.5);
                    $this->pos17 = new Vector3($this->pos17["x"] + 0.5, $this->pos17["y"], $this->pos17["z"] + 0.5);
                    $this->pos18 = new Vector3($this->pos18["x"] + 0.5, $this->pos18["y"], $this->pos18["z"] + 0.5);
                    $this->pos19 = new Vector3($this->pos19["x"] + 0.5, $this->pos19["y"], $this->pos19["z"] + 0.5);
                    $this->pos20 = new Vector3($this->pos20["x"] + 0.5, $this->pos20["y"], $this->pos20["z"] + 0.5);
                    $this->pos21 = new Vector3($this->pos21["x"] + 0.5, $this->pos21["y"], $this->pos21["z"] + 0.5);
                    $this->pos22 = new Vector3($this->pos22["x"] + 0.5, $this->pos22["y"], $this->pos22["z"] + 0.5);
                    $this->pos23 = new Vector3($this->pos23["x"] + 0.5, $this->pos23["y"], $this->pos23["z"] + 0.5);
                    $this->pos24 = new Vector3($this->pos24["x"] + 0.5, $this->pos24["y"], $this->pos24["z"] + 0.5);
                    $this->lastpos = new Vector3($this->lastpos["x"] + 0.5, $this->lastpos["y"], $this->lastpos["z"] + 0.5);
                }
                if (!$this->config->exists("gameTime")) {
                    $this->config->set("gameTime", 300);
                }
                if (!$this->config->exists("prefix")) {
                    $this->config->set("prefix", "Game");
                }
                $this->gameTime = (int) $this->config->get("gameTime");
                $this->prefix = (int) $this->config->get("prefix");
                $this->gameStatus = 0;
                $this->lastTime = 0;
                $this->players = array();
                $this->SetStatus = array();
                $this->all = 0;
                //
                $this->config->save();
                $sender->sendMessage(TextFormat::GREEN . "All SurvivalGames configuration has been reloaded");
                break;
            default:
                return false;
                break;
        }
        return true;
    }