<commit_before>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.CommandUsageException;
import in.twizmwaz.cardinal.GameHandler;
import in.twizmwaz.cardinal.chat.ChatConstant;
import in.twizmwaz.cardinal.chat.LocalizedChatMessage;
import in.twizmwaz.cardinal.chat.UnlocalizedChatMessage;
import in.twizmwaz.cardinal.event.TeamNameChangeEvent;
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;

import java.util.ArrayList;
import java.util.List;
import java.util.Random;

public class TeamCommand {

    @Command(aliases = {"team"}, desc = "Manage the teams in the match.", usage = "<force, alias, shuffle> [player, old team] [force team, new team]", min = 1)
    public static void team(final CommandContext cmd, CommandSender sender) throws CommandException {
        if (cmd.getString(0).equalsIgnoreCase("force")) {
            if (sender.hasPermission("cardinal.team.force")) {
                if (cmd.argsLength() >= 3) {
                    if (Bukkit.getPlayer(cmd.getString(1)) != null) {
                        String msg = "";
                        for (int i = 2; i < cmd.argsLength(); i++) {
                            msg += cmd.getString(i) + " ";
                        }
                        msg = msg.trim();
                        if (TeamUtils.getTeamByName(msg) != null) {
                            TeamModule team = TeamUtils.getTeamByName(msg);
                            if (!team.contains(Bukkit.getPlayer(cmd.getString(1)))) {
                                team.add(Bukkit.getPlayer(cmd.getString(1)), true, false);
                                sender.sendMessage(team.getColor() + Bukkit.getPlayer(cmd.getString(1)).getName() + ChatColor.GRAY + " forced to " + team.getCompleteName());
                            } else throw new CommandException(new LocalizedChatMessage(ChatConstant.ERROR_ALREADY_ON_TEAM, TeamUtils.getTeamByPlayer(Bukkit.getPlayer(cmd.getString(1))).getColor() + Bukkit.getPlayer(cmd.getString(1)).getName() + ChatColor.RED, TeamUtils.getTeamByPlayer(Bukkit.getPlayer(cmd.getString(1))).getCompleteName()).getMessage(((Player) sender).getLocale()));
                        } else {
                            throw new CommandException(new LocalizedChatMessage(ChatConstant.ERROR_NO_TEAM_MATCH).getMessage(ChatUtils.getLocale(sender)));
                        }
                    } else {
                        throw new CommandException(new LocalizedChatMessage(ChatConstant.ERROR_NO_PLAYER_MATCH).getMessage(ChatUtils.getLocale(sender)));
                    }
                } else {
                    throw new CommandUsageException("Too few arguments.", "/team <force> <player> <force team>");
                }
            }
        } else if (cmd.getString(0).equalsIgnoreCase("alias")) {
            if (sender.hasPermission("cardinal.team.alias")) {
                if (cmd.argsLength() >= 3) {
                    TeamModule team = TeamUtils.getTeamByName(cmd.getString(1));
                    if (team != null) {
                        String msg = "";
                        for (int i = 2; i < cmd.argsLength(); i++) {
                            msg += cmd.getString(i) + " ";
                        }
                        msg = msg.trim();
                        String locale = ChatUtils.getLocale(sender);
                        sender.sendMessage(ChatColor.GRAY + new LocalizedChatMessage(ChatConstant.GENERIC_TEAM_ALIAS, team.getCompleteName() + ChatColor.GRAY, team.getColor() + msg + ChatColor.GRAY).getMessage(locale));
                        team.setName(msg);
                        Bukkit.getServer().getPluginManager().callEvent(new TeamNameChangeEvent(team));
                    } else {
                        throw new CommandException(new LocalizedChatMessage(ChatConstant.ERROR_NO_TEAM_MATCH).getMessage(ChatUtils.getLocale(sender)));
                    }
                } else {
                    throw new CommandUsageException("Too few arguments!", "/team <alias> <old team> <new team>");
                }
            }
        } else if (cmd.getString(0).equalsIgnoreCase("shuffle")) {
            if (sender.hasPermission("cardinal.team.shuffle")) {
                List<Player> playersToShuffle = new ArrayList<>();
                for (Player player : Bukkit.getOnlinePlayers()) {
                    if (TeamUtils.getTeamByPlayer(player) != null) {
                        if (!TeamUtils.getTeamByPlayer(player).isObserver()) {
                            playersToShuffle.add(player);
                            TeamModule observers = TeamUtils.getTeamById("observers");
                            observers.add(player, true, false);
                        }
                    }
                }
                while (playersToShuffle.size() > 0) {
                    Player player = playersToShuffle.get(new Random().nextInt(playersToShuffle.size()));
                    TeamModule team = TeamUtils.getTeamWithFewestPlayers(GameHandler.getGameHandler().getMatch());
                    team.add(player, true);
                    playersToShuffle.remove(player);
                }
                String locale = ChatUtils.getLocale(sender);
                sender.sendMessage(ChatColor.GREEN + new LocalizedChatMessage(ChatConstant.GENERIC_TEAM_SHUFFLE).getMessage(locale));
            }
        } else {
            throw new CommandUsageException("Invalid arguments.", "/team <force, alias, shuffle> [player, old team] [force team, new team]");
        }
    }

