Search in sources :

Example 1 with ClientboundSetBorderPacket

use of net.minecraft.network.protocol.game.ClientboundSetBorderPacket in project SpongeCommon by SpongePowered.

the class PerWorldBorderListener method sendWorldBorderActionPacket.

private void sendWorldBorderActionPacket(final WorldBorder border, final ClientboundSetBorderPacket.Type action) {
    final ClientboundSetBorderPacket packet = new ClientboundSetBorderPacket(border, action);
    this.world.players().forEach(player -> player.connection.send(packet));
}
Also used : ClientboundSetBorderPacket(net.minecraft.network.protocol.game.ClientboundSetBorderPacket)

Example 2 with ClientboundSetBorderPacket

use of net.minecraft.network.protocol.game.ClientboundSetBorderPacket 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

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