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