Search in sources :

Example 21 with ByteBuffer

use of org.lanternpowered.server.network.buffer.ByteBuffer in project LanternServer by LanternPowered.

the class CodecPlayOutBlockAction method encode.

@Override
public ByteBuffer encode(CodecContext context, MessagePlayOutBlockAction message) throws CodecException {
    final ByteBuffer buf = context.byteBufAlloc().buffer();
    buf.write(Types.VECTOR_3_I, message.getPosition());
    final int[] parameters = message.getParameters();
    buf.writeByte((byte) parameters[0]);
    buf.writeByte((byte) parameters[1]);
    buf.writeVarInt(message.getBlockType());
    return buf;
}
Also used : ByteBuffer(org.lanternpowered.server.network.buffer.ByteBuffer)

Example 22 with ByteBuffer

use of org.lanternpowered.server.network.buffer.ByteBuffer in project LanternServer by LanternPowered.

the class CodecPlayOutBlockBreakAnimation method encode.

@Override
public ByteBuffer encode(CodecContext context, MessagePlayOutBlockBreakAnimation message) throws CodecException {
    ByteBuffer buf = context.byteBufAlloc().buffer();
    buf.writeVarInt(message.getId());
    buf.write(Types.VECTOR_3_I, message.getPosition());
    // Make sure that the state fits in the byte
    int state = message.getState();
    buf.writeByte((byte) (state >= 0 && state <= 9 ? state : 10));
    return buf;
}
Also used : ByteBuffer(org.lanternpowered.server.network.buffer.ByteBuffer)

Example 23 with ByteBuffer

use of org.lanternpowered.server.network.buffer.ByteBuffer in project LanternServer by LanternPowered.

the class CodecPlayOutChatMessage method encode.

@SuppressWarnings("deprecation")
@Override
public ByteBuffer encode(CodecContext context, MessagePlayOutChatMessage message) throws CodecException {
    final ByteBuffer buf = context.byteBufAlloc().buffer();
    buf.write(Types.LOCALIZED_TEXT, message.getMessage());
    buf.writeByte((byte) message.getType().ordinal());
    return buf;
}
Also used : ByteBuffer(org.lanternpowered.server.network.buffer.ByteBuffer)

Example 24 with ByteBuffer

use of org.lanternpowered.server.network.buffer.ByteBuffer in project LanternServer by LanternPowered.

the class CodecPlayOutScoreboardDisplayObjective method encode.

@Override
public ByteBuffer encode(CodecContext context, MessagePlayOutScoreboardDisplayObjective message) throws CodecException {
    ByteBuffer buf = context.byteBufAlloc().buffer();
    buf.writeByte((byte) ((LanternDisplaySlot) message.getDisplaySlot()).getInternalId());
    String objectiveName = message.getObjectiveName();
    buf.writeString(objectiveName == null ? "" : objectiveName);
    return buf;
}
Also used : LanternDisplaySlot(org.lanternpowered.server.scoreboard.LanternDisplaySlot) ByteBuffer(org.lanternpowered.server.network.buffer.ByteBuffer)

Example 25 with ByteBuffer

use of org.lanternpowered.server.network.buffer.ByteBuffer in project LanternServer by LanternPowered.

the class CodecPlayOutScoreboardScore method encode.

@Override
public ByteBuffer encode(CodecContext context, MessagePlayOutScoreboardScore message) throws CodecException {
    ByteBuffer buf = context.byteBufAlloc().buffer();
    buf.writeString(message.getScoreName());
    int action = message instanceof MessagePlayOutScoreboardScore.Remove ? 1 : 0;
    buf.writeByte((byte) action);
    buf.writeString(message.getObjectiveName());
    if (action == 0) {
        buf.writeVarInt(((MessagePlayOutScoreboardScore.CreateOrUpdate) message).getValue());
    }
    return buf;
}
Also used : MessagePlayOutScoreboardScore(org.lanternpowered.server.network.vanilla.message.type.play.MessagePlayOutScoreboardScore) ByteBuffer(org.lanternpowered.server.network.buffer.ByteBuffer)

Aggregations

ByteBuffer (org.lanternpowered.server.network.buffer.ByteBuffer)75 EncoderException (io.netty.handler.codec.EncoderException)9 Vector3d (com.flowpowered.math.vector.Vector3d)7 Message (org.lanternpowered.server.network.message.Message)5 Map (java.util.Map)4 MessagePlayInOutChannelPayload (org.lanternpowered.server.network.vanilla.message.type.play.MessagePlayInOutChannelPayload)4 AbstractParameterList (org.lanternpowered.server.network.entity.parameter.AbstractParameterList)3 NullMessage (org.lanternpowered.server.network.message.NullMessage)3 ItemStack (org.spongepowered.api.item.inventory.ItemStack)3 Vector3i (com.flowpowered.math.vector.Vector3i)2 CodecException (io.netty.handler.codec.CodecException)2 LanternPotionEffectType (org.lanternpowered.server.effect.potion.LanternPotionEffectType)2 LanternPlayer (org.lanternpowered.server.entity.living.player.LanternPlayer)2 NetworkSession (org.lanternpowered.server.network.NetworkSession)2 LanternByteBuffer (org.lanternpowered.server.network.buffer.LanternByteBuffer)2 BulkMessage (org.lanternpowered.server.network.message.BulkMessage)2 CodecRegistration (org.lanternpowered.server.network.message.CodecRegistration)2 HandlerMessage (org.lanternpowered.server.network.message.HandlerMessage)2 Codec (org.lanternpowered.server.network.message.codec.Codec)2 RawItemStack (org.lanternpowered.server.network.objects.RawItemStack)2