Search in sources :

Example 16 with Message

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

the class CodecPlayOutEffect method encode.

@Override
public ByteBuffer encode(CodecContext context, Message message) throws CodecException {
    final ByteBuffer buf = context.byteBufAlloc().buffer();
    if (message instanceof MessagePlayOutEffect) {
        final MessagePlayOutEffect message1 = (MessagePlayOutEffect) message;
        buf.writeInteger(message1.getType());
        buf.write(Types.VECTOR_3_I, message1.getPosition());
        buf.writeInteger(message1.getData());
        buf.writeBoolean(message1.isBroadcast());
    } else if (message instanceof MessagePlayOutRecord) {
        final MessagePlayOutRecord message1 = (MessagePlayOutRecord) message;
        buf.writeInteger(1010);
        buf.write(Types.VECTOR_3_I, message1.getPosition());
        buf.writeInteger(message1.getRecord().map(type -> 2256 + ((LanternRecordType) type).getInternalId()).orElse(0));
        buf.writeBoolean(false);
    } else {
        throw new EncoderException("Unsupported message type: " + message.getClass().getName());
    }
    return buf;
}
Also used : EncoderException(io.netty.handler.codec.EncoderException) CodecException(io.netty.handler.codec.CodecException) Codec(org.lanternpowered.server.network.message.codec.Codec) MessagePlayOutRecord(org.lanternpowered.server.network.vanilla.message.type.play.MessagePlayOutRecord) LanternRecordType(org.lanternpowered.server.data.type.record.LanternRecordType) MessagePlayOutEffect(org.lanternpowered.server.network.vanilla.message.type.play.MessagePlayOutEffect) ByteBuffer(org.lanternpowered.server.network.buffer.ByteBuffer) Types(org.lanternpowered.server.network.buffer.objects.Types) CodecContext(org.lanternpowered.server.network.message.codec.CodecContext) Message(org.lanternpowered.server.network.message.Message) EncoderException(io.netty.handler.codec.EncoderException) MessagePlayOutEffect(org.lanternpowered.server.network.vanilla.message.type.play.MessagePlayOutEffect) MessagePlayOutRecord(org.lanternpowered.server.network.vanilla.message.type.play.MessagePlayOutRecord) ByteBuffer(org.lanternpowered.server.network.buffer.ByteBuffer)

Example 17 with Message

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

the class LanternWorld method sendMessage.

