    001    package net.minecraft.src;
    002
    003    import java.util.List;
    004    import net.minecraft.server.MinecraftServer;
    005
    006    public class CommandXP extends CommandBase
    007    {
    008        public String getCommandName()
    009        {
    010            return "xp";
    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.xp.usage", new Object[0]);
    024        }
    025
    026        public void processCommand(ICommandSender par1ICommandSender, String[] par2ArrayOfStr)
    027        {
    028            if (par2ArrayOfStr.length <= 0)
    029            {
    030                throw new WrongUsageException("commands.xp.usage", new Object[0]);
    031            }
    032            else
    033            {
    034                String var4 = par2ArrayOfStr[0];
    035                boolean var5 = var4.endsWith("l") || var4.endsWith("L");
    036
    037                if (var5 && var4.length() > 1)
    038                {
    039                    var4 = var4.substring(0, var4.length() - 1);
    040                }
    041
    042                int var6 = parseInt(par1ICommandSender, var4);
    043                boolean var7 = var6 < 0;
    044
    045                if (var7)
    046                {
    047                    var6 *= -1;
    048                }
    049
    050                EntityPlayerMP var3;
    051
    052                if (par2ArrayOfStr.length > 1)
    053                {
    054                    var3 = func_82359_c(par1ICommandSender, par2ArrayOfStr[1]);
    055                }
    056                else
    057                {
    058                    var3 = getCommandSenderAsPlayer(par1ICommandSender);
    059                }
    060
    061                if (var5)
    062                {
    063                    if (var7)
    064                    {
    065                        var3.addExperienceLevel(-var6);
    066                        notifyAdmins(par1ICommandSender, "commands.xp.success.negative.levels", new Object[] {Integer.valueOf(var6), var3.getEntityName()});
    067                    }
    068                    else
    069                    {
    070                        var3.addExperienceLevel(var6);
    071                        notifyAdmins(par1ICommandSender, "commands.xp.success.levels", new Object[] {Integer.valueOf(var6), var3.getEntityName()});
    072                    }
    073                }
    074                else
    075                {
    076                    if (var7)
    077                    {
    078                        throw new WrongUsageException("commands.xp.failure.widthdrawXp", new Object[0]);
    079                    }
    080
    081                    var3.addExperience(var6);
    082                    notifyAdmins(par1ICommandSender, "commands.xp.success", new Object[] {Integer.valueOf(var6), var3.getEntityName()});
    083                }
    084            }
    085        }
    086
    087        /**
    088         * Adds the strings available in this command to the given list of tab completion options.
    089         */
    090        public List addTabCompletionOptions(ICommandSender par1ICommandSender, String[] par2ArrayOfStr)
    091        {
    092            return par2ArrayOfStr.length == 2 ? getListOfStringsMatchingLastWord(par2ArrayOfStr, this.getAllUsernames()) : null;
    093        }
    094
    095        protected String[] getAllUsernames()
    096        {
    097            return MinecraftServer.getServer().getAllUsernames();
    098        }
    099
    100        /**
    101         * Return whether the specified command parameter index is a username parameter.
    102         */
    103        public boolean isUsernameIndex(int par1)
    104        {
    105            return par1 == 1;
    106        }
    107    }