Search in sources :

Example 1 with WorldBorder

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

the class ServerLevelMixin_API method setBorder.

@Override
public WorldBorder setBorder(final WorldBorder border) {
    final WorldBorder worldBorder = ((WorldBorderBridge) ((CollisionGetter) this).getWorldBorder()).bridge$applyFrom(border);
    if (worldBorder == null) {
        return (WorldBorder) net.minecraft.world.level.border.WorldBorder.DEFAULT_SETTINGS;
    }
    this.serverLevelData.setWorldBorder((net.minecraft.world.level.border.WorldBorder.Settings) border);
    return worldBorder;
}
Also used : WorldBorder(org.spongepowered.api.world.border.WorldBorder) WorldBorderBridge(org.spongepowered.common.bridge.world.level.border.WorldBorderBridge)

Example 2 with WorldBorder

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

the class ServerPlayerMixin_API method setWorldBorder.

@SuppressWarnings("ConstantConditions")
@Override
@NonNull
public Optional<WorldBorder> setWorldBorder(@Nullable final WorldBorder border) {
    if (this.impl$isFake) {
        return Optional.empty();
    }
    final Optional<WorldBorder> currentBorder = this.worldBorder();
    if (Objects.equals(currentBorder.orElse(null), border)) {
        // do not fire an event since nothing would have changed
        return currentBorder;
    }
    final ChangeWorldBorderEvent.Player event = SpongeEventFactory.createChangeWorldBorderEventPlayer(PhaseTracker.getCauseStackManager().currentCause(), Optional.ofNullable(border), Optional.ofNullable(border), this, Optional.ofNullable(border));
    if (SpongeCommon.post(event)) {
        return currentBorder;
    }
    if (this.api$worldBorder != null) {
        // is the world border about to be unset?
        ((WorldBorderAccessor) this.api$worldBorder).accessor$listeners().remove(// remove the listener, if so
        ((ServerPlayerBridge) this).bridge$getWorldBorderListener());
    }
    final Optional<WorldBorder> toSet = event.newBorder();
    if (toSet.isPresent()) {
        final net.minecraft.world.level.border.WorldBorder mutableWorldBorder = new net.minecraft.world.level.border.WorldBorder();
        this.api$worldBorder = ((WorldBorderBridge) mutableWorldBorder);
        this.api$worldBorder.bridge$applyFrom(toSet.get());
        mutableWorldBorder.addListener(((ServerPlayerBridge) this).bridge$getWorldBorderListener());
        this.connection.send(new ClientboundSetBorderPacket((net.minecraft.world.level.border.WorldBorder) this.api$worldBorder, ClientboundSetBorderPacket.Type.INITIALIZE));
    } else {
        // unset the border if null
        this.api$worldBorder = null;
        this.connection.send(new ClientboundSetBorderPacket(this.shadow$getCommandSenderWorld().getWorldBorder(), ClientboundSetBorderPacket.Type.INITIALIZE));
    }
    return toSet;
}
Also used : ClientboundSetBorderPacket(net.minecraft.network.protocol.game.ClientboundSetBorderPacket) WorldBorder(org.spongepowered.api.world.border.WorldBorder) ChangeWorldBorderEvent(org.spongepowered.api.event.world.ChangeWorldBorderEvent) WorldBorderBridge(org.spongepowered.common.bridge.world.level.border.WorldBorderBridge) NonNull(org.checkerframework.checker.nullness.qual.NonNull)

Example 3 with WorldBorder

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

the class WorldBorderListener method logBorder.

private void logBorder(final ChangeWorldBorderEvent event) {
    if (event.previousBorder().isPresent()) {
        final WorldBorder worldBorder = event.previousBorder().get();
        this.logBorder("Previous", worldBorder);
    } else {
        this.logger.info("No previous border");
    }
    if (event.newBorder().isPresent()) {
        final WorldBorder worldBorder = event.newBorder().get();
        this.logBorder("New", worldBorder);
    } else {
        this.logger.info("No new border");
    }
}
Also used : WorldBorder(org.spongepowered.api.world.border.WorldBorder)

Aggregations

WorldBorder (org.spongepowered.api.world.border.WorldBorder)3 WorldBorderBridge (org.spongepowered.common.bridge.world.level.border.WorldBorderBridge)2 ClientboundSetBorderPacket (net.minecraft.network.protocol.game.ClientboundSetBorderPacket)1 NonNull (org.checkerframework.checker.nullness.qual.NonNull)1 ChangeWorldBorderEvent (org.spongepowered.api.event.world.ChangeWorldBorderEvent)1