@Override
public void sendMessage(ChatType type, Text message) {
    checkNotNull(type, "chatType");
    checkNotNull(message, "message");
    if (!this.players.isEmpty()) {
        final Map<Locale, Message> networkMessages = new HashMap<>();
        for (LanternPlayer player : this.players) {
            player.getConnection().send(networkMessages.computeIfAbsent(player.getLocale(), locale -> ((LanternChatType) type).getMessageProvider().apply(message, locale)));
        }
    }
}
Also used : Locale(java.util.Locale) LanternEntity(org.lanternpowered.server.entity.LanternEntity) AnvilChunkIOService(org.lanternpowered.server.data.io.anvil.AnvilChunkIOService) WorldStorage(org.spongepowered.api.world.storage.WorldStorage) WorldConfig(org.lanternpowered.server.config.world.WorldConfig) RuleHolder(org.lanternpowered.server.world.rules.RuleHolder) SoundCategory(org.spongepowered.api.effect.sound.SoundCategory) BookView(org.spongepowered.api.text.BookView) ItemStack(org.spongepowered.api.item.inventory.ItemStack) ChunkIOService(org.lanternpowered.server.data.io.ChunkIOService) LanternChunkManager(org.lanternpowered.server.world.chunk.LanternChunkManager) MutableBiomeVolumeWorker(org.spongepowered.api.world.extent.worker.MutableBiomeVolumeWorker) Map(java.util.Map) GameProfile(org.spongepowered.api.profile.GameProfile) VecHelper(org.lanternpowered.server.util.VecHelper) LanternSoundType(org.lanternpowered.server.effect.sound.LanternSoundType) Path(java.nio.file.Path) InteractWithBlockBehavior(org.lanternpowered.server.block.behavior.types.InteractWithBlockBehavior) MessagePlayOutParticleEffect(org.lanternpowered.server.network.vanilla.message.type.play.MessagePlayOutParticleEffect) RuleType(org.lanternpowered.server.world.rules.RuleType) Location(org.spongepowered.api.world.Location) AbstractViewer(org.lanternpowered.server.effect.AbstractViewer) HardnessProperty(org.spongepowered.api.data.property.block.HardnessProperty) LanternWeather(org.lanternpowered.server.world.weather.LanternWeather) Extent(org.spongepowered.api.world.extent.Extent) UnbreakableProperty(org.spongepowered.api.data.property.block.UnbreakableProperty) ArchetypeVolume(org.spongepowered.api.world.extent.ArchetypeVolume) DataContainer(org.spongepowered.api.data.DataContainer) Set(java.util.Set) Weathers(org.spongepowered.api.world.weather.Weathers) BlockAction(org.lanternpowered.server.block.action.BlockAction) BlockState(org.spongepowered.api.block.BlockState) Direction(org.spongepowered.api.util.Direction) ConstructEntityEvent(org.spongepowered.api.event.entity.ConstructEntityEvent) AbstractExtent(org.lanternpowered.server.world.extent.AbstractExtent) World(org.spongepowered.api.world.World) MessagePlayOutRecord(org.lanternpowered.server.network.vanilla.message.type.play.MessagePlayOutRecord) Player(org.spongepowered.api.entity.living.player.Player) EntityProtocolType(org.lanternpowered.server.network.entity.EntityProtocolType) ObservedChunkManager(org.lanternpowered.server.entity.living.player.ObservedChunkManager) BehaviorPipeline(org.lanternpowered.server.behavior.pipeline.BehaviorPipeline) ImmutableValue(org.spongepowered.api.data.value.immutable.ImmutableValue) Vector3d(com.flowpowered.math.vector.Vector3d) AABB(org.spongepowered.api.util.AABB) GameModes(org.spongepowered.api.entity.living.player.gamemode.GameModes) Supplier(java.util.function.Supplier) Key(org.spongepowered.api.data.key.Key) ArrayList(java.util.ArrayList) Vector2i(com.flowpowered.math.vector.Vector2i) LanternTitles(org.lanternpowered.server.text.title.LanternTitles) Lists(com.google.common.collect.Lists) CauseStack(org.lanternpowered.server.event.CauseStack) ExtentViewDownsize(org.lanternpowered.server.world.extent.ExtentViewDownsize) Text(org.spongepowered.api.text.Text) Nullable(javax.annotation.Nullable) ContextKeys(org.lanternpowered.server.behavior.ContextKeys) MessagePlayOutStopSounds(org.lanternpowered.server.network.vanilla.message.type.play.MessagePlayOutStopSounds) Context(org.spongepowered.api.service.context.Context) SpongeEventFactory(org.spongepowered.api.event.SpongeEventFactory) InvalidDataException(org.spongepowered.api.data.persistence.InvalidDataException) SpawnEntityEvent(org.spongepowered.api.event.entity.SpawnEntityEvent) Scoreboard(org.spongepowered.api.scoreboard.Scoreboard) IOException(java.io.IOException) DataHolder(org.spongepowered.api.data.DataHolder) Entity(org.spongepowered.api.entity.Entity) Message(org.lanternpowered.server.network.message.Message) LanternMutableBlockVolumeWorker(org.lanternpowered.server.world.extent.worker.LanternMutableBlockVolumeWorker) DataView(org.spongepowered.api.data.DataView) Vector3i(com.flowpowered.math.vector.Vector3i) PortalAgent(org.spongepowered.api.world.PortalAgent) EventContextKeys(org.spongepowered.api.event.cause.EventContextKeys) LanternBlockType(org.lanternpowered.server.block.LanternBlockType) LanternChunkPreGenerateTask(org.lanternpowered.server.world.pregen.LanternChunkPreGenerateTask) BiFunction(java.util.function.BiFunction) LoggerFactory(org.slf4j.LoggerFactory) EntityProtocolManager(org.lanternpowered.server.network.entity.EntityProtocolManager) LanternChunkTicketManager(org.lanternpowered.server.world.chunk.LanternChunkTicketManager) SPACE_MIN(org.lanternpowered.server.world.chunk.LanternChunkLayout.SPACE_MIN) Behavior(org.lanternpowered.server.behavior.Behavior) EntitySnapshot(org.spongepowered.api.entity.EntitySnapshot) ChatType(org.spongepowered.api.text.chat.ChatType) Preconditions.checkArgument(com.google.common.base.Preconditions.checkArgument) BreakBlockBehavior(org.lanternpowered.server.block.behavior.types.BreakBlockBehavior) ParticleEffect(org.spongepowered.api.effect.particle.ParticleEffect) TileEntity(org.spongepowered.api.block.tileentity.TileEntity) Locale(java.util.Locale) ChunkPreGenerate(org.spongepowered.api.world.ChunkPreGenerate) Title(org.spongepowered.api.text.title.Title) MergeFunction(org.spongepowered.api.data.merge.MergeFunction) LanternChunk.fixEntityYSection(org.lanternpowered.server.world.chunk.LanternChunk.fixEntityYSection) Dimension(org.spongepowered.api.world.Dimension) MutableBlockVolumeWorker(org.spongepowered.api.world.extent.worker.MutableBlockVolumeWorker) SPACE_MAX(org.lanternpowered.server.world.chunk.LanternChunkLayout.SPACE_MAX) ImmutableSet(com.google.common.collect.ImmutableSet) User(org.spongepowered.api.entity.living.player.User) SoundType(org.spongepowered.api.effect.sound.SoundType) Predicate(java.util.function.Predicate) Collection(java.util.Collection) ChunkLoadingTicket(org.lanternpowered.server.world.chunk.ChunkLoadingTicket) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) Sponge(org.spongepowered.api.Sponge) Tuple(org.spongepowered.api.util.Tuple) UUID(java.util.UUID) Collectors(java.util.stream.Collectors) Sets(com.google.common.collect.Sets) LanternEntityType(org.lanternpowered.server.entity.LanternEntityType) LanternGame(org.lanternpowered.server.game.LanternGame) WorldGenerator(org.spongepowered.api.world.gen.WorldGenerator) Cause(org.spongepowered.api.event.cause.Cause) List(java.util.List) Lantern(org.lanternpowered.server.game.Lantern) Explosion(org.spongepowered.api.world.explosion.Explosion) Transform(org.spongepowered.api.entity.Transform) BlockType(org.spongepowered.api.block.BlockType) DataManipulator(org.spongepowered.api.data.manipulator.DataManipulator) Optional(java.util.Optional) RecordType(org.spongepowered.api.effect.sound.record.RecordType) ScheduledBlockUpdate(org.spongepowered.api.block.ScheduledBlockUpdate) LanternChatType(org.lanternpowered.server.text.chat.LanternChatType) BlockSnapshot(org.spongepowered.api.block.BlockSnapshot) ChatTypes(org.spongepowered.api.text.chat.ChatTypes) WeatherUniverse(org.lanternpowered.api.world.weather.WeatherUniverse) Keys(org.spongepowered.api.data.key.Keys) ScoreboardIO(org.lanternpowered.server.data.io.ScoreboardIO) LanternChunk(org.lanternpowered.server.world.chunk.LanternChunk) BehaviorContextImpl(org.lanternpowered.server.behavior.BehaviorContextImpl) BiomeType(org.spongepowered.api.world.biome.BiomeType) HashMap(java.util.HashMap) DataTransactionResult(org.spongepowered.api.data.DataTransactionResult) Function(java.util.function.Function) BlockChangeFlag(org.spongepowered.api.world.BlockChangeFlag) ImmutableList(com.google.common.collect.ImmutableList) EntityTypes(org.spongepowered.api.entity.EntityTypes) PlaceBlockBehavior(org.lanternpowered.server.block.behavior.types.PlaceBlockBehavior) Rule(org.lanternpowered.server.world.rules.Rule) Logger(org.slf4j.Logger) Weather(org.spongepowered.api.world.weather.Weather) Iterator(java.util.Iterator) Preconditions.checkNotNull(com.google.common.base.Preconditions.checkNotNull) BaseValue(org.spongepowered.api.data.value.BaseValue) Chunk(org.spongepowered.api.world.Chunk) Consumer(java.util.function.Consumer) LanternMutableBiomeVolumeWorker(org.lanternpowered.server.world.extent.worker.LanternMutableBiomeVolumeWorker) LanternDimensionType(org.lanternpowered.server.world.dimension.LanternDimensionType) Difficulty(org.spongepowered.api.world.difficulty.Difficulty) LanternPlayer(org.lanternpowered.server.entity.living.player.LanternPlayer) Property(org.spongepowered.api.data.Property) IGeneratorType(org.lanternpowered.server.world.gen.IGeneratorType) EntityType(org.spongepowered.api.entity.EntityType) MessageChannel(org.spongepowered.api.text.channel.MessageChannel) Collections(java.util.Collections) Message(org.lanternpowered.server.network.message.Message) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap) LanternPlayer(org.lanternpowered.server.entity.living.player.LanternPlayer)

