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));
}
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;
}
Aggregations