| 1 | package net.minecraft.command;
|
| 2 |
|
| 3 | import com.google.common.collect.Lists;
|
| 4 | import java.util.List;
|
| 5 | import net.minecraft.entity.Entity;
|
| 6 | import net.minecraft.entity.player.EntityPlayerMP;
|
| 7 | import net.minecraft.scoreboard.IScoreObjectiveCriteria;
|
| 8 | import net.minecraft.scoreboard.Score;
|
| 9 | import net.minecraft.scoreboard.ScoreObjective;
|
| 10 | import net.minecraft.scoreboard.Scoreboard;
|
| 11 | import net.minecraft.server.MinecraftServer;
|
| 12 | import net.minecraft.util.BlockPos;
|
| 13 |
|
| 14 | public class CommandTrigger extends CommandBase
|
| 15 | {
|
| 16 | /**
|
| 17 | * Gets the name of the command
|
| 18 | */
|
| 19 | public String getCommandName()
|
| 20 | {
|
| 21 | return "trigger";
|
| 22 | }
|
| 23 |
|
| 24 | /**
|
| 25 | * Return the required permission level for this command.
|
| 26 | */
|
| 27 | public int getRequiredPermissionLevel()
|
| 28 | {
|
| 29 | return 0;
|
| 30 | }
|
| 31 |
|
| 32 | /**
|
| 33 | * Gets the usage string for the command.
|
| 34 | */
|
| 35 | public String getCommandUsage(ICommandSender sender)
|
| 36 | {
|
| 37 | return "commands.trigger.usage";
|
| 38 | }
|
| 39 |
|
| 40 | /**
|
| 41 | * Callback when the command is invoked
|
| 42 | */
|
| 43 | public void processCommand(ICommandSender sender, String[] args) throws CommandException
|
| 44 | {
|
| 45 | if (args.length < 3)
|
| 46 | {
|
| 47 | throw new WrongUsageException("commands.trigger.usage", new Object[0]);
|
| 48 | }
|
| 49 | else
|
| 50 | {
|
| 51 | EntityPlayerMP entityplayermp;
|
| 52 |
|
| 53 | if (sender instanceof EntityPlayerMP)
|
| 54 | {
|
| 55 | entityplayermp = (EntityPlayerMP)sender;
|
| 56 | }
|
| 57 | else
|
| 58 | {
|
| 59 | Entity entity = sender.getCommandSenderEntity();
|
| 60 |
|
| 61 | if (!(entity instanceof EntityPlayerMP))
|
| 62 | {
|
| 63 | throw new CommandException("commands.trigger.invalidPlayer", new Object[0]);
|
| 64 | }
|
| 65 |
|
| 66 | entityplayermp = (EntityPlayerMP)entity;
|
| 67 | }
|
| 68 |
|
| 69 | Scoreboard scoreboard = MinecraftServer.getServer().worldServerForDimension(0).getScoreboard();
|
| 70 | ScoreObjective scoreobjective = scoreboard.getObjective(args[0]);
|
| 71 |
|
| 72 | if (scoreobjective != null && scoreobjective.getCriteria() == IScoreObjectiveCriteria.TRIGGER)
|
| 73 | {
|
| 74 | int i = parseInt(args[2]);
|
| 75 |
|
| 76 | if (!scoreboard.entityHasObjective(entityplayermp.getName(), scoreobjective))
|
| 77 | {
|
| 78 | throw new CommandException("commands.trigger.invalidObjective", new Object[] {args[0]});
|
| 79 | }
|
| 80 | else
|
| 81 | {
|
| 82 | Score score = scoreboard.getValueFromObjective(entityplayermp.getName(), scoreobjective);
|
| 83 |
|
| 84 | if (score.isLocked())
|
| 85 | {
|
| 86 | throw new CommandException("commands.trigger.disabled", new Object[] {args[0]});
|
| 87 | }
|
| 88 | else
|
| 89 | {
|
| 90 | if ("set".equals(args[1]))
|
| 91 | {
|
| 92 | score.setScorePoints(i);
|
| 93 | }
|
| 94 | else
|
| 95 | {
|
| 96 | if (!"add".equals(args[1]))
|
| 97 | {
|
| 98 | throw new CommandException("commands.trigger.invalidMode", new Object[] {args[1]});
|
| 99 | }
|
| 100 |
|
| 101 | score.increseScore(i);
|
| 102 | }
|
| 103 |
|
| 104 | score.setLocked(true);
|
| 105 |
|
| 106 | if (entityplayermp.theItemInWorldManager.isCreative())
|
| 107 | {
|
| 108 | notifyOperators(sender, this, "commands.trigger.success", new Object[] {args[0], args[1], args[2]});
|
| 109 | }
|
| 110 | }
|
| 111 | }
|
| 112 | }
|
| 113 | else
|
| 114 | {
|
| 115 | throw new CommandException("commands.trigger.invalidObjective", new Object[] {args[0]});
|
| 116 | }
|
| 117 | }
|
| 118 | }
|
| 119 |
|
| 120 | public List<String> addTabCompletionOptions(ICommandSender sender, String[] args, BlockPos pos)
|
| 121 | {
|
| 122 | if (args.length == 1)
|
| 123 | {
|
| 124 | Scoreboard scoreboard = MinecraftServer.getServer().worldServerForDimension(0).getScoreboard();
|
| 125 | List<String> list = Lists.<String>newArrayList();
|
| 126 |
|
| 127 | for (ScoreObjective scoreobjective : scoreboard.getScoreObjectives())
|
| 128 | {
|
| 129 | if (scoreobjective.getCriteria() == IScoreObjectiveCriteria.TRIGGER)
|
| 130 | {
|
| 131 | list.add(scoreobjective.getName());
|
| 132 | }
|
| 133 | }
|
| 134 |
|
| 135 | return getListOfStringsMatchingLastWord(args, (String[])list.toArray(new String[list.size()]));
|
| 136 | }
|
| 137 | else
|
| 138 | {
|
| 139 | return args.length == 2 ? getListOfStringsMatchingLastWord(args, new String[] {"add", "set"}): null;
|
| 140 | }
|
| 141 | }
|
| 142 | }
|
| 143 |
|