    001package net.minecraft.command;
    002
    003import java.util.List;
    004import net.minecraft.entity.item.EntityItem;
    005import net.minecraft.entity.player.EntityPlayerMP;
    006import net.minecraft.item.Item;
    007import net.minecraft.item.ItemStack;
    008import net.minecraft.server.MinecraftServer;
    009
    010public class CommandGive extends CommandBase
    011{
    012    public String getCommandName()
    013    {
    014        return "give";
    015    }
    016
    017    /**
    018     * Return the required permission level for this command.
    019     */
    020    public int getRequiredPermissionLevel()
    021    {
    022        return 2;
    023    }
    024
    025    public String getCommandUsage(ICommandSender par1ICommandSender)
    026    {
    027        return par1ICommandSender.translateString("commands.give.usage", new Object[0]);
    028    }
    029
    030    public void processCommand(ICommandSender par1ICommandSender, String[] par2ArrayOfStr)
    031    {
    032        if (par2ArrayOfStr.length >= 2)
    033        {
    034            EntityPlayerMP entityplayermp = func_82359_c(par1ICommandSender, par2ArrayOfStr[0]);
    035            int i = parseIntWithMin(par1ICommandSender, par2ArrayOfStr[1], 1);
    036            int j = 1;
    037            int k = 0;
    038
    039            if (Item.itemsList[i] == null)
    040            {
    041                throw new NumberInvalidException("commands.give.notFound", new Object[] {Integer.valueOf(i)});
    042            }
    043            else
    044            {
    045                if (par2ArrayOfStr.length >= 3)
    046                {
    047                    j = parseIntBounded(par1ICommandSender, par2ArrayOfStr[2], 1, 64);
    048                }
    049
    050                if (par2ArrayOfStr.length >= 4)
    051                {
    052                    k = parseInt(par1ICommandSender, par2ArrayOfStr[3]);
    053                }
    054
    055                ItemStack itemstack = new ItemStack(i, j, k);
    056                EntityItem entityitem = entityplayermp.dropPlayerItem(itemstack);
    057                entityitem.delayBeforeCanPickup = 0;
    058                notifyAdmins(par1ICommandSender, "commands.give.success", new Object[] {Item.itemsList[i].func_77653_i(itemstack), Integer.valueOf(i), Integer.valueOf(j), entityplayermp.getEntityName()});
    059            }
    060        }
    061        else
    062        {
    063            throw new WrongUsageException("commands.give.usage", new Object[0]);
    064        }
    065    }
    066
    067    /**
    068     * Adds the strings available in this command to the given list of tab completion options.
    069     */
    070    public List addTabCompletionOptions(ICommandSender par1ICommandSender, String[] par2ArrayOfStr)
    071    {
    072        return par2ArrayOfStr.length == 1 ? getListOfStringsMatchingLastWord(par2ArrayOfStr, this.getPlayers()) : null;
    073    }
    074
    075    protected String[] getPlayers()
    076    {
    077        return MinecraftServer.getServer().getAllUsernames();
    078    }
    079
    080    /**
    081     * Return whether the specified command parameter index is a username parameter.
    082     */
    083    public boolean isUsernameIndex(String[] par1ArrayOfStr, int par2)
    084    {
    085        return par2 == 0;
    086    }
    087}