Search in sources :

Example 86 with WorldProperties

use of org.spongepowered.api.world.storage.WorldProperties in project ProjectWorlds by trentech.

the class EventManager method onRespawnPlayerEvent2.

@Listener(order = Order.LAST)
public void onRespawnPlayerEvent2(RespawnPlayerEvent event) {
    Player player = event.getTargetEntity();
    if (player.hasPermission("pjw.override.gamemode")) {
        return;
    }
    World from = event.getFromTransform().getExtent();
    World to = event.getToTransform().getExtent();
    WorldProperties properties = to.getProperties();
    if (!from.equals(to)) {
        if (properties.getGameRule("forceGamemode").get().equalsIgnoreCase("true")) {
            if (!properties.getGameMode().equals(player.gameMode().get())) {
                player.offer(Keys.GAME_MODE, properties.getGameMode());
            }
        }
    }
}
Also used : Player(org.spongepowered.api.entity.living.player.Player) World(org.spongepowered.api.world.World) WorldProperties(org.spongepowered.api.world.storage.WorldProperties) Listener(org.spongepowered.api.event.Listener)

Example 87 with WorldProperties

use of org.spongepowered.api.world.storage.WorldProperties in project LanternServer by LanternPowered.

the class CommandParticleEffect method completeSpec.

@Override
public void completeSpec(PluginContainer pluginContainer, CommandSpec.Builder specBuilder) {
    specBuilder.arguments(GenericArguments.catalogedElement(Text.of("type"), ParticleType.class), GenericArguments.vector3d(Text.of("position")), GenericArguments.optional(GenericArguments.world(Text.of("world"))), // TODO: Tab complaining is currently throwing errors, but it's a small bug in SpongeAPI
    GenericArguments.flags().valueFlag(GenericArguments.integer(Text.of("quantity")), "-quantity", "q").valueFlag(GenericArguments.vector3d(Text.of("offset")), "-offset", "o").valueFlag(GenericArguments.vector3d(Text.of("velocity")), "-velocity", "v").valueFlag(GenericArguments.vector3d(Text.of("color")), "-color", "c").valueFlag(GenericArguments.doubleNum(Text.of("scale")), "-scale", "s").valueFlag(GenericArguments.catalogedElement(Text.of("note"), NotePitch.class), "-note", "n").valueFlag(GenericArguments.catalogedElement(Text.of("block"), BlockState.class), "-block", "b").valueFlag(GenericArguments.catalogedElement(Text.of("item"), ItemType.class), "-item", "i").valueFlag(GenericArguments.catalogedElement(Text.of("potion"), PotionEffectType.class), "-potion", "p").buildWith(GenericArguments.none())).executor((src, args) -> {
        final ParticleType particleType = args.<ParticleType>getOne("type").get();
        final Vector3d position = args.<Vector3d>getOne("position").get();
        final World world = args.<WorldProperties>getOne("world").map(props -> Sponge.getServer().getWorld(props.getUniqueId()).get()).orElseGet(((Locatable) src)::getWorld);
        final ParticleEffect.Builder builder = ParticleEffect.builder().type(particleType);
        args.<Integer>getOne("quantity").ifPresent(builder::quantity);
        args.<Vector3d>getOne("offset").ifPresent(builder::offset);
        args.<Vector3d>getOne("velocity").ifPresent(builder::velocity);
        args.<Vector3d>getOne("color").ifPresent(color -> builder.option(ParticleOptions.COLOR, Color.of(color.toInt())));
        args.<NotePitch>getOne("note").ifPresent(note -> builder.option(ParticleOptions.NOTE, note));
        args.<Double>getOne("scale").ifPresent(scale -> builder.option(ParticleOptions.SCALE, scale));
        args.<BlockState>getOne("block").ifPresent(blockState -> builder.option(ParticleOptions.BLOCK_STATE, blockState));
        args.<ItemType>getOne("item").ifPresent(item -> builder.option(ParticleOptions.ITEM_STACK_SNAPSHOT, new LanternItemStack(item).createSnapshot()));
        args.<PotionEffectType>getOne("potion").ifPresent(type -> builder.option(ParticleOptions.POTION_EFFECT_TYPE, type));
        world.spawnParticles(builder.build(), position);
        src.sendMessage(t("Successfully spawned the particle %s", particleType.getName()));
        return CommandResult.success();
    });
}
Also used : CommandResult(org.spongepowered.api.command.CommandResult) PotionEffectType(org.spongepowered.api.effect.potion.PotionEffectType) TranslationHelper.t(org.lanternpowered.server.text.translation.TranslationHelper.t) ParticleOptions(org.spongepowered.api.effect.particle.ParticleOptions) BlockTypes(org.spongepowered.api.block.BlockTypes) Sponge(org.spongepowered.api.Sponge) Vector3d(com.flowpowered.math.vector.Vector3d) GenericArguments(org.spongepowered.api.command.args.GenericArguments) CommandSpec(org.spongepowered.api.command.spec.CommandSpec) BlockState(org.spongepowered.api.block.BlockState) ParticleEffect(org.spongepowered.api.effect.particle.ParticleEffect) ParticleType(org.spongepowered.api.effect.particle.ParticleType) ItemStack(org.spongepowered.api.item.inventory.ItemStack) Text(org.spongepowered.api.text.Text) Locatable(org.spongepowered.api.world.Locatable) World(org.spongepowered.api.world.World) WorldProperties(org.spongepowered.api.world.storage.WorldProperties) NotePitch(org.spongepowered.api.data.type.NotePitch) Color(org.spongepowered.api.util.Color) LanternItemStack(org.lanternpowered.server.inventory.LanternItemStack) ItemType(org.spongepowered.api.item.ItemType) PluginContainer(org.spongepowered.api.plugin.PluginContainer) ParticleEffect(org.spongepowered.api.effect.particle.ParticleEffect) Vector3d(com.flowpowered.math.vector.Vector3d) ItemType(org.spongepowered.api.item.ItemType) ParticleType(org.spongepowered.api.effect.particle.ParticleType) World(org.spongepowered.api.world.World) LanternItemStack(org.lanternpowered.server.inventory.LanternItemStack) WorldProperties(org.spongepowered.api.world.storage.WorldProperties) NotePitch(org.spongepowered.api.data.type.NotePitch)

