|
10 | 10 | import net.minecraft.text.LiteralText;
|
11 | 11 | import net.minecraft.text.TranslatableText;
|
12 | 12 |
|
13 |
| -import static net.minecraft.server.command.CommandManager.*; |
| 13 | +import static net.minecraft.server.command.CommandManager.argument; |
| 14 | +import static net.minecraft.server.command.CommandManager.literal; |
14 | 15 |
|
15 | 16 | public class SpeedrunnerCommand {
|
16 | 17 | public static void register(CommandDispatcher<ServerCommandSource> dispatcher) {
|
17 | 18 | dispatcher.register(
|
18 | 19 | literal("speedrunner").then(
|
19 |
| - argument("target", EntityArgumentType.player()).executes(SpeedrunnerCommand::execute) |
| 20 | + literal("set").then( |
| 21 | + argument("target", EntityArgumentType.player()).executes(SpeedrunnerCommand::executeSet) |
| 22 | + ) |
20 | 23 | ).then(
|
21 | 24 | literal("get").executes(SpeedrunnerCommand::executeGet)
|
| 25 | + ).then( |
| 26 | + literal("clear").executes(SpeedrunnerCommand::executeClear) |
22 | 27 | )
|
23 | 28 | );
|
24 | 29 | }
|
25 | 30 |
|
26 |
| - private static int execute(CommandContext<ServerCommandSource> context) throws CommandSyntaxException { |
| 31 | + private static int executeSet(CommandContext<ServerCommandSource> context) throws CommandSyntaxException { |
27 | 32 | boolean playerHasMod = ManhuntUtils.playerHasMod(context);
|
28 | 33 | ServerPlayerEntity target = EntityArgumentType.getPlayer(context, "target");
|
29 | 34 |
|
30 | 35 | if (ManhuntUtils.hunters.contains(target.getUuid())) {
|
31 |
| - if (playerHasMod) |
| 36 | + if (playerHasMod) { |
32 | 37 | context.getSource().sendError(new TranslatableText("text.manhunt.command.speedrunner.error.hunter", target.getDisplayName()));
|
33 |
| - else |
34 |
| - context.getSource().sendError(new LiteralText("Cannot set speedrunner to ").append(target.getDisplayName()).append(new LiteralText(" because they are a hunter!"))); |
| 38 | + } else { |
| 39 | + context.getSource() |
| 40 | + .sendError(new LiteralText("Cannot set speedrunner to ").append(target.getDisplayName()) |
| 41 | + .append(new LiteralText(" because they are a hunter!"))); |
| 42 | + } |
35 | 43 | return 1;
|
36 | 44 | }
|
37 | 45 |
|
38 | 46 | ManhuntUtils.speedrunner = target.getUuid();
|
39 |
| - if (playerHasMod) |
40 |
| - context.getSource().sendFeedback(new TranslatableText("text.manhunt.command.speedrunner.set", ManhuntUtils.fromCmdContext(context, ManhuntUtils.speedrunner).getDisplayName()), true); |
41 |
| - else |
42 |
| - context.getSource().sendFeedback(new LiteralText("Set speedrunner to ").append(target.getDisplayName()).append(new LiteralText("!")), true); |
| 47 | + if (playerHasMod) { |
| 48 | + context.getSource() |
| 49 | + .sendFeedback(new TranslatableText("text.manhunt.command.speedrunner.set", |
| 50 | + ManhuntUtils.fromCmdContext(context, ManhuntUtils.speedrunner).getDisplayName() |
| 51 | + ), true); |
| 52 | + } else { |
| 53 | + context.getSource() |
| 54 | + .sendFeedback(new LiteralText("Set speedrunner to ").append(target.getDisplayName()).append(new LiteralText("!")), true); |
| 55 | + } |
43 | 56 | return 1;
|
44 | 57 | }
|
45 | 58 |
|
46 | 59 | private static int executeGet(CommandContext<ServerCommandSource> context) throws CommandSyntaxException {
|
47 | 60 | boolean playerHasMod = ManhuntUtils.playerHasMod(context);
|
48 | 61 | if (ManhuntUtils.speedrunner == null) return 1;
|
49 | 62 |
|
50 |
| - if (playerHasMod) |
51 |
| - context.getSource().sendFeedback(new TranslatableText("text.manhunt.command.speedrunner.get", ManhuntUtils.fromCmdContext(context, ManhuntUtils.speedrunner).getDisplayName()), false); |
52 |
| - else |
53 |
| - context.getSource().sendFeedback(new LiteralText("Speedrunner is currently: ").append(ManhuntUtils.fromCmdContext(context, ManhuntUtils.speedrunner).getDisplayName()), true); |
| 63 | + if (playerHasMod) { |
| 64 | + context.getSource() |
| 65 | + .sendFeedback(new TranslatableText("text.manhunt.command.speedrunner.get", |
| 66 | + ManhuntUtils.fromCmdContext(context, ManhuntUtils.speedrunner).getDisplayName() |
| 67 | + ), false); |
| 68 | + } else { |
| 69 | + context.getSource() |
| 70 | + .sendFeedback(new LiteralText("Speedrunner is currently: ").append(ManhuntUtils.fromCmdContext(context, ManhuntUtils.speedrunner) |
| 71 | + .getDisplayName()), true); |
| 72 | + } |
| 73 | + return 1; |
| 74 | + } |
| 75 | + |
| 76 | + private static int executeClear(CommandContext<ServerCommandSource> context) { |
| 77 | + ManhuntUtils.speedrunner = null; |
54 | 78 | return 1;
|
55 | 79 | }
|
56 | 80 | }
|
0 commit comments