Search in sources :

Example 1 with WorldBorder

use of org.spongepowered.api.world.WorldBorder in project SpongeCommon by SpongePowered.

the class MixinEntityPlayerMP method setWorldBorder.

@Override
public void setWorldBorder(@Nullable WorldBorder border, Cause cause) {
    if (this.worldBorder == border) {
        // do not fire an event since nothing would have changed
        return;
    }
    if (!SpongeImpl.postEvent(SpongeEventFactory.createChangeWorldBorderEventTargetPlayer(cause, Optional.ofNullable(this.worldBorder), Optional.ofNullable(border), this))) {
        if (this.worldBorder != null) {
            // is the world border about to be unset?
            // remove the listener, if so
            ((net.minecraft.world.border.WorldBorder) this.worldBorder).listeners.remove(this.borderListener);
        }
        this.worldBorder = border;
        if (this.worldBorder != null) {
            ((net.minecraft.world.border.WorldBorder) this.worldBorder).addListener(this.borderListener);
            this.connection.sendPacket(new SPacketWorldBorder((net.minecraft.world.border.WorldBorder) this.worldBorder, SPacketWorldBorder.Action.INITIALIZE));
        } else {
            // unset the border if null
            this.connection.sendPacket(new SPacketWorldBorder(this.world.getWorldBorder(), SPacketWorldBorder.Action.INITIALIZE));
        }
    }
}
Also used : SPacketWorldBorder(net.minecraft.network.play.server.SPacketWorldBorder) WorldBorder(org.spongepowered.api.world.WorldBorder) SPacketWorldBorder(net.minecraft.network.play.server.SPacketWorldBorder)

Example 2 with WorldBorder

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

the class CommandBorder method completeSpec.

