    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 String getCommandUsage(ICommandSender par1ICommandSender)
    014        {
    015            return par1ICommandSender.translateString("commands.ban.usage", new Object[0]);
    016        }
    017
    018        /**
    019         * Returns true if the given command sender is allowed to use this command.
    020         */
    021        public boolean canCommandSenderUseCommand(ICommandSender par1ICommandSender)
    022        {
    023            return MinecraftServer.getServer().getConfigurationManager().getBannedPlayers().isListActive() && super.canCommandSenderUseCommand(par1ICommandSender);
    024        }
    025
    026        public void processCommand(ICommandSender par1ICommandSender, String[] par2ArrayOfStr)
    027        {
    028            if (par2ArrayOfStr.length >= 1 && par2ArrayOfStr[0].length() > 0)
    029            {
    030                EntityPlayerMP var3 = MinecraftServer.getServer().getConfigurationManager().getPlayerForUsername(par2ArrayOfStr[0]);
    031                BanEntry var4 = new BanEntry(par2ArrayOfStr[0]);
    032                var4.setBannedBy(par1ICommandSender.getCommandSenderName());
    033
    034                if (par2ArrayOfStr.length >= 2)
    035                {
    036                    var4.setBanReason(joinString(par2ArrayOfStr, 1));
    037                }
    038
    039                MinecraftServer.getServer().getConfigurationManager().getBannedPlayers().put(var4);
    040
    041                if (var3 != null)
    042                {
    043                    var3.playerNetServerHandler.kickPlayerFromServer("You are banned from this server.");
    044                }
    045
    046                notifyAdmins(par1ICommandSender, "commands.ban.success", new Object[] {par2ArrayOfStr[0]});
    047            }
    048            else
    049            {
    050                throw new WrongUsageException("commands.ban.usage", new Object[0]);
    051            }
    052        }
    053
    054        /**
    055         * Adds the strings available in this command to the given list of tab completion options.
    056         */
    057        public List addTabCompletionOptions(ICommandSender par1ICommandSender, String[] par2ArrayOfStr)
    058        {
    059            return par2ArrayOfStr.length >= 1 ? getListOfStringsMatchingLastWord(par2ArrayOfStr, MinecraftServer.getServer().getAllUsernames()) : null;
    060        }
    061    }