    001package net.minecraft.command;
    002
    003import java.util.List;
    004import net.minecraft.entity.player.EntityPlayerMP;
    005import net.minecraft.server.MinecraftServer;
    006
    007public class CommandClearInventory extends CommandBase
    008{
    009    public String getCommandName()
    010    {
    011        return "clear";
    012    }
    013
    014    public String getCommandUsage(ICommandSender par1ICommandSender)
    015    {
    016        return par1ICommandSender.translateString("commands.clear.usage", new Object[0]);
    017    }
    018
    019    /**
    020     * Return the required permission level for this command.
    021     */
    022    public int getRequiredPermissionLevel()
    023    {
    024        return 2;
    025    }
    026
    027    public void processCommand(ICommandSender par1ICommandSender, String[] par2ArrayOfStr)
    028    {
    029        EntityPlayerMP entityplayermp = par2ArrayOfStr.length == 0 ? getCommandSenderAsPlayer(par1ICommandSender) : func_82359_c(par1ICommandSender, par2ArrayOfStr[0]);
    030        int i = par2ArrayOfStr.length >= 2 ? parseIntWithMin(par1ICommandSender, par2ArrayOfStr[1], 1) : -1;
    031        int j = par2ArrayOfStr.length >= 3 ? parseIntWithMin(par1ICommandSender, par2ArrayOfStr[2], 0) : -1;
    032        int k = entityplayermp.inventory.clearInventory(i, j);
    033        entityplayermp.inventoryContainer.detectAndSendChanges();
    034
    035        if (k == 0)
    036        {
    037            throw new CommandException("commands.clear.failure", new Object[] {entityplayermp.getEntityName()});
    038        }
    039        else
    040        {
    041            notifyAdmins(par1ICommandSender, "commands.clear.success", new Object[] {entityplayermp.getEntityName(), Integer.valueOf(k)});
    042        }
    043    }
    044
    045    /**
    046     * Adds the strings available in this command to the given list of tab completion options.
    047     */
    048    public List addTabCompletionOptions(ICommandSender par1ICommandSender, String[] par2ArrayOfStr)
    049    {
    050        return par2ArrayOfStr.length == 1 ? getListOfStringsMatchingLastWord(par2ArrayOfStr, this.getAllOnlineUsernames()) : null;
    051    }
    052
    053    /**
    054     * Return all usernames currently connected to the server.
    055     */
    056    protected String[] getAllOnlineUsernames()
    057    {
    058        return MinecraftServer.getServer().getAllUsernames();
    059    }
    060
    061    /**
    062     * Return whether the specified command parameter index is a username parameter.
    063     */
    064    public boolean isUsernameIndex(String[] par1ArrayOfStr, int par2)
    065    {
    066        return par2 == 0;
    067    }
    068}