@Override
public void completeSpec(PluginContainer pluginContainer, CommandSpec.Builder specBuilder) {
    specBuilder.child(CommandSpec.builder().arguments(GenericArguments.flags().valueFlag(GenericArguments.world(CommandHelper.WORLD_KEY), "-world", "w").buildWith(GenericArguments.none()), GenericArguments.doubleNum(Text.of("distance")), GenericArguments.optional(GenericArguments.integer(Text.of("time")))).executor((src, args) -> {
        World world = CommandHelper.getWorld(src, args);
        WorldBorder border = world.getWorldBorder();
        double oldDiameter = border.getDiameter();
        double diameter = oldDiameter + args.<Double>getOne("distance").get();
        int time = args.<Integer>getOne("time").orElse(0);
        border.setDiameter(diameter, time);
        if (time > 0) {
            if (diameter < oldDiameter) {
                src.sendMessage(t("commands.worldborder.setSlowly.shrink.success", String.format("%.1f", diameter), String.format("%.1f", oldDiameter), time / 1000L));
            } else {
                src.sendMessage(t("commands.worldborder.setSlowly.grow.success", String.format("%.1f", diameter), String.format("%.1f", oldDiameter), time / 1000L));
            }
        } else {
            src.sendMessage(t("commands.worldborder.set.success", String.format("%.1f", diameter), String.format("%.1f", oldDiameter)));
        }
        return CommandResult.success();
    }).build(), "add").child(CommandSpec.builder().arguments(GenericArguments.doubleNum(Text.of("distance")), GenericArguments.optional(GenericArguments.integer(Text.of("time"))), GenericArguments.optional(GenericArguments.world(Text.of("world")))).executor((src, args) -> {
        World world = CommandHelper.getWorld(src, args);
        WorldBorder border = world.getWorldBorder();
        double oldDiameter = border.getDiameter();
        double diameter = args.<Double>getOne("distance").get();
        int time = args.<Integer>getOne("time").orElse(0);
        border.setDiameter(diameter, time);
        if (time > 0) {
            if (diameter < oldDiameter) {
                src.sendMessage(t("commands.worldborder.setSlowly.shrink.success", String.format("%.1f", diameter), String.format("%.1f", oldDiameter), time / 1000L));
            } else {
                src.sendMessage(t("commands.worldborder.setSlowly.grow.success", String.format("%.1f", diameter), String.format("%.1f", oldDiameter), time / 1000L));
            }
        } else {
            src.sendMessage(t("commands.worldborder.set.success", String.format("%.1f", diameter), String.format("%.1f", oldDiameter)));
        }
        return CommandResult.success();
    }).build(), "set").child(CommandSpec.builder().arguments(GenericArguments.doubleNum(Text.of("x")), GenericArguments.doubleNum(Text.of("z")), GenericArguments.optional(GenericArguments.world(Text.of("world")))).executor((src, args) -> {
        World world = CommandHelper.getWorld(src, args);
        WorldBorder border = world.getWorldBorder();
        double x = args.<Double>getOne("x").get();
        double z = args.<Double>getOne("z").get();
        border.setCenter(x, z);
        src.sendMessage(t("commands.worldborder.center.success", x, z));
        return CommandResult.success();
    }).build(), "center").child(CommandSpec.builder().child(CommandSpec.builder().arguments(GenericArguments.doubleNum(Text.of("damagePerBlock")), GenericArguments.optional(GenericArguments.world(Text.of("world")))).executor((src, args) -> {
        World world = CommandHelper.getWorld(src, args);
        WorldBorder border = world.getWorldBorder();
        double oldDamage = border.getDamageAmount();
        double damage = args.<Double>getOne("damagePerBlock").get();
        border.setDamageAmount(damage);
        src.sendMessage(t("commands.worldborder.damage.buffer.success", String.format("%.1f", damage), String.format("%.1f", oldDamage)));
        return CommandResult.success();
    }).build(), "amount").child(CommandSpec.builder().arguments(GenericArguments.doubleNum(Text.of("distance")), GenericArguments.optional(GenericArguments.world(Text.of("world")))).executor((src, args) -> {
        World world = CommandHelper.getWorld(src, args);
        WorldBorder border = world.getWorldBorder();
        double oldDistance = border.getDamageThreshold();
        double distance = args.<Double>getOne("distance").get();
        border.setDamageThreshold(args.<Double>getOne("distance").get());
        src.sendMessage(t("commands.worldborder.damage.amount.success", String.format("%.1f", distance), String.format("%.1f", oldDistance)));
        return CommandResult.success();
    }).build(), "buffer").build(), "damage").child(CommandSpec.builder().children(ImmutableMap.of(Lists.newArrayList("distance"), CommandSpec.builder().arguments(GenericArguments.integer(Text.of("distance")), GenericArguments.optional(GenericArguments.world(Text.of("world")))).executor((src, args) -> {
        World world = CommandHelper.getWorld(src, args);
        WorldBorder border = world.getWorldBorder();
        int oldDistance = border.getWarningDistance();
        int distance = args.<Integer>getOne("distance").get();
        border.setWarningDistance(distance);
        src.sendMessage(t("commands.worldborder.warning.distance.success", distance, oldDistance));
        return CommandResult.success();
    }).build(), Lists.newArrayList("time"), CommandSpec.builder().arguments(GenericArguments.integer(Text.of("time")), GenericArguments.optional(GenericArguments.world(Text.of("world")))).executor((src, args) -> {
        World world = CommandHelper.getWorld(src, args);
        WorldBorder border = world.getWorldBorder();
        int oldTime = border.getWarningTime();
        int time = args.<Integer>getOne("time").get();
        border.setWarningTime(time);
        src.sendMessage(t("commands.worldborder.warning.time.success", time, oldTime));
        return CommandResult.success();
    }).build())).build(), "warning").child(CommandSpec.builder().arguments(GenericArguments.optional(GenericArguments.world(Text.of("world")))).executor((src, args) -> {
        World world = CommandHelper.getWorld(src, args);
        WorldBorder border = world.getWorldBorder();
        double diameter = border.getDiameter();
        src.sendMessage(t("commands.worldborder.get.success", String.format("%.1f", diameter), String.format("%.1f", diameter)));
        return CommandResult.builder().queryResult((int) (diameter + 0.5)).build();
    }).build(), "get");
}
Also used : CommandResult(org.spongepowered.api.command.CommandResult) Lists(com.google.common.collect.Lists) Text(org.spongepowered.api.text.Text) TranslationHelper.t(org.lanternpowered.server.text.translation.TranslationHelper.t) ImmutableMap(com.google.common.collect.ImmutableMap) World(org.spongepowered.api.world.World) GenericArguments(org.spongepowered.api.command.args.GenericArguments) PluginContainer(org.spongepowered.api.plugin.PluginContainer) WorldBorder(org.spongepowered.api.world.WorldBorder) CommandSpec(org.spongepowered.api.command.spec.CommandSpec) WorldBorder(org.spongepowered.api.world.WorldBorder) World(org.spongepowered.api.world.World)

