    001    package net.minecraft.src;
    002
    003    import java.util.List;
    004    import net.minecraft.server.MinecraftServer;
    005
    006    public class CommandEnchant extends CommandBase
    007    {
    008        public String getCommandName()
    009        {
    010            return "enchant";
    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.enchant.usage", new Object[0]);
    024        }
    025
    026        public void processCommand(ICommandSender par1ICommandSender, String[] par2ArrayOfStr)
    027        {
    028            if (par2ArrayOfStr.length < 2)
    029            {
    030                throw new WrongUsageException("commands.enchant.usage", new Object[0]);
    031            }
    032            else
    033            {
    034                EntityPlayerMP var3 = func_82359_c(par1ICommandSender, par2ArrayOfStr[0]);
    035                int var4 = parseIntBounded(par1ICommandSender, par2ArrayOfStr[1], 1, Enchantment.enchantmentsList.length - 1);
    036                int var5 = 1;
    037                ItemStack var6 = var3.getCurrentEquippedItem();
    038
    039                if (var6 == null)
    040                {
    041                    notifyAdmins(par1ICommandSender, "commands.enchant.noItem", new Object[0]);
    042                }
    043                else
    044                {
    045                    Enchantment var7 = Enchantment.enchantmentsList[var4];
    046
    047                    if (var7 == null)
    048                    {
    049                        throw new NumberInvalidException("commands.enchant.notFound", new Object[] {Integer.valueOf(var4)});
    050                    }
    051                    else if (!var7.type.canEnchantItem(var6.getItem()))
    052                    {
    053                        notifyAdmins(par1ICommandSender, "commands.enchant.cantEnchant", new Object[0]);
    054                    }
    055                    else
    056                    {
    057                        if (par2ArrayOfStr.length >= 3)
    058                        {
    059                            var5 = parseIntBounded(par1ICommandSender, par2ArrayOfStr[2], var7.getMinLevel(), var7.getMaxLevel());
    060                        }
    061
    062                        if (var6.hasTagCompound())
    063                        {
    064                            NBTTagList var8 = var6.getEnchantmentTagList();
    065
    066                            if (var8 != null)
    067                            {
    068                                for (int var9 = 0; var9 < var8.tagCount(); ++var9)
    069                                {
    070                                    short var10 = ((NBTTagCompound)var8.tagAt(var9)).getShort("id");
    071
    072                                    if (Enchantment.enchantmentsList[var10] != null)
    073                                    {
    074                                        Enchantment var11 = Enchantment.enchantmentsList[var10];
    075
    076                                        if (!var11.canApplyTogether(var7))
    077                                        {
    078                                            notifyAdmins(par1ICommandSender, "commands.enchant.cantCombine", new Object[] {var7.getTranslatedName(var5), var11.getTranslatedName(((NBTTagCompound)var8.tagAt(var9)).getShort("lvl"))});
    079                                            return;
    080                                        }
    081                                    }
    082                                }
    083                            }
    084                        }
    085
    086                        var6.addEnchantment(var7, var5);
    087                        notifyAdmins(par1ICommandSender, "commands.enchant.success", new Object[0]);
    088                    }
    089                }
    090            }
    091        }
    092
    093        /**
    094         * Adds the strings available in this command to the given list of tab completion options.
    095         */
    096        public List addTabCompletionOptions(ICommandSender par1ICommandSender, String[] par2ArrayOfStr)
    097        {
    098            return par2ArrayOfStr.length == 1 ? getListOfStringsMatchingLastWord(par2ArrayOfStr, this.func_90022_d()) : null;
    099        }
    100
    101        protected String[] func_90022_d()
    102        {
    103            return MinecraftServer.getServer().getAllUsernames();
    104        }
    105
    106        /**
    107         * Return whether the specified command parameter index is a username parameter.
    108         */
    109        public boolean isUsernameIndex(int par1)
    110        {
    111            return par1 == 0;
    112        }
    113    }