]> git.lizzy.rs Git - BoundingBoxOutlineReloaded.git/blob - src/main/java/com/irtimaled/bbor/client/commands/BeaconCommandBuilder.java
Simplify commands to use Coords & Pos objects
[BoundingBoxOutlineReloaded.git] / src / main / java / com / irtimaled / bbor / client / commands / BeaconCommandBuilder.java
1 package com.irtimaled.bbor.client.commands;
2
3 import com.irtimaled.bbor.client.providers.CustomBeaconProvider;
4 import com.irtimaled.bbor.common.models.Coords;
5 import com.mojang.brigadier.builder.LiteralArgumentBuilder;
6 import com.mojang.brigadier.context.CommandContext;
7 import com.mojang.brigadier.exceptions.CommandSyntaxException;
8 import net.minecraft.command.CommandSource;
9 import net.minecraft.command.Commands;
10
11 class BeaconCommandBuilder {
12     private static final String LEVEL = "level";
13
14     static LiteralArgumentBuilder<CommandSource> build(String command) {
15         return Commands.literal(command)
16                 .then(Commands.literal(ArgumentNames.ADD)
17                         .then(Commands.argument(LEVEL, Arguments.integer(1,4))
18                                 .executes(BeaconCommandBuilder::addBeacon)
19                                 .then(Commands.argument(ArgumentNames.POS, Arguments.coords())
20                                         .executes(BeaconCommandBuilder::addBeacon)))
21                 )
22                 .then(Commands.literal(ArgumentNames.CLEAR)
23                         .executes(context -> {
24                             CustomBeaconProvider.clear();
25
26                             CommandHelper.feedback(context, "bbor.commands.beacon.cleared.all");
27                             return 0;
28                         })
29                         .then(Commands.argument(ArgumentNames.POS, Arguments.coords())
30                                 .executes(context -> {
31                                     Coords coords = Arguments.getCoords(context, ArgumentNames.POS);
32                                     boolean removed = CustomBeaconProvider.remove(coords);
33
34                                     String format = removed ? "bbor.commands.beacon.cleared" : "bbor.commands.beacon.notFound";
35                                     CommandHelper.feedback(context, format, coords.getX(), coords.getY(), coords.getZ());
36                                     return 0;
37                                 })));
38     }
39
40     private static int addBeacon(CommandContext<CommandSource> context) throws CommandSyntaxException {
41         Coords coords = Arguments.getCoords(context, ArgumentNames.POS);
42         int level = Arguments.getInteger(context, LEVEL);
43
44         CustomBeaconProvider.add(coords, level);
45         CommandHelper.feedback(context, "bbor.commands.beacon.added", coords.getX(), coords.getY(), coords.getZ(), level);
46         return 0;
47     }
48 }