Example 3 with WorldBorder

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

the class RandomTeleportCommand method executeWithPlayer.

@Override
protected CommandResult executeWithPlayer(CommandSource src, Player player, CommandContext args, boolean self) throws Exception {
    // Get the current world.
    final WorldProperties wp;
    if (this.rc.getDefaultWorld().isPresent()) {
        wp = args.<WorldProperties>getOne(worldKey).orElseGet(() -> this.rc.getDefaultWorld().get());
    } else {
        wp = this.getWorldFromUserOrArgs(src, worldKey, args);
    }
    if (rc.isPerWorldPermissions()) {
        String name = wp.getWorldName();
        permissions.checkSuffix(src, "worlds." + name.toLowerCase(), () -> ReturnMessageException.fromKey("command.rtp.worldnoperm", name));
    }
    World currentWorld = Sponge.getServer().loadWorld(wp.getUniqueId()).orElse(null);
    if (currentWorld == null) {
        currentWorld = Sponge.getServer().loadWorld(wp).orElseThrow(() -> ReturnMessageException.fromKey("command.rtp.worldnoload", wp.getWorldName()));
    }
    // World border
    WorldBorder wb = currentWorld.getWorldBorder();
    int diameter = Math.min(Math.abs(rc.getRadius(currentWorld.getName()) * 2), (int) wb.getDiameter());
    int minDiameter = Math.max(Math.abs(rc.getMinRadius(currentWorld.getName()) * 2), 0);
    Vector3d centre = wb.getCenter();
    src.sendMessage(NucleusPlugin.getNucleus().getMessageProvider().getTextMessageWithFormat("command.rtp.searching"));
    if (self) {
        Sponge.getScheduler().createTaskBuilder().execute(new RTPTask(plugin, centre, minDiameter, diameter, getCost(src, args), player, currentWorld, rc)).submit(plugin);
    } else {
        Sponge.getScheduler().createTaskBuilder().execute(new RTPTask(plugin, centre, minDiameter, diameter, getCost(src, args), player, currentWorld, src, rc)).submit(plugin);
    }
    return CommandResult.success();
}
Also used : Vector3d(com.flowpowered.math.vector.Vector3d) WorldBorder(org.spongepowered.api.world.WorldBorder) World(org.spongepowered.api.world.World) WorldProperties(org.spongepowered.api.world.storage.WorldProperties)

Aggregations

WorldBorder (org.spongepowered.api.world.WorldBorder)3 World (org.spongepowered.api.world.World)2 Vector3d (com.flowpowered.math.vector.Vector3d)1 ImmutableMap (com.google.common.collect.ImmutableMap)1 Lists (com.google.common.collect.Lists)1 SPacketWorldBorder (net.minecraft.network.play.server.SPacketWorldBorder)1 TranslationHelper.t (org.lanternpowered.server.text.translation.TranslationHelper.t)1 CommandResult (org.spongepowered.api.command.CommandResult)1 GenericArguments (org.spongepowered.api.command.args.GenericArguments)1 CommandSpec (org.spongepowered.api.command.spec.CommandSpec)1 PluginContainer (org.spongepowered.api.plugin.PluginContainer)1 Text (org.spongepowered.api.text.Text)1 WorldProperties (org.spongepowered.api.world.storage.WorldProperties)1