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 com.sk89q.minecraft.util.commands.CommandPermissions;
import in.twizmwaz.cardinal.GameHandler;
import in.twizmwaz.cardinal.module.modules.chatChannels.AdminChannel;
import in.twizmwaz.cardinal.module.modules.chatChannels.ChatChannelModule;
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 PunishmentCommands {
    @Command(aliases = {"kick", "k"}, desc = "Kick a player", usage = "<player> [message]", min = 2)
    @CommandPermissions({"cardinal.punish.kick"})
    public static void kick(CommandContext cmd, CommandSender sender)
            throws CommandException {
        Player kicked = Bukkit.getPlayer(cmd.getString(0));
        if (kicked.isOnline()) {
            String reason = "";
            for (int i = 1; i < cmd.argsLength(); i++) {
                reason = reason + cmd.getString(i) + " ";
            }
            reason = reason.trim();
            Bukkit.broadcastMessage(ChatColor.GOLD + "*Console" + ChatColor.GOLD + " Kicked " + TeamUtils.getTeamByPlayer(kicked).getColor() + kicked.getDisplayName() + ChatColor.GOLD + " for " + ChatColor.DARK_AQUA + reason);
            kicked.kickPlayer(ChatColor.DARK_PURPLE + "You have been " + ChatColor.YELLOW + "kicked" + ChatColor.DARK_PURPLE + "for \n" + ChatColor.YELLOW + ChatColor.BOLD + reason + "\n " + ChatColor.DARK_PURPLE + "by " + ((sender instanceof Player) ? TeamUtils.getTeamByPlayer((Player) sender).getColor() + ((Player) sender).getDisplayName() : new StringBuilder().append(ChatColor.GOLD).append("*Console").toString()));
        } else {
            throw new CommandException("Player must be online!");
        }
    }

    @Command(aliases = {"warn", "w"}, usage = "<player> [reason]", desc = "Warn a player", min = 2)
    @CommandPermissions({"cardinal.punish.warn"})
    public static void warn(CommandContext cmd, CommandSender sender)
            throws CommandException {
        Player warned = Bukkit.getPlayer(cmd.getString(0));
        if (warned.isOnline()) {
            String reason = "";
            for (int i = 1; i < cmd.argsLength(); i++) {
                reason = reason + cmd.getString(i) + " ";
            }
            reason = reason.trim();
            Bukkit.broadcastMessage(ChatColor.GOLD + "*Console" + ChatColor.GOLD + " Kicked " + TeamUtils.getTeamByPlayer(warned).getColor() + warned.getDisplayName() + ChatColor.GOLD + " for " + ChatColor.DARK_AQUA + reason);
            ChatChannelModule channel = (ChatChannelModule) GameHandler.getGameHandler().getMatch().getModules().getModule(AdminChannel.class);
            channel.sendMessage("[" + ChatColor.YELLOW + "A" + ChatColor.WHITE + "] " + ((sender instanceof Player) ? TeamUtils.getTeamByPlayer((Player) sender).getColor() + ((Player) sender).getDisplayName() : new StringBuilder().append(ChatColor.GOLD).append("*Console").append(ChatColor.GOLD).append(" Kicked ").append(TeamUtils.getTeamByPlayer(warned).getColor()).append(warned.getDisplayName()).append(ChatColor.GOLD).append(" for ").append(ChatColor.DARK_AQUA).append(reason).toString()));
            warned.sendMessage(ChatColor.RED + "" + ChatColor.MAGIC + "-------" + ChatColor.YELLOW + "WARNING" + ChatColor.RED + ChatColor.MAGIC + "-------");
            warned.sendMessage(ChatColor.GREEN + reason);
            warned.sendMessage(ChatColor.YELLOW + reason);
            warned.sendMessage(ChatColor.RED + reason);
            warned.sendMessage(ChatColor.RED + "" + ChatColor.MAGIC + "-------" + ChatColor.YELLOW + "WARNING" + ChatColor.RED + ChatColor.MAGIC + "-------");
        } else {
            throw new CommandException("Player must be online!");
        }
    }

    @Command(aliases = {"ban"}, usage = "<player> [reason]", desc = "Ban a player from the server", min = 2)
    @CommandPermissions({"cardinal.punish.ban"})
    public static void ban(CommandContext cmd, CommandSender sender)
            throws CommandException {
        Player banned = Bukkit.getPlayer(cmd.getString(0));
        String reason = "";
        for (int i = 1; i < cmd.argsLength(); i++) {
            reason = reason + cmd.getString(i) + " ";
        }
        reason = reason.trim();
        Bukkit.broadcastMessage(ChatColor.GOLD + "*Console" + ChatColor.GOLD + " Kicked " + TeamUtils.getTeamByPlayer(banned).getColor() + banned.getDisplayName() + ChatColor.GOLD + " for " + ChatColor.DARK_AQUA + reason);
        banned.kickPlayer(ChatColor.DARK_PURPLE + "You have been " + ChatColor.RED + "banned" + ChatColor.DARK_PURPLE + "for \n" + ChatColor.YELLOW + ChatColor.BOLD + reason + "\n " + ChatColor.DARK_PURPLE + "by " + ((sender instanceof Player) ? TeamUtils.getTeamByPlayer((Player) sender).getColor() + ((Player) sender).getDisplayName() : new StringBuilder().append(ChatColor.GOLD).append("*Console").toString()));
    }
}

@@ -737,17 +737,16 @@
 er%3E 
-%5Bmessage%5D
+%3Creason%3E
 %22, m
@@ -769,33 +769,32 @@
 mandPermissions(
-%7B
 %22cardinal.punish
@@ -799,17 +799,16 @@
 sh.kick%22
-%7D
 )%0A    pu
@@ -2000,32 +2000,32 @@
 = %22%3Cplayer%3E 
-%5B
+%3C
 reason
-%5D
+%3E
 %22, desc = %22W
@@ -2064,33 +2064,32 @@
 mandPermissions(
-%7B
 %22cardinal.punish
@@ -2094,17 +2094,16 @@
 sh.warn%22
-%7D
 )%0A    pu
@@ -4085,17 +4085,16 @@
 issions(
-%7B
 %22cardina
@@ -4106,17 +4106,16 @@
 ish.ban%22
-%7D
 )%0A    pu

Fix permissions with punishments, fixes #262