    001package net.minecraft.command;
    002
    003import java.util.List;
    004import java.util.regex.Matcher;
    005import net.minecraft.server.MinecraftServer;
    006
    007public class CommandServerPardonIp extends CommandBase
    008{
    009    public String getCommandName()
    010    {
    011        return "pardon-ip";
    012    }
    013
    014    /**
    015     * Return the required permission level for this command.
    016     */
    017    public int getRequiredPermissionLevel()
    018    {
    019        return 3;
    020    }
    021
    022    /**
    023     * Returns true if the given command sender is allowed to use this command.
    024     */
    025    public boolean canCommandSenderUseCommand(ICommandSender par1ICommandSender)
    026    {
    027        return MinecraftServer.getServer().getConfigurationManager().getBannedIPs().isListActive() && super.canCommandSenderUseCommand(par1ICommandSender);
    028    }
    029
    030    public String getCommandUsage(ICommandSender par1ICommandSender)
    031    {
    032        return par1ICommandSender.translateString("commands.unbanip.usage", new Object[0]);
    033    }
    034
    035    public void processCommand(ICommandSender par1ICommandSender, String[] par2ArrayOfStr)
    036    {
    037        if (par2ArrayOfStr.length == 1 && par2ArrayOfStr[0].length() > 1)
    038        {
    039            Matcher matcher = CommandServerBanIp.IPv4Pattern.matcher(par2ArrayOfStr[0]);
    040
    041            if (matcher.matches())
    042            {
    043                MinecraftServer.getServer().getConfigurationManager().getBannedIPs().remove(par2ArrayOfStr[0]);
    044                notifyAdmins(par1ICommandSender, "commands.unbanip.success", new Object[] {par2ArrayOfStr[0]});
    045            }
    046            else
    047            {
    048                throw new SyntaxErrorException("commands.unbanip.invalid", new Object[0]);
    049            }
    050        }
    051        else
    052        {
    053            throw new WrongUsageException("commands.unbanip.usage", new Object[0]);
    054        }
    055    }
    056
    057    /**
    058     * Adds the strings available in this command to the given list of tab completion options.
    059     */
    060    public List addTabCompletionOptions(ICommandSender par1ICommandSender, String[] par2ArrayOfStr)
    061    {
    062        return par2ArrayOfStr.length == 1 ? getListOfStringsFromIterableMatchingLastWord(par2ArrayOfStr, MinecraftServer.getServer().getConfigurationManager().getBannedIPs().getBannedList().keySet()) : null;
    063    }
    064}