use of org.spongepowered.api.world.Locatable in project SpongeCommon by SpongePowered.
the class MixinCommandSenderWrapper method onInit.
@Inject(method = "<init>", at = @At("RETURN"))
private void onInit(ICommandSender delegateIn, Vec3d positionVectorIn, BlockPos positionIn, Integer permissionLevelIn, Entity entityIn, Boolean sendCommandFeedbackIn, CallbackInfo ci) {
CommandSource wrappedDelegate = WrapperCommandSource.of(this.delegate);
Subject subjectDelegate;
if (this.permissionLevel == null) {
subjectDelegate = wrappedDelegate;
} else {
subjectDelegate = new AndPermissionLevelSubject(this, wrappedDelegate);
}
if (this.positionVector != null || wrappedDelegate instanceof Locatable) {
this.sponge = new SpongeProxySource.Located(this, wrappedDelegate, subjectDelegate);
} else {
this.sponge = new SpongeProxySource(this, wrappedDelegate, subjectDelegate);
}
}
use of org.spongepowered.api.world.Locatable in project LanternServer by LanternPowered.
the class CommandSetSpawn method completeSpec.
@Override
public void completeSpec(PluginContainer pluginContainer, CommandSpec.Builder specBuilder) {
specBuilder.arguments(GenericArguments.flags().valueFlag(GenericArguments.world(CommandHelper.WORLD_KEY), "-world", "w").buildWith(GenericArguments.none()), GenericArguments.optional(GenericArguments2.targetedVector3d(Text.of("coordinates")))).executor((src, args) -> {
WorldProperties world = CommandHelper.getWorldProperties(src, args);
Vector3d position;
if (args.hasAny("coordinates")) {
position = args.<Vector3d>getOne("coordinates").get();
} else if (src instanceof Locatable) {
position = ((Locatable) src).getLocation().getPosition();
} else {
throw new CommandException(t("Non-located sources must specify coordinates."));
}
Vector3i position0 = position.toInt();
world.setSpawnPosition(position0);
src.sendMessage(t("commands.setworldspawn.success", position0.getX(), position0.getY(), position0.getZ()));
return CommandResult.success();
});
}
use of org.spongepowered.api.world.Locatable 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.spongepowered.api.world.Locatable in project LanternServer by LanternPowered.
the class LanternContextCalculator method accumulateContexts.
@Override
public void accumulateContexts(Subject subject, Set<Context> accumulator) {
final Optional<CommandSource> subjSource = subject.getCommandSource();
if (subjSource.isPresent()) {
final CommandSource source = subjSource.get();
if (source instanceof Locatable) {
final World currentExt = ((Locatable) source).getWorld();
accumulator.add(currentExt.getContext());
accumulator.add((currentExt.getDimension().getContext()));
}
if (source instanceof RemoteSource) {
final RemoteSource rem = (RemoteSource) source;
accumulator.addAll(this.remoteIpCache.get(rem));
accumulator.addAll(this.localIpCache.get(rem));
accumulator.add(new Context(Context.LOCAL_PORT_KEY, String.valueOf(rem.getConnection().getVirtualHost().getPort())));
accumulator.add(new Context(Context.LOCAL_HOST_KEY, rem.getConnection().getVirtualHost().getHostName()));
}
}
}
use of org.spongepowered.api.world.Locatable in project Nucleus by NucleusPowered.
the class SetSpawnWorldCommand method executeCommand.
@Override
protected CommandResult executeCommand(CommandSource src, CommandContext args) throws Exception {
WorldProperties world = this.getWorldFromUserOrArgs(src, this.worldKey, args);
Vector3i loc;
if (args.hasAny(this.xKey)) {
loc = new Vector3i(args.<Integer>getOne(this.xKey).get(), args.<Integer>getOne(this.yKey).get(), args.<Integer>getOne(this.zKey).get());
} else {
loc = ((Locatable) src).getLocation().getBlockPosition();
}
world.setSpawnPosition(loc);
src.sendMessage(plugin.getMessageProvider().getTextMessageWithFormat("command.world.setspawn.success"));
return CommandResult.success();
}
Aggregations