use of org.spongepowered.common.bridge.network.ConnectionHolderBridge in project SpongeCommon by SpongePowered.
the class PacketSender method sendTo.
public static void sendTo(final EngineConnection connection, final Packet<?> packet, @Nullable final Consumer<Future<? super Void>> listener) {
final Connection networkManager = ((ConnectionHolderBridge) connection).bridge$getConnection();
GenericFutureListener<? extends Future<? super Void>> asyncListener = null;
if (listener != null) {
final EngineConnectionSide<?> side = connection.side();
// Complete the netty callback on the sync thread
asyncListener = future -> {
final BlockableEventLoop<?> executor;
if (side == EngineConnectionSide.CLIENT) {
executor = (BlockableEventLoop<?>) Sponge.client();
} else {
executor = (BlockableEventLoop<?>) Sponge.server();
}
executor.execute(() -> listener.accept(future));
};
}
networkManager.send(packet, asyncListener);
}
Aggregations