Search in sources :

Example 21 with Message

use of org.lanternpowered.server.network.message.Message in project LanternServer by LanternPowered.

the class LanternChannelRegistrar method sendPayloadToAll.

void sendPayloadToAll(String channel, Consumer<ByteBuffer> payload) {
    checkNotNull(payload, "payload");
    final Iterator<Player> players = this.server.getOnlinePlayers().stream().filter(player -> ((LanternPlayer) player).getConnection().getRegisteredChannels().contains(channel)).iterator();
    if (players.hasNext()) {
        final ByteBuffer buf = ByteBufferAllocator.unpooled().buffer();
        payload.accept(buf);
        final Message msg = new MessagePlayInOutChannelPayload(channel, buf);
        players.forEachRemaining(player -> ((LanternPlayer) player).getConnection().send(msg));
    }
}
Also used : RemoteConnection(org.spongepowered.api.network.RemoteConnection) ByteBufferAllocator(org.lanternpowered.server.network.buffer.ByteBufferAllocator) IndexedMessageChannel(org.spongepowered.api.network.ChannelBinding.IndexedMessageChannel) Inject(com.google.inject.Inject) MessagePlayInOutChannelPayload(org.lanternpowered.server.network.vanilla.message.type.play.MessagePlayInOutChannelPayload) Platform(org.spongepowered.api.Platform) MessagePlayInOutUnregisterChannels(org.lanternpowered.server.network.vanilla.message.type.play.MessagePlayInOutUnregisterChannels) Preconditions.checkArgument(com.google.common.base.Preconditions.checkArgument) NetworkSession(org.lanternpowered.server.network.NetworkSession) ChannelRegistrar(org.spongepowered.api.network.ChannelRegistrar) Map(java.util.Map) MessagePlayInOutRegisterChannels(org.lanternpowered.server.network.vanilla.message.type.play.MessagePlayInOutRegisterChannels) Server(org.spongepowered.api.Server) Conditions.checkNotNullOrEmpty(org.lanternpowered.server.util.Conditions.checkNotNullOrEmpty) ByteBuffer(org.lanternpowered.server.network.buffer.ByteBuffer) PluginContainer(org.spongepowered.api.plugin.PluginContainer) ImmutableSet(com.google.common.collect.ImmutableSet) Iterator(java.util.Iterator) Preconditions.checkNotNull(com.google.common.base.Preconditions.checkNotNull) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) Set(java.util.Set) Sets(com.google.common.collect.Sets) Message(org.lanternpowered.server.network.message.Message) ChannelBinding(org.spongepowered.api.network.ChannelBinding) Consumer(java.util.function.Consumer) ChannelRegistrationException(org.spongepowered.api.network.ChannelRegistrationException) LanternPlayer(org.lanternpowered.server.entity.living.player.LanternPlayer) Optional(java.util.Optional) Player(org.spongepowered.api.entity.living.player.Player) Conditions.checkPlugin(org.lanternpowered.server.util.Conditions.checkPlugin) Collections(java.util.Collections) Singleton(com.google.inject.Singleton) LanternPlayer(org.lanternpowered.server.entity.living.player.LanternPlayer) Player(org.spongepowered.api.entity.living.player.Player) Message(org.lanternpowered.server.network.message.Message) MessagePlayInOutChannelPayload(org.lanternpowered.server.network.vanilla.message.type.play.MessagePlayInOutChannelPayload) ByteBuffer(org.lanternpowered.server.network.buffer.ByteBuffer) LanternPlayer(org.lanternpowered.server.entity.living.player.LanternPlayer)

Aggregations

Message (org.lanternpowered.server.network.message.Message)21 NullMessage (org.lanternpowered.server.network.message.NullMessage)7 BulkMessage (org.lanternpowered.server.network.message.BulkMessage)6 ArrayList (java.util.ArrayList)5 ByteBuffer (org.lanternpowered.server.network.buffer.ByteBuffer)5 HandlerMessage (org.lanternpowered.server.network.message.HandlerMessage)5 ChannelPromise (io.netty.channel.ChannelPromise)4 EventLoop (io.netty.channel.EventLoop)4 EncoderException (io.netty.handler.codec.EncoderException)3 ReferenceCountUtil (io.netty.util.ReferenceCountUtil)3 Iterator (java.util.Iterator)3 Map (java.util.Map)3 Set (java.util.Set)3 LanternPlayer (org.lanternpowered.server.entity.living.player.LanternPlayer)3 Preconditions.checkArgument (com.google.common.base.Preconditions.checkArgument)2 Preconditions.checkNotNull (com.google.common.base.Preconditions.checkNotNull)2 ImmutableSet (com.google.common.collect.ImmutableSet)2 Sets (com.google.common.collect.Sets)2 CodecException (io.netty.handler.codec.CodecException)2 Collections (java.util.Collections)2