    001    package net.minecraft.src;
    002
    003    import java.util.ArrayList;
    004    import java.util.List;
    005    import net.minecraft.server.MinecraftServer;
    006
    007    public class CommandServerWhitelist extends CommandBase
    008    {
    009        public String getCommandName()
    010        {
    011            return "whitelist";
    012        }
    013
    014        public String getCommandUsage(ICommandSender par1ICommandSender)
    015        {
    016            return par1ICommandSender.translateString("commands.whitelist.usage", new Object[0]);
    017        }
    018
    019        public void processCommand(ICommandSender par1ICommandSender, String[] par2ArrayOfStr)
    020        {
    021            if (par2ArrayOfStr.length >= 1)
    022            {
    023                if (par2ArrayOfStr[0].equals("on"))
    024                {
    025                    MinecraftServer.getServer().getConfigurationManager().setWhiteListEnabled(true);
    026                    notifyAdmins(par1ICommandSender, "commands.whitelist.enabled", new Object[0]);
    027                    return;
    028                }
    029
    030                if (par2ArrayOfStr[0].equals("off"))
    031                {
    032                    MinecraftServer.getServer().getConfigurationManager().setWhiteListEnabled(false);
    033                    notifyAdmins(par1ICommandSender, "commands.whitelist.disabled", new Object[0]);
    034                    return;
    035                }
    036
    037                if (par2ArrayOfStr[0].equals("list"))
    038                {
    039                    par1ICommandSender.sendChatToPlayer(par1ICommandSender.translateString("commands.whitelist.list", new Object[] {Integer.valueOf(MinecraftServer.getServer().getConfigurationManager().getWhiteListedPlayers().size()), Integer.valueOf(MinecraftServer.getServer().getConfigurationManager().getAvailablePlayerDat().length)}));
    040                    par1ICommandSender.sendChatToPlayer(joinNiceString(MinecraftServer.getServer().getConfigurationManager().getWhiteListedPlayers().toArray(new String[0])));
    041                    return;
    042                }
    043
    044                if (par2ArrayOfStr[0].equals("add"))
    045                {
    046                    if (par2ArrayOfStr.length < 2)
    047                    {
    048                        throw new WrongUsageException("commands.whitelist.add.usage", new Object[0]);
    049                    }
    050
    051                    MinecraftServer.getServer().getConfigurationManager().addToWhiteList(par2ArrayOfStr[1]);
    052                    notifyAdmins(par1ICommandSender, "commands.whitelist.add.success", new Object[] {par2ArrayOfStr[1]});
    053                    return;
    054                }
    055
    056                if (par2ArrayOfStr[0].equals("remove"))
    057                {
    058                    if (par2ArrayOfStr.length < 2)
    059                    {
    060                        throw new WrongUsageException("commands.whitelist.remove.usage", new Object[0]);
    061                    }
    062
    063                    MinecraftServer.getServer().getConfigurationManager().removeFromWhitelist(par2ArrayOfStr[1]);
    064                    notifyAdmins(par1ICommandSender, "commands.whitelist.remove.success", new Object[] {par2ArrayOfStr[1]});
    065                    return;
    066                }
    067
    068                if (par2ArrayOfStr[0].equals("reload"))
    069                {
    070                    MinecraftServer.getServer().getConfigurationManager().loadWhiteList();
    071                    notifyAdmins(par1ICommandSender, "commands.whitelist.reloaded", new Object[0]);
    072                    return;
    073                }
    074            }
    075
    076            throw new WrongUsageException("commands.whitelist.usage", new Object[0]);
    077        }
    078
    079        /**
    080         * Adds the strings available in this command to the given list of tab completion options.
    081         */
    082        public List addTabCompletionOptions(ICommandSender par1ICommandSender, String[] par2ArrayOfStr)
    083        {
    084            if (par2ArrayOfStr.length == 1)
    085            {
    086                return getListOfStringsMatchingLastWord(par2ArrayOfStr, new String[] {"on", "off", "list", "add", "remove", "reload"});
    087            }
    088            else
    089            {
    090                if (par2ArrayOfStr.length == 2)
    091                {
    092                    if (par2ArrayOfStr[0].equals("add"))
    093                    {
    094                        String[] var3 = MinecraftServer.getServer().getConfigurationManager().getAvailablePlayerDat();
    095                        ArrayList var4 = new ArrayList();
    096                        String var5 = par2ArrayOfStr[par2ArrayOfStr.length - 1];
    097                        String[] var6 = var3;
    098                        int var7 = var3.length;
    099
    100                        for (int var8 = 0; var8 < var7; ++var8)
    101                        {
    102                            String var9 = var6[var8];
    103
    104                            if (doesStringStartWith(var5, var9) && !MinecraftServer.getServer().getConfigurationManager().getWhiteListedPlayers().contains(var9))
    105                            {
    106                                var4.add(var9);
    107                            }
    108                        }
    109
    110                        return var4;
    111                    }
    112
    113                    if (par2ArrayOfStr[0].equals("remove"))
    114                    {
    115                        return getListOfStringsFromIterableMatchingLastWord(par2ArrayOfStr, MinecraftServer.getServer().getConfigurationManager().getWhiteListedPlayers());
    116                    }
    117                }
    118
    119                return null;
    120            }
    121        }
    122    }