43 lines
2.4 KiB
Java
43 lines
2.4 KiB
Java
package carpet.commands;
|
|
|
|
import carpet.CarpetSettings;
|
|
import carpet.utils.DistanceCalculator;
|
|
import com.mojang.brigadier.CommandDispatcher;
|
|
import com.mojang.brigadier.builder.LiteralArgumentBuilder;
|
|
import net.minecraft.server.command.ServerCommandSource;
|
|
import net.minecraft.command.arguments.Vec3ArgumentType;
|
|
|
|
import static net.minecraft.server.command.CommandManager.argument;
|
|
import static net.minecraft.server.command.CommandManager.literal;
|
|
|
|
public class DistanceCommand
|
|
{
|
|
public static void register(CommandDispatcher<ServerCommandSource> dispatcher)
|
|
{
|
|
LiteralArgumentBuilder<ServerCommandSource> command = literal("distance").
|
|
requires((player) -> CarpetSettings.getBool("commandDistance")).
|
|
then(literal("from").
|
|
executes( (c) -> DistanceCalculator.setStart(c.getSource(), c.getSource().getPosition())).
|
|
then(argument("from", Vec3ArgumentType.create()).
|
|
executes( (c) -> DistanceCalculator.setStart(
|
|
c.getSource(),
|
|
Vec3ArgumentType.getVec3(c, "from"))).
|
|
then(literal("to").
|
|
executes((c) -> DistanceCalculator.distance(
|
|
c.getSource(),
|
|
Vec3ArgumentType.getVec3(c, "from"),
|
|
c.getSource().getPosition())).
|
|
then(argument("to", Vec3ArgumentType.create()).
|
|
executes( (c) -> DistanceCalculator.distance(
|
|
c.getSource(),
|
|
Vec3ArgumentType.getVec3(c, "from"),
|
|
Vec3ArgumentType.getVec3(c, "to")
|
|
)))))).
|
|
then(literal("to").
|
|
executes( (c) -> DistanceCalculator.setEnd(c.getSource(), c.getSource().getPosition()) ).
|
|
then(argument("to", Vec3ArgumentType.create()).
|
|
executes( (c) -> DistanceCalculator.setEnd(c.getSource(), Vec3ArgumentType.getVec3(c, "to")))));
|
|
dispatcher.register(command);
|
|
}
|
|
}
|