Search in sources :

Example 1 with ConnectionHolderBridge

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);
}
Also used : EngineConnection(org.spongepowered.api.network.EngineConnection) Connection(net.minecraft.network.Connection) ConnectionHolderBridge(org.spongepowered.common.bridge.network.ConnectionHolderBridge)

Aggregations

Connection (net.minecraft.network.Connection)1 EngineConnection (org.spongepowered.api.network.EngineConnection)1 ConnectionHolderBridge (org.spongepowered.common.bridge.network.ConnectionHolderBridge)1