| 1 | package net.minecraft.command;
|
| 2 |
|
| 3 | import java.util.List;
|
| 4 | import net.minecraft.entity.player.EntityPlayer;
|
| 5 | import net.minecraft.server.MinecraftServer;
|
| 6 | import net.minecraft.util.BlockPos;
|
| 7 |
|
| 8 | public class CommandXP extends CommandBase
|
| 9 | {
|
| 10 | /**
|
| 11 | * Gets the name of the command
|
| 12 | */
|
| 13 | public String getCommandName()
|
| 14 | {
|
| 15 | return "xp";
|
| 16 | }
|
| 17 |
|
| 18 | /**
|
| 19 | * Return the required permission level for this command.
|
| 20 | */
|
| 21 | public int getRequiredPermissionLevel()
|
| 22 | {
|
| 23 | return 2;
|
| 24 | }
|
| 25 |
|
| 26 | /**
|
| 27 | * Gets the usage string for the command.
|
| 28 | */
|
| 29 | public String getCommandUsage(ICommandSender sender)
|
| 30 | {
|
| 31 | return "commands.xp.usage";
|
| 32 | }
|
| 33 |
|
| 34 | /**
|
| 35 | * Callback when the command is invoked
|
| 36 | */
|
| 37 | public void processCommand(ICommandSender sender, String[] args) throws CommandException
|
| 38 | {
|
| 39 | if (args.length <= 0)
|
| 40 | {
|
| 41 | throw new WrongUsageException("commands.xp.usage", new Object[0]);
|
| 42 | }
|
| 43 | else
|
| 44 | {
|
| 45 | String s = args[0];
|
| 46 | boolean flag = s.endsWith("l") || s.endsWith("L");
|
| 47 |
|
| 48 | if (flag && s.length() > 1)
|
| 49 | {
|
| 50 | s = s.substring(0, s.length() - 1);
|
| 51 | }
|
| 52 |
|
| 53 | int i = parseInt(s);
|
| 54 | boolean flag1 = i < 0;
|
| 55 |
|
| 56 | if (flag1)
|
| 57 | {
|
| 58 | i *= -1;
|
| 59 | }
|
| 60 |
|
| 61 | EntityPlayer entityplayer = args.length > 1 ? getPlayer(sender, args[1]) : getCommandSenderAsPlayer(sender);
|
| 62 |
|
| 63 | if (flag)
|
| 64 | {
|
| 65 | sender.setCommandStat(CommandResultStats.Type.QUERY_RESULT, entityplayer.experienceLevel);
|
| 66 |
|
| 67 | if (flag1)
|
| 68 | {
|
| 69 | entityplayer.addExperienceLevel(-i);
|
| 70 | notifyOperators(sender, this, "commands.xp.success.negative.levels", new Object[] {Integer.valueOf(i), entityplayer.getName()});
|
| 71 | }
|
| 72 | else
|
| 73 | {
|
| 74 | entityplayer.addExperienceLevel(i);
|
| 75 | notifyOperators(sender, this, "commands.xp.success.levels", new Object[] {Integer.valueOf(i), entityplayer.getName()});
|
| 76 | }
|
| 77 | }
|
| 78 | else
|
| 79 | {
|
| 80 | sender.setCommandStat(CommandResultStats.Type.QUERY_RESULT, entityplayer.experienceTotal);
|
| 81 |
|
| 82 | if (flag1)
|
| 83 | {
|
| 84 | throw new CommandException("commands.xp.failure.widthdrawXp", new Object[0]);
|
| 85 | }
|
| 86 |
|
| 87 | entityplayer.addExperience(i);
|
| 88 | notifyOperators(sender, this, "commands.xp.success", new Object[] {Integer.valueOf(i), entityplayer.getName()});
|
| 89 | }
|
| 90 | }
|
| 91 | }
|
| 92 |
|
| 93 | public List<String> addTabCompletionOptions(ICommandSender sender, String[] args, BlockPos pos)
|
| 94 | {
|
| 95 | return args.length == 2 ? getListOfStringsMatchingLastWord(args, this.getAllUsernames()) : null;
|
| 96 | }
|
| 97 |
|
| 98 | protected String[] getAllUsernames()
|
| 99 | {
|
| 100 | return MinecraftServer.getServer().getAllUsernames();
|
| 101 | }
|
| 102 |
|
| 103 | /**
|
| 104 | * Return whether the specified command parameter index is a username parameter.
|
| 105 | */
|
| 106 | public boolean isUsernameIndex(String[] args, int index)
|
| 107 | {
|
| 108 | return index == 1;
|
| 109 | }
|
| 110 | }
|
| 111 |
|