package in.twizmwaz.cardinal.command;

import com.sk89q.minecraft.util.commands.Command;
import com.sk89q.minecraft.util.commands.CommandContext;
import com.sk89q.minecraft.util.commands.CommandException;
import in.twizmwaz.cardinal.GameHandler;
import in.twizmwaz.cardinal.match.Match;
import in.twizmwaz.cardinal.match.MatchState;
import in.twizmwaz.cardinal.module.modules.matchTimer.MatchTimer;
import in.twizmwaz.cardinal.module.modules.startTimer.StartTimer;
import in.twizmwaz.cardinal.module.modules.team.TeamModule;
import in.twizmwaz.cardinal.util.ChatUtils;
import in.twizmwaz.cardinal.util.TeamUtils;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;

public class ReadyCommand {

    @Command(aliases = {"ready"}, desc = "Make your team ready.")
    public static void ready(final CommandContext cmd, CommandSender sender) throws CommandException {
        if (!(sender instanceof Player)) throw new CommandException("Console cannot use this command!");
        if (GameHandler.getGameHandler().getMatch().getState().equals(MatchState.WAITING)) {
            TeamModule team = TeamUtils.getTeamByPlayer((Player) sender);
            if (!team.isReady()) {
                team.setReady(true);
                ChatUtils.getGlobalChannel().sendMessage(team.getCompleteName() + ChatColor.YELLOW + " is now ready");
                if (TeamUtils.teamsReady()) GameHandler.getGameHandler().getMatch().start(600);
            } else throw new CommandException("Your team is already ready!");
        }
    }

    @Command(aliases = {"unready"}, desc = "Make your team not ready.")
    public static void unready(final CommandContext cmd, CommandSender sender) throws CommandException {
        if (!(sender instanceof Player)) throw new CommandException("Console cannot use this command!");
        if (GameHandler.getGameHandler().getMatch().getState().equals(MatchState.WAITING)) {
            TeamModule team = TeamUtils.getTeamByPlayer((Player) sender);
            if (team.isReady()) {
                team.setReady(false);
                ChatUtils.getGlobalChannel().sendMessage(team.getCompleteName() + ChatColor.YELLOW + " is no longer ready");
                if (GameHandler.getGameHandler().getMatch().getState().equals(MatchState.STARTING)) {
                    GameHandler.getGameHandler().getMatch().setState(MatchState.WAITING);
                    GameHandler.getGameHandler().getMatch().getModules().getModule(StartTimer.class).setCancelled(true);
                    ChatUtils.getGlobalChannel().sendMessage(ChatColor.RED + "Match start countdown cancelled because " + team.getCompleteName() + ChatColor.RED + " became un-ready.");
                }
            } else throw new CommandException("Your team is already not ready!");
        }
    }

}

@@ -1572,32 +1572,112 @@
 dy!%22);%0A        %7D
+ else throw new CommandException(%22You cannot ready up during or after a match%22);
 %0A    %7D%0A%0A    @Com
@@ -2917,22 +2917,101 @@
 );%0A        %7D
+ else throw new CommandException(%22You cannot unready during or after a match%22);
 %0A    %7D%0A%0A%7D%0A

Add error message to ready command when not waiting state