use of org.lanternpowered.server.command.element.RelativeDouble in project LanternServer by LanternPowered.
the class CommandTeleport method completeSpec.
@Override
public void completeSpec(PluginContainer pluginContainer, CommandSpec.Builder specBuilder) {
specBuilder.arguments(// TODO: Replace with entity selector
GenericArguments.player(Text.of("target")), GenericArguments.flags().valueFlag(GenericArguments.world(CommandHelper.WORLD_KEY), "-world", "w").buildWith(GenericArguments.none()), GenericArguments.vector3d(Text.of("position")), GenericArguments.optional(GenericArguments.seq(GenericArguments2.relativeDoubleNum(Text.of("y-rot")), GenericArguments2.relativeDoubleNum(Text.of("x-rot"))))).executor((src, args) -> {
// TODO: Replace with selected entities
final Entity target = args.<Entity>getOne("target").get();
final World world = CommandHelper.getWorld(src, args);
final Location<World> location = new Location<>(world, args.<Vector3d>getOne("position").get());
if (args.hasAny("y-rot")) {
RelativeDouble yRot = args.<RelativeDouble>getOne("y-rot").get();
RelativeDouble xRot = args.<RelativeDouble>getOne("x-rot").get();
boolean rel = yRot.isRelative() || xRot.isRelative();
if (rel && !(src instanceof Locatable)) {
throw new CommandException(t("Relative rotation specified but source does not have a rotation."));
}
double xRot0 = xRot.getValue();
double yRot0 = yRot.getValue();
double zRot0 = 0;
// is locatable, just handle it then as absolute
if (src instanceof Entity) {
final Vector3d rot = ((Entity) src).getRotation();
xRot0 = xRot.applyToValue(rot.getX());
yRot0 = yRot.applyToValue(rot.getY());
zRot0 = rot.getZ();
}
target.setLocationAndRotation(location, new Vector3d(xRot0, yRot0, zRot0));
} else {
target.setLocation(location);
}
src.sendMessage(t("commands.teleport.success.coordinates", location.getX(), location.getY(), location.getZ()));
return CommandResult.success();
});
}
use of org.lanternpowered.server.command.element.RelativeDouble in project LanternServer by LanternPowered.
the class CommandTp method completeSpec.
@Override
public void completeSpec(PluginContainer pluginContainer, CommandSpec.Builder specBuilder) {
specBuilder.arguments(GenericArguments.optional(GenericArguments.player(Text.of("target"))), GenericArguments.firstParsing(GenericArguments.player(Text.of("destination")), GenericArguments.seq(/*
GenericArguments.flags()
.valueFlag(GenericArguments.world(CommandHelper.WORLD_KEY),
"-world", "w")
.buildWith(GenericArguments.none()),
*/
GenericArguments.optional(GenericArguments.world(CommandHelper.WORLD_KEY)), GenericArguments2.targetedRelativeVector3d(Text.of("coordinates")), GenericArguments.optional(GenericArguments.seq(GenericArguments2.relativeDoubleNum(Text.of("y-rot")), GenericArguments2.relativeDoubleNum(Text.of("x-rot"))))))).executor((src, args) -> {
Player target = args.<Player>getOne("target").orElse(null);
if (target == null) {
if (!(src instanceof Player)) {
throw new CommandException(t("The target parameter is only optional for players."));
}
target = (Player) src;
}
final Optional<Player> optDestination = args.getOne("destination");
if (optDestination.isPresent()) {
final Player destination = optDestination.get();
target.setTransform(destination.getTransform());
src.sendMessage(t("commands.tp.success", target.getName(), destination.getName()));
} else {
final RelativeVector3d coords = args.<RelativeVector3d>getOne("coordinates").get();
final Transform<World> transform = target.getTransform();
World world = args.<WorldProperties>getOne(CommandHelper.WORLD_KEY).flatMap(p -> Lantern.getServer().getWorld(p.getUniqueId())).orElse(transform.getExtent());
Vector3d position = coords.applyToValue(transform.getPosition());
final Optional<RelativeDouble> optYRot = args.getOne("y-rot");
if (optYRot.isPresent()) {
final Vector3d rot = transform.getRotation();
double xRot = args.<RelativeDouble>getOne("x-rot").get().applyToValue(rot.getX());
double yRot = args.<RelativeDouble>getOne("y-rot").get().applyToValue(rot.getY());
double zRot = rot.getZ();
target.setLocationAndRotation(new Location<>(world, position), new Vector3d(xRot, yRot, zRot));
} else {
target.setLocation(new Location<>(world, position));
}
src.sendMessage(t("commands.tp.success.position", target.getName(), formatDouble(position.getX()), formatDouble(position.getY()), formatDouble(position.getZ()), world.getName()));
}
return CommandResult.success();
});
}
Aggregations