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