Example 18 with Message

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

the class LanternWorldBorder method broadcast.

private void broadcast(Supplier<Message> supplier) {
    if (!this.players.isEmpty()) {
        final Message message = supplier.get();
        this.players.forEach(p -> p.getConnection().send(message));
    }
}
Also used : Message(org.lanternpowered.server.network.message.Message)

Example 19 with Message

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

the class LanternBossBar method setPercent.

@Override
public LanternBossBar setPercent(float percent) {
    checkNotNull(percent >= 0f && percent <= 1f, "Percent must be between 0 and 1, but %s is not", percent);
    if (percent != this.percent && !this.viewers.isEmpty()) {
        final Message message = new MessagePlayOutBossBar.UpdatePercent(this.uniqueId, percent);
        this.viewers.forEach(player -> player.getConnection().send(message));
    }
    this.percent = percent;
    return this;
}
Also used : Message(org.lanternpowered.server.network.message.Message)

Example 20 with Message

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

the class MessageProcessorHandler method acceptOutboundMessage.

@Override
public boolean acceptOutboundMessage(Object msg) throws Exception {
    final Message message = (Message) msg;
    final Protocol protocol = this.codecContext.getSession().getProtocol();
    final MessageRegistration registration = protocol.outbound().findByMessageType(message.getClass()).orElse(null);
    if (registration == null) {
        throw new EncoderException("Message type (" + message.getClass().getName() + ") is not registered in state " + this.codecContext.getSession().getProtocolState().name() + "!");
    }
    final List<Processor> processors = ((MessageRegistration) protocol.outbound().findByMessageType(message.getClass()).get()).getProcessors();
    // Only process if there are processors found
    if (!processors.isEmpty()) {
        final List<Object> messages = new ArrayList<>();
        for (Processor processor : processors) {
            // The processor should handle the output messages
            processor.process(this.codecContext, message, messages);
        }
        if (message instanceof ReferenceCounted && !messages.contains(message)) {
            ((ReferenceCounted) message).release();
        }
        if (!messages.isEmpty()) {
            this.messages.set(messages);
        }
        return true;
    }
    return false;
}
Also used : EncoderException(io.netty.handler.codec.EncoderException) MessageRegistration(org.lanternpowered.server.network.message.MessageRegistration) Processor(org.lanternpowered.server.network.message.processor.Processor) Message(org.lanternpowered.server.network.message.Message) ArrayList(java.util.ArrayList) Protocol(org.lanternpowered.server.network.protocol.Protocol) ReferenceCounted(io.netty.util.ReferenceCounted)

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