    001    package net.minecraft.command;
    002
    003    import java.util.List;
    004    import net.minecraft.entity.item.EntityItem;
    005    import net.minecraft.entity.player.EntityPlayerMP;
    006    import net.minecraft.item.Item;
    007    import net.minecraft.item.ItemStack;
    008    import net.minecraft.server.MinecraftServer;
    009
    010    public 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 var3 = func_82359_c(par1ICommandSender, par2ArrayOfStr[0]);
    035                int var4 = parseIntWithMin(par1ICommandSender, par2ArrayOfStr[1], 1);
    036                int var5 = 1;
    037                int var6 = 0;
    038
    039                if (Item.itemsList[var4] == null)
    040                {
    041                    throw new NumberInvalidException("commands.give.notFound", new Object[] {Integer.valueOf(var4)});
    042                }
    043                else
    044                {
    045                    if (par2ArrayOfStr.length >= 3)
    046                    {
    047                        var5 = parseIntBounded(par1ICommandSender, par2ArrayOfStr[2], 1, 64);
    048                    }
    049
    050                    if (par2ArrayOfStr.length >= 4)
    051                    {
    052                        var6 = parseInt(par1ICommandSender, par2ArrayOfStr[3]);
    053                    }
    054
    055                    ItemStack var7 = new ItemStack(var4, var5, var6);
    056                    EntityItem var8 = var3.dropPlayerItem(var7);
    057                    var8.delayBeforeCanPickup = 0;
    058                    notifyAdmins(par1ICommandSender, "commands.give.success", new Object[] {Item.itemsList[var4].func_77653_i(var7), Integer.valueOf(var4), Integer.valueOf(var5), var3.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(int par1)
    084        {
    085            return par1 == 0;
    086        }
    087    }