Example 88 with WorldProperties

use of org.spongepowered.api.world.storage.WorldProperties in project LanternServer by LanternPowered.

the class CommandDifficulty method completeSpec.

@Override
public void completeSpec(PluginContainer pluginContainer, CommandSpec.Builder specBuilder) {
    final ImmutableMap.Builder<String, Object> baseBuilder = ImmutableMap.builder();
    final ImmutableMap.Builder<String, Object> aliasesBuilder = ImmutableMap.builder();
    for (Difficulty difficulty : Sponge.getRegistry().getAllOf(Difficulty.class)) {
        baseBuilder.put(difficulty.getName(), difficulty);
        aliasesBuilder.put(difficulty.getName().substring(0, 1), difficulty);
        aliasesBuilder.put(((LanternDifficulty) difficulty).getInternalId() + "", difficulty);
    }
    specBuilder.arguments(GenericArguments.flags().valueFlag(GenericArguments.world(CommandHelper.WORLD_KEY), "-world", "w").buildWith(GenericArguments.none()), ChoicesElement.of(Text.of("difficulty"), baseBuilder.build(), aliasesBuilder.build(), false, true)).executor((src, args) -> {
        WorldProperties world = CommandHelper.getWorldProperties(src, args);
        Difficulty difficulty = args.<Difficulty>getOne("difficulty").get();
        world.setDifficulty(difficulty);
        src.sendMessage(t("commands.difficulty.success", difficulty.getName()));
        return CommandResult.success();
    });
}
Also used : Difficulty(org.spongepowered.api.world.difficulty.Difficulty) LanternDifficulty(org.lanternpowered.server.world.difficulty.LanternDifficulty) LanternDifficulty(org.lanternpowered.server.world.difficulty.LanternDifficulty) ImmutableMap(com.google.common.collect.ImmutableMap) WorldProperties(org.spongepowered.api.world.storage.WorldProperties)

Example 89 with WorldProperties

