Search in sources :

Example 1 with Locatable

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);
    }
}
Also used : SpongeProxySource(org.spongepowered.common.command.SpongeProxySource) WrapperCommandSource(org.spongepowered.common.command.WrapperCommandSource) CommandSource(org.spongepowered.api.command.CommandSource) AndPermissionLevelSubject(org.spongepowered.common.command.AndPermissionLevelSubject) AndPermissionLevelSubject(org.spongepowered.common.command.AndPermissionLevelSubject) Subject(org.spongepowered.api.service.permission.Subject) Locatable(org.spongepowered.api.world.Locatable) Inject(org.spongepowered.asm.mixin.injection.Inject)

Example 2 with Locatable

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();
    });
}
Also used : Vector3d(com.flowpowered.math.vector.Vector3d) Vector3i(com.flowpowered.math.vector.Vector3i) CommandException(org.spongepowered.api.command.CommandException) WorldProperties(org.spongepowered.api.world.storage.WorldProperties) Locatable(org.spongepowered.api.world.Locatable)

Example 3 with Locatable

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();
    });
}
Also used : Entity(org.spongepowered.api.entity.Entity) Vector3d(com.flowpowered.math.vector.Vector3d) RelativeDouble(org.lanternpowered.server.command.element.RelativeDouble) CommandException(org.spongepowered.api.command.CommandException) World(org.spongepowered.api.world.World) Location(org.spongepowered.api.world.Location) Locatable(org.spongepowered.api.world.Locatable)

Example 4 with Locatable

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()));
        }
    }
}
Also used : Context(org.spongepowered.api.service.context.Context) RemoteSource(org.spongepowered.api.command.source.RemoteSource) CommandSource(org.spongepowered.api.command.CommandSource) World(org.spongepowered.api.world.World) Locatable(org.spongepowered.api.world.Locatable)

Example 5 with Locatable

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();
}
Also used : Vector3i(com.flowpowered.math.vector.Vector3i) WorldProperties(org.spongepowered.api.world.storage.WorldProperties) Locatable(org.spongepowered.api.world.Locatable)

Aggregations

Locatable (org.spongepowered.api.world.Locatable)9 World (org.spongepowered.api.world.World)5 WorldProperties (org.spongepowered.api.world.storage.WorldProperties)5 Vector3d (com.flowpowered.math.vector.Vector3d)4 CommandSource (org.spongepowered.api.command.CommandSource)3 Vector3i (com.flowpowered.math.vector.Vector3i)2 CommandException (org.spongepowered.api.command.CommandException)2 RemoteSource (org.spongepowered.api.command.source.RemoteSource)2 Entity (org.spongepowered.api.entity.Entity)2 Context (org.spongepowered.api.service.context.Context)2 RelativeDouble (org.lanternpowered.server.command.element.RelativeDouble)1 LanternItemStack (org.lanternpowered.server.inventory.LanternItemStack)1 TranslationHelper.t (org.lanternpowered.server.text.translation.TranslationHelper.t)1 Sponge (org.spongepowered.api.Sponge)1 BlockState (org.spongepowered.api.block.BlockState)1 BlockTypes (org.spongepowered.api.block.BlockTypes)1 CommandResult (org.spongepowered.api.command.CommandResult)1 GenericArguments (org.spongepowered.api.command.args.GenericArguments)1 CommandSpec (org.spongepowered.api.command.spec.CommandSpec)1 NotePitch (org.spongepowered.api.data.type.NotePitch)1