    @Command(aliases = {"myteam", "mt"}, desc = "Shows what team you are on", min = 0, max = 0)
    public static void myTeam(final CommandContext cmd, CommandSender sender) throws CommandException {
        if (!(sender instanceof Player)) {
            return;<commit_msg>Implement team size command<commit_after>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.CommandUsageException;
import com.sk89q.util.StringUtil;
import in.twizmwaz.cardinal.GameHandler;
import in.twizmwaz.cardinal.chat.ChatConstant;
import in.twizmwaz.cardinal.chat.LocalizedChatMessage;
import in.twizmwaz.cardinal.chat.UnlocalizedChatMessage;
import in.twizmwaz.cardinal.event.TeamNameChangeEvent;
import in.twizmwaz.cardinal.module.modules.team.TeamModule;
import in.twizmwaz.cardinal.util.ChatUtils;
import in.twizmwaz.cardinal.util.TeamUtils;
import org.apache.commons.lang.CharUtils;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;

import java.util.ArrayList;
import java.util.List;
import java.util.Random;

public class TeamCommand {

    @Command(aliases = {"team"}, desc = "Manage the teams in the match.", usage = "<force, alias, shuffle> [player, old team] [force team, new team]", min = 1)
    public static void team(final CommandContext cmd, CommandSender sender) throws CommandException {
        if (cmd.getString(0).equalsIgnoreCase("force")) {
            if (sender.hasPermission("cardinal.team.force")) {
                if (cmd.argsLength() >= 3) {
                    if (Bukkit.getPlayer(cmd.getString(1)) != null) {
                        String msg = "";
                        for (int i = 2; i < cmd.argsLength(); i++) {
                            msg += cmd.getString(i) + " ";
                        }
                        msg = msg.trim();
                        if (TeamUtils.getTeamByName(msg) != null) {
                            TeamModule team = TeamUtils.getTeamByName(msg);
                            if (!team.contains(Bukkit.getPlayer(cmd.getString(1)))) {
                                team.add(Bukkit.getPlayer(cmd.getString(1)), true, false);
                                sender.sendMessage(team.getColor() + Bukkit.getPlayer(cmd.getString(1)).getName() + ChatColor.GRAY + " forced to " + team.getCompleteName());
                            } else throw new CommandException(new LocalizedChatMessage(ChatConstant.ERROR_ALREADY_ON_TEAM, TeamUtils.getTeamByPlayer(Bukkit.getPlayer(cmd.getString(1))).getColor() + Bukkit.getPlayer(cmd.getString(1)).getName() + ChatColor.RED, TeamUtils.getTeamByPlayer(Bukkit.getPlayer(cmd.getString(1))).getCompleteName()).getMessage(((Player) sender).getLocale()));
                        } else {
                            throw new CommandException(new LocalizedChatMessage(ChatConstant.ERROR_NO_TEAM_MATCH).getMessage(ChatUtils.getLocale(sender)));
                        }
                    } else {
                        throw new CommandException(new LocalizedChatMessage(ChatConstant.ERROR_NO_PLAYER_MATCH).getMessage(ChatUtils.getLocale(sender)));
                    }
                } else {
                    throw new CommandUsageException("Too few arguments.", "/team <force> <player> <force team>");
                }
            }
        } else if (cmd.getString(0).equalsIgnoreCase("alias")) {
            if (sender.hasPermission("cardinal.team.alias")) {
                if (cmd.argsLength() >= 3) {
                    TeamModule team = TeamUtils.getTeamByName(cmd.getString(1));
                    if (team != null) {
                        String msg = "";
                        for (int i = 2; i < cmd.argsLength(); i++) {
                            msg += cmd.getString(i) + " ";
                        }
                        msg = msg.trim();
                        String locale = ChatUtils.getLocale(sender);
                        sender.sendMessage(ChatColor.GRAY + new LocalizedChatMessage(ChatConstant.GENERIC_TEAM_ALIAS, team.getCompleteName() + ChatColor.GRAY, team.getColor() + msg + ChatColor.GRAY).getMessage(locale));
                        team.setName(msg);
                        Bukkit.getServer().getPluginManager().callEvent(new TeamNameChangeEvent(team));
                    } else {
                        throw new CommandException(new LocalizedChatMessage(ChatConstant.ERROR_NO_TEAM_MATCH).getMessage(ChatUtils.getLocale(sender)));
                    }
                } else {
                    throw new CommandUsageException("Too few arguments!", "/team <alias> <old team> <new team>");
                }
            }
        } else if (cmd.getString(0).equalsIgnoreCase("shuffle")) {
            if (sender.hasPermission("cardinal.team.shuffle")) {
                List<Player> playersToShuffle = new ArrayList<>();
                for (Player player : Bukkit.getOnlinePlayers()) {
                    if (TeamUtils.getTeamByPlayer(player) != null) {
                        if (!TeamUtils.getTeamByPlayer(player).isObserver()) {
                            playersToShuffle.add(player);
                            TeamModule observers = TeamUtils.getTeamById("observers");
                            observers.add(player, true, false);
                        }
                    }
                }
                while (playersToShuffle.size() > 0) {
                    Player player = playersToShuffle.get(new Random().nextInt(playersToShuffle.size()));
                    TeamModule team = TeamUtils.getTeamWithFewestPlayers(GameHandler.getGameHandler().getMatch());
                    team.add(player, true);
                    playersToShuffle.remove(player);
                }
                String locale = ChatUtils.getLocale(sender);
                sender.sendMessage(ChatColor.GREEN + new LocalizedChatMessage(ChatConstant.GENERIC_TEAM_SHUFFLE).getMessage(locale));
            }
        } else if(cmd.getString(0).equalsIgnoreCase("size")) {
          if (sender.hasPermission("cardinal.team.size")) {
              try {
                  TeamUtils.getTeamByName(cmd.getString(1)).setMaxOverfill(Integer.parseInt(cmd.getString(2)));
                  TeamUtils.getTeamByName(cmd.getString(1)).setMax(Integer.parseInt(cmd.getString(2)));
                  sender.sendMessage(TeamUtils.getTeamByName(cmd.getString(1)).getCompleteName() + ChatColor.WHITE + " max-overfill was set to " + ChatColor.AQUA + cmd.getString(2));
              } catch (NumberFormatException e) {
                  throw new CommandException("Team size is not a valid integer");
              }
          }
        } else {
            throw new CommandUsageException("Invalid arguments.", "/team <force, alias, shuffle> [player, old team] [force team, new team]");
        }
    }

    @Command(aliases = {"myteam", "mt"}, desc = "Shows what team you are on", min = 0, max = 0)
    public static void myTeam(final CommandContext cmd, CommandSender sender) throws CommandException {
        if (!(sender instanceof Player)) {
            return;
{'fraction_non_alphanumeric': 0.11543705499166793, 'fraction_numerical': 0.004772004241781549, 'mean_word_length': 2.088421052631579, 'pattern_counts': {'":': 0, '<': 27, '<?xml version=': 0, '>': 29, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2650750', 'n_tokens_mistral': 3571, 'n_tokens_neox': 3428, 'n_words': 619}