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