package net.minecraft.command;

import java.util.List;
import net.minecraft.entity.player.EntityPlayerMP;
import net.minecraft.item.Item;
import net.minecraft.server.MinecraftServer;

public class CommandClearInventory extends CommandBase
{
	private static final String __OBFID = "CL_00000218";

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

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

	public int getRequiredPermissionLevel()
	{
		return 2;
	}

	public void processCommand(ICommandSender par1ICommandSender, String[] par2ArrayOfStr)
	{
		EntityPlayerMP entityplayermp = par2ArrayOfStr.length == 0 ? getCommandSenderAsPlayer(par1ICommandSender) : getPlayer(par1ICommandSender, par2ArrayOfStr[0]);
		Item item = par2ArrayOfStr.length >= 2 ? getItemByText(par1ICommandSender, par2ArrayOfStr[1]) : null;
		int i = par2ArrayOfStr.length >= 3 ? parseIntWithMin(par1ICommandSender, par2ArrayOfStr[2], 0) : -1;

		if (par2ArrayOfStr.length >= 2 && item == null)
		{
			throw new CommandException("commands.clear.failure", new Object[] {entityplayermp.getCommandSenderName()});
		}
		else
		{
			int j = entityplayermp.inventory.clearInventory(item, i);
			entityplayermp.inventoryContainer.detectAndSendChanges();

			if (!entityplayermp.capabilities.isCreativeMode)
			{
				entityplayermp.updateHeldItem();
			}

			if (j == 0)
			{
				throw new CommandException("commands.clear.failure", new Object[] {entityplayermp.getCommandSenderName()});
			}
			else
			{
				notifyAdmins(par1ICommandSender, "commands.clear.success", new Object[] {entityplayermp.getCommandSenderName(), Integer.valueOf(j)});
			}
		}
	}

	public List addTabCompletionOptions(ICommandSender par1ICommandSender, String[] par2ArrayOfStr)
	{
		return par2ArrayOfStr.length == 1 ? getListOfStringsMatchingLastWord(par2ArrayOfStr, this.func_147209_d()) : (par2ArrayOfStr.length == 2 ? getListOfStringsFromIterableMatchingLastWord(par2ArrayOfStr, Item.itemRegistry.getKeys()) : null);
	}

	protected String[] func_147209_d()
	{
		return MinecraftServer.getServer().getAllUsernames();
	}

	public boolean isUsernameIndex(String[] par1ArrayOfStr, int par2)
	{
		return par2 == 0;
	}
}