package net.minecraft.command.server;

import java.util.List;
import net.minecraft.command.CommandBase;
import net.minecraft.command.ICommandSender;
import net.minecraft.command.WrongUsageException;
import net.minecraft.entity.player.EntityPlayerMP;
import net.minecraft.server.MinecraftServer;
import net.minecraft.server.management.BanEntry;

public class CommandBanPlayer extends CommandBase
{
	private static final String __OBFID = "CL_00000165";

	public String getCommandName()
	{
		return "ban";
	}

	public int getRequiredPermissionLevel()
	{
		return 3;
	}

	public String getCommandUsage(ICommandSender par1ICommandSender)
	{
		return "commands.ban.usage";
	}

	public boolean canCommandSenderUseCommand(ICommandSender par1ICommandSender)
	{
		return MinecraftServer.getServer().getConfigurationManager().getBannedPlayers().isListActive() && super.canCommandSenderUseCommand(par1ICommandSender);
	}

	public void processCommand(ICommandSender par1ICommandSender, String[] par2ArrayOfStr)
	{
		if (par2ArrayOfStr.length >= 1 && par2ArrayOfStr[0].length() > 0)
		{
			EntityPlayerMP entityplayermp = MinecraftServer.getServer().getConfigurationManager().getPlayerForUsername(par2ArrayOfStr[0]);
			BanEntry banentry = new BanEntry(par2ArrayOfStr[0]);
			banentry.setBannedBy(par1ICommandSender.getCommandSenderName());

			if (par2ArrayOfStr.length >= 2)
			{
				banentry.setBanReason(func_147178_a(par1ICommandSender, par2ArrayOfStr, 1).getUnformattedText());
			}

			MinecraftServer.getServer().getConfigurationManager().getBannedPlayers().put(banentry);

			if (entityplayermp != null)
			{
				entityplayermp.playerNetServerHandler.kickPlayerFromServer("You are banned from this server.");
			}

			notifyAdmins(par1ICommandSender, "commands.ban.success", new Object[] {par2ArrayOfStr[0]});
		}
		else
		{
			throw new WrongUsageException("commands.ban.usage", new Object[0]);
		}
	}

	public List addTabCompletionOptions(ICommandSender par1ICommandSender, String[] par2ArrayOfStr)
	{
		return par2ArrayOfStr.length >= 1 ? getListOfStringsMatchingLastWord(par2ArrayOfStr, MinecraftServer.getServer().getAllUsernames()) : null;
	}
}