1 package com.irtimaled.bbor.client.commands;
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;
11 class BeaconCommandBuilder {
12 private static final String LEVEL = "level";
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)))
22 .then(Commands.literal(ArgumentNames.CLEAR)
23 .executes(context -> {
24 CustomBeaconProvider.clear();
26 CommandHelper.feedback(context, "bbor.commands.beacon.cleared.all");
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);
34 String format = removed ? "bbor.commands.beacon.cleared" : "bbor.commands.beacon.notFound";
35 CommandHelper.feedback(context, format, coords.getX(), coords.getY(), coords.getZ());
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);
44 CustomBeaconProvider.add(coords, level);
45 CommandHelper.feedback(context, "bbor.commands.beacon.added", coords.getX(), coords.getY(), coords.getZ(), level);