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