    001package net.minecraft.command;
    002
    003import java.util.List;
    004import net.minecraft.entity.player.EntityPlayerMP;
    005import net.minecraft.server.MinecraftServer;
    006
    007public 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 s = par2ArrayOfStr[0];
    036            boolean flag = s.endsWith("l") || s.endsWith("L");
    037
    038            if (flag && s.length() > 1)
    039            {
    040                s = s.substring(0, s.length() - 1);
    041            }
    042
    043            int i = parseInt(par1ICommandSender, s);
    044            boolean flag1 = i < 0;
    045
    046            if (flag1)
    047            {
    048                i *= -1;
    049            }
    050
    051            EntityPlayerMP entityplayermp;
    052
    053            if (par2ArrayOfStr.length > 1)
    054            {
    055                entityplayermp = func_82359_c(par1ICommandSender, par2ArrayOfStr[1]);
    056            }
    057            else
    058            {
    059                entityplayermp = getCommandSenderAsPlayer(par1ICommandSender);
    060            }
    061
    062            if (flag)
    063            {
    064                if (flag1)
    065                {
    066                    entityplayermp.addExperienceLevel(-i);
    067                    notifyAdmins(par1ICommandSender, "commands.xp.success.negative.levels", new Object[] {Integer.valueOf(i), entityplayermp.getEntityName()});
    068                }
    069                else
    070                {
    071                    entityplayermp.addExperienceLevel(i);
    072                    notifyAdmins(par1ICommandSender, "commands.xp.success.levels", new Object[] {Integer.valueOf(i), entityplayermp.getEntityName()});
    073                }
    074            }
    075            else
    076            {
    077                if (flag1)
    078                {
    079                    throw new WrongUsageException("commands.xp.failure.widthdrawXp", new Object[0]);
    080                }
    081
    082                entityplayermp.addExperience(i);
    083                notifyAdmins(par1ICommandSender, "commands.xp.success", new Object[] {Integer.valueOf(i), entityplayermp.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(String[] par1ArrayOfStr, int par2)
    105    {
    106        return par2 == 1;
    107    }
    108}