Search in sources :

Example 1 with WorldBorderBridge

use of org.spongepowered.common.bridge.world.level.border.WorldBorderBridge 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 WorldBorderBridge

use of org.spongepowered.common.bridge.world.level.border.WorldBorderBridge 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)

Aggregations

WorldBorder (org.spongepowered.api.world.border.WorldBorder)2 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