package in.twizmwaz.cardinal.command;

import com.sk89q.minecraft.util.commands.*;
import in.twizmwaz.cardinal.GameHandler;
import in.twizmwaz.cardinal.rotation.LoadedMap;
import org.bukkit.command.CommandSender;

public class CycleCommand {

    @Command(aliases = {"cycle"}, desc = "Cycles the world and loads a new world.", usage = "[time]")
    @CommandPermissions("cardinal.match.cycle")
    public static void cycle(final CommandContext cmd, CommandSender sender) throws CommandException {
        if (GameHandler.getGameHandler().getMatch().isRunning()) {
            throw new CommandException("Cannot cycle while the match is running!");
        }
        try {
            GameHandler.getGameHandler().startCycleTimer(cmd.getInteger(0));
        } catch (IndexOutOfBoundsException e) {
            GameHandler.getGameHandler().startCycleTimer(30);
        }
    }

    @Command(aliases = {"setnext", "sn"}, desc = "Sets the next map.", usage = "[map]", min = 0)
    @CommandPermissions("cardinal.match.setnext")
    public static void setNext(final CommandContext cmd, CommandSender sender) throws CommandException {
        String input = "";
        try {
            for (int i = 0; i < cmd.argsLength(); i++) {
                input = input + cmd.getString(i);
            }
        } catch (IndexOutOfBoundsException ex) {
            throw new CommandException("Please specify a map!");
        }
        LoadedMap nextMap = null;
        for (LoadedMap loadedMap : GameHandler.getGameHandler().getRotation().getLoaded()) {
            if (loadedMap.getName().toLowerCase().replaceAll(" ", "").equalsIgnoreCase(input.toLowerCase())) {
                nextMap = loadedMap;
            }
        }
        if (nextMap == null) {
            for (LoadedMap loadedMap : GameHandler.getGameHandler().getRotation().getLoaded()) {
                if (loadedMap.getName().toLowerCase().replaceAll(" ", "").startsWith(input.toLowerCase())) {
                    nextMap = loadedMap;
                }
            }
        }
        if (nextMap == null) {
            throw new CommandException("No map named " + input);
        } else {
            GameHandler.getGameHandler().getCycle().setMap(nextMap);
            sender.sendMessage(ChatColor.DARK_PURPLE + "Next map set to " + ChatColor.GOLD + nextMap.getName());
        }
    }

}

@@ -149,26 +149,130 @@
 nal.
-rotation.LoadedMap
+module.modules.team.TeamModule;%0Aimport in.twizmwaz.cardinal.rotation.LoadedMap;%0Aimport in.twizmwaz.cardinal.util.TeamUtils
 ;%0Aim
@@ -440,16 +440,29 @@
 %22%5Btime%5D%22
+, flags = %22f%22
 )%0A    @C
@@ -669,24 +669,403 @@
 unning()) %7B%0A
+            if(cmd.hasFlag('f'))%7B%0A                try %7B%0A                    TeamModule team = TeamUtils.getTeamByName(cmd.getString(0));%0A                    GameHandler.getGameHandler().getMatch().end(team);%0A                %7D catch (IndexOutOfBoundsException ex) %7B%0A                    GameHandler.getGameHandler().getMatch().end(null);%0A                %7D%0A            %7D else %7B%0A    
             
@@ -1132,24 +1132,38 @@
 running!%22);%0A
+            %7D%0A
         %7D%0A  

add a force flag to cycle