    001    package net.minecraft.src;
    002
    003    import java.util.List;
    004    import net.minecraft.server.MinecraftServer;
    005
    006    public class CommandServerBan extends CommandBase
    007    {
    008        public String getCommandName()
    009        {
    010            return "ban";
    011        }
    012
    013        public int func_82362_a()
    014        {
    015            return 3;
    016        }
    017
    018        public String getCommandUsage(ICommandSender par1ICommandSender)
    019        {
    020            return par1ICommandSender.translateString("commands.ban.usage", new Object[0]);
    021        }
    022
    023        /**
    024         * Returns true if the given command sender is allowed to use this command.
    025         */
    026        public boolean canCommandSenderUseCommand(ICommandSender par1ICommandSender)
    027        {
    028            return MinecraftServer.getServer().getConfigurationManager().getBannedPlayers().isListActive() && super.canCommandSenderUseCommand(par1ICommandSender);
    029        }
    030
    031        public void processCommand(ICommandSender par1ICommandSender, String[] par2ArrayOfStr)
    032        {
    033            if (par2ArrayOfStr.length >= 1 && par2ArrayOfStr[0].length() > 0)
    034            {
    035                EntityPlayerMP var3 = MinecraftServer.getServer().getConfigurationManager().getPlayerForUsername(par2ArrayOfStr[0]);
    036                BanEntry var4 = new BanEntry(par2ArrayOfStr[0]);
    037                var4.setBannedBy(par1ICommandSender.getCommandSenderName());
    038
    039                if (par2ArrayOfStr.length >= 2)
    040                {
    041                    var4.setBanReason(func_82360_a(par1ICommandSender, par2ArrayOfStr, 1));
    042                }
    043
    044                MinecraftServer.getServer().getConfigurationManager().getBannedPlayers().put(var4);
    045
    046                if (var3 != null)
    047                {
    048                    var3.playerNetServerHandler.kickPlayerFromServer("You are banned from this server.");
    049                }
    050
    051                notifyAdmins(par1ICommandSender, "commands.ban.success", new Object[] {par2ArrayOfStr[0]});
    052            }
    053            else
    054            {
    055                throw new WrongUsageException("commands.ban.usage", new Object[0]);
    056            }
    057        }
    058
    059        /**
    060         * Adds the strings available in this command to the given list of tab completion options.
    061         */
    062        public List addTabCompletionOptions(ICommandSender par1ICommandSender, String[] par2ArrayOfStr)
    063        {
    064            return par2ArrayOfStr.length >= 1 ? getListOfStringsMatchingLastWord(par2ArrayOfStr, MinecraftServer.getServer().getAllUsernames()) : null;
    065        }
    066    }