    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        public String getCommandUsage(ICommandSender par1ICommandSender)
    014        {
    015            return par1ICommandSender.translateString("commands.give.usage", new Object[0]);
    016        }
    017
    018        public void processCommand(ICommandSender par1ICommandSender, String[] par2ArrayOfStr)
    019        {
    020            if (par2ArrayOfStr.length >= 2)
    021            {
    022                EntityPlayer var3 = this.getTargetPlayer(par2ArrayOfStr[0]);
    023                int var4 = parseIntWithMin(par1ICommandSender, par2ArrayOfStr[1], 1);
    024                int var5 = 1;
    025                int var6 = 0;
    026
    027                if (Item.itemsList[var4] == null)
    028                {
    029                    throw new NumberInvalidException("commands.give.notFound", new Object[] {Integer.valueOf(var4)});
    030                }
    031                else
    032                {
    033                    if (par2ArrayOfStr.length >= 3)
    034                    {
    035                        var5 = parseIntBounded(par1ICommandSender, par2ArrayOfStr[2], 1, 64);
    036                    }
    037
    038                    if (par2ArrayOfStr.length >= 4)
    039                    {
    040                        var6 = parseInt(par1ICommandSender, par2ArrayOfStr[3]);
    041                    }
    042
    043                    ItemStack var7 = new ItemStack(var4, var5, var6);
    044                    var3.dropPlayerItem(var7);
    045                    notifyAdmins(par1ICommandSender, "commands.give.success", new Object[] {Item.itemsList[var4].func_77653_i(var7), Integer.valueOf(var4), Integer.valueOf(var5), var3.getEntityName()});
    046                }
    047            }
    048            else
    049            {
    050                throw new WrongUsageException("commands.give.usage", new Object[0]);
    051            }
    052        }
    053
    054        /**
    055         * Adds the strings available in this command to the given list of tab completion options.
    056         */
    057        public List addTabCompletionOptions(ICommandSender par1ICommandSender, String[] par2ArrayOfStr)
    058        {
    059            return par2ArrayOfStr.length == 1 ? getListOfStringsMatchingLastWord(par2ArrayOfStr, this.getPlayers()) : null;
    060        }
    061
    062        protected EntityPlayer getTargetPlayer(String par1Str)
    063        {
    064            EntityPlayerMP var2 = MinecraftServer.getServer().getConfigurationManager().getPlayerForUsername(par1Str);
    065
    066            if (var2 == null)
    067            {
    068                throw new PlayerNotFoundException();
    069            }
    070            else
    071            {
    072                return var2;
    073            }
    074        }
    075
    076        protected String[] getPlayers()
    077        {
    078            return MinecraftServer.getServer().getAllUsernames();
    079        }
    080    }