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