use of org.spongepowered.api.world.storage.WorldProperties 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();
    });
}
Also used : CommandResult(org.spongepowered.api.command.CommandResult) RelativeDouble(org.lanternpowered.server.command.element.RelativeDouble) Location(org.spongepowered.api.world.Location) TranslationHelper.t(org.lanternpowered.server.text.translation.TranslationHelper.t) Vector3d(com.flowpowered.math.vector.Vector3d) GenericArguments(org.spongepowered.api.command.args.GenericArguments) RelativeVector3d(org.lanternpowered.server.command.element.RelativeVector3d) CommandSpec(org.spongepowered.api.command.spec.CommandSpec) CommandException(org.spongepowered.api.command.CommandException) Text(org.spongepowered.api.text.Text) Lantern(org.lanternpowered.server.game.Lantern) Transform(org.spongepowered.api.entity.Transform) GenericArguments2(org.lanternpowered.server.command.element.GenericArguments2) World(org.spongepowered.api.world.World) WorldProperties(org.spongepowered.api.world.storage.WorldProperties) Optional(java.util.Optional) Player(org.spongepowered.api.entity.living.player.Player) PluginContainer(org.spongepowered.api.plugin.PluginContainer) Player(org.spongepowered.api.entity.living.player.Player) RelativeVector3d(org.lanternpowered.server.command.element.RelativeVector3d) CommandException(org.spongepowered.api.command.CommandException) World(org.spongepowered.api.world.World) Vector3d(com.flowpowered.math.vector.Vector3d) RelativeVector3d(org.lanternpowered.server.command.element.RelativeVector3d) RelativeDouble(org.lanternpowered.server.command.element.RelativeDouble) WorldProperties(org.spongepowered.api.world.storage.WorldProperties)

Example 90 with WorldProperties

use of org.spongepowered.api.world.storage.WorldProperties in project Nucleus by NucleusPowered.

the class KillEntityCommand method executeCommand.

@Override
protected CommandResult executeCommand(CommandSource src, CommandContext args) throws Exception {
    if (!(src instanceof Locatable) && args.hasAny(radius)) {
        // We can't do that.
        throw ReturnMessageException.fromKey("command.killentity.commandsourceradius");
    }
    if (args.hasAny(radius) && args.hasAny(world)) {
        // Can't do that, either.
        throw ReturnMessageException.fromKey("command.killentity.radiusworld");
    }
    Set<Entity> currentEntities;
    if (args.hasAny(radius)) {
        Locatable l = ((Locatable) src);
        Vector3d locationTest = l.getLocation().getPosition();
        int r = args.<Integer>getOne(radius).get();
        currentEntities = Sets.newHashSet(l.getWorld().getEntities(entity -> entity.getTransform().getPosition().distance(locationTest) <= r));
    } else {
        WorldProperties worldProperties = this.getWorldFromUserOrArgs(src, world, args);
        currentEntities = Sets.newHashSet(Sponge.getServer().getWorld(worldProperties.getUniqueId()).get().getEntities());
    }
    Predicate<Entity> entityPredicate = args.<Predicate<Entity>>getAll(type).stream().reduce(Predicate::or).orElseThrow(() -> ReturnMessageException.fromKey("command.killentity.noselection"));
    Set<Entity> toKill = currentEntities.stream().filter(entityPredicate).collect(Collectors.toSet());
    if (toKill.isEmpty()) {
        throw ReturnMessageException.fromKey("command.killentity.nothing");
    }
    int killCount = toKill.size();
    toKill.forEach(x -> {
        x.offer(Keys.HEALTH, 0d);
        x.remove();
    });
    src.sendMessage(plugin.getMessageProvider().getTextMessageWithFormat("command.killentity.success", String.valueOf(killCount)));
    return CommandResult.affectedEntities(killCount);
}
Also used : Entity(org.spongepowered.api.entity.Entity) Vector3d(com.flowpowered.math.vector.Vector3d) WorldProperties(org.spongepowered.api.world.storage.WorldProperties) Locatable(org.spongepowered.api.world.Locatable)

Aggregations

WorldProperties (org.spongepowered.api.world.storage.WorldProperties)109 World (org.spongepowered.api.world.World)37 CommandException (org.spongepowered.api.command.CommandException)27 ArrayList (java.util.ArrayList)26 Player (org.spongepowered.api.entity.living.player.Player)19 Text (org.spongepowered.api.text.Text)16 Vector3d (com.flowpowered.math.vector.Vector3d)9 ReturnMessageException (io.github.nucleuspowered.nucleus.internal.command.ReturnMessageException)9 Listener (org.spongepowered.api.event.Listener)9 WorldGeneratorModifier (org.spongepowered.api.world.gen.WorldGeneratorModifier)9 List (java.util.List)8 Optional (java.util.Optional)8 CommandResult (org.spongepowered.api.command.CommandResult)8 Vector3i (com.flowpowered.math.vector.Vector3i)7 IOException (java.io.IOException)7 Sponge (org.spongepowered.api.Sponge)7 CommandSource (org.spongepowered.api.command.CommandSource)7 IMixinWorldInfo (org.spongepowered.common.interfaces.world.IMixinWorldInfo)7 GenericArguments (org.spongepowered.api.command.args.GenericArguments)6 Location (org.spongepowered.api.world.Location)6