package net.minecraft.command.server;

import java.util.ArrayList;
import java.util.List;
import net.minecraft.command.CommandBase;
import net.minecraft.command.ICommandSender;
import net.minecraft.command.WrongUsageException;
import net.minecraft.server.MinecraftServer;

public class CommandOp extends CommandBase
{
	private static final String __OBFID = "CL_00000694";

	public String getCommandName()
	{
		return "op";
	}

	public int getRequiredPermissionLevel()
	{
		return 3;
	}

	public String getCommandUsage(ICommandSender par1ICommandSender)
	{
		return "commands.op.usage";
	}

	public void processCommand(ICommandSender par1ICommandSender, String[] par2ArrayOfStr)
	{
		if (par2ArrayOfStr.length == 1 && par2ArrayOfStr[0].length() > 0)
		{
			MinecraftServer.getServer().getConfigurationManager().addOp(par2ArrayOfStr[0]);
			notifyAdmins(par1ICommandSender, "commands.op.success", new Object[] {par2ArrayOfStr[0]});
		}
		else
		{
			throw new WrongUsageException("commands.op.usage", new Object[0]);
		}
	}

	public List addTabCompletionOptions(ICommandSender par1ICommandSender, String[] par2ArrayOfStr)
	{
		if (par2ArrayOfStr.length == 1)
		{
			String s = par2ArrayOfStr[par2ArrayOfStr.length - 1];
			ArrayList arraylist = new ArrayList();
			String[] astring1 = MinecraftServer.getServer().getAllUsernames();
			int i = astring1.length;

			for (int j = 0; j < i; ++j)
			{
				String s1 = astring1[j];

				if (!MinecraftServer.getServer().getConfigurationManager().isPlayerOpped(s1) && doesStringStartWith(s, s1))
				{
					arraylist.add(s1);
				}
			}

			return arraylist;
		}
		else
		{
			return null;
		}
	}
}