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