    001package net.minecraft.command;
    002
    003import java.util.ArrayList;
    004import java.util.List;
    005import net.minecraft.server.MinecraftServer;
    006
    007public 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[] astring1 = MinecraftServer.getServer().getConfigurationManager().getAvailablePlayerDat();
    103                    ArrayList arraylist = new ArrayList();
    104                    String s = par2ArrayOfStr[par2ArrayOfStr.length - 1];
    105                    String[] astring2 = astring1;
    106                    int i = astring1.length;
    107
    108                    for (int j = 0; j < i; ++j)
    109                    {
    110                        String s1 = astring2[j];
    111
    112                        if (doesStringStartWith(s, s1) && !MinecraftServer.getServer().getConfigurationManager().getWhiteListedPlayers().contains(s1))
    113                        {
    114                            arraylist.add(s1);
    115                        }
    116                    }
    117
    118                    return arraylist;
    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}