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