Search in sources :

Example 1 with MessagePlayOutBossBar

use of org.lanternpowered.server.network.vanilla.message.type.play.MessagePlayOutBossBar in project LanternServer by LanternPowered.

the class CodecPlayOutBossBar method encode.

@Override
public ByteBuffer encode(CodecContext context, MessagePlayOutBossBar message) throws CodecException {
    ByteBuffer buf = context.byteBufAlloc().buffer();
    buf.writeUniqueId(message.getUniqueId());
    if (message instanceof MessagePlayOutBossBar.Add) {
        MessagePlayOutBossBar.Add message0 = (MessagePlayOutBossBar.Add) message;
        buf.writeVarInt(0);
        buf.write(Types.LOCALIZED_TEXT, message0.getTitle());
        buf.writeFloat(message0.getHealth());
        buf.writeVarInt(((LanternBossBarColor) message0.getColor()).getInternalId());
        buf.writeVarInt(((LanternBossBarOverlay) message0.getOverlay()).getInternalId());
        buf.writeByte(toFlags(message0.isDarkenSky(), message0.isEndMusic()));
    } else if (message instanceof MessagePlayOutBossBar.Remove) {
        buf.writeVarInt(1);
    } else if (message instanceof MessagePlayOutBossBar.UpdatePercent) {
        buf.writeVarInt(2);
        buf.writeFloat(((MessagePlayOutBossBar.UpdatePercent) message).getPercent());
    } else if (message instanceof MessagePlayOutBossBar.UpdateTitle) {
        buf.writeVarInt(3);
        buf.write(Types.LOCALIZED_TEXT, ((MessagePlayOutBossBar.UpdateTitle) message).getTitle());
    } else if (message instanceof MessagePlayOutBossBar.UpdateStyle) {
        MessagePlayOutBossBar.UpdateStyle message0 = (MessagePlayOutBossBar.UpdateStyle) message;
        buf.writeVarInt(4);
        buf.writeVarInt(((LanternBossBarColor) message0.getColor()).getInternalId());
        buf.writeVarInt(((LanternBossBarOverlay) message0.getOverlay()).getInternalId());
    } else if (message instanceof MessagePlayOutBossBar.UpdateMisc) {
        MessagePlayOutBossBar.UpdateMisc message0 = (MessagePlayOutBossBar.UpdateMisc) message;
        buf.writeVarInt(5);
        buf.writeByte(toFlags(message0.isDarkenSky(), message0.isEndMusic()));
    } else {
        throw new EncoderException("Unsupported message type: " + message.getClass().getName());
    }
    return buf;
}
Also used : MessagePlayOutBossBar(org.lanternpowered.server.network.vanilla.message.type.play.MessagePlayOutBossBar) ByteBuffer(org.lanternpowered.server.network.buffer.ByteBuffer) EncoderException(io.netty.handler.codec.EncoderException)

Aggregations

EncoderException (io.netty.handler.codec.EncoderException)1 ByteBuffer (org.lanternpowered.server.network.buffer.ByteBuffer)1 MessagePlayOutBossBar (org.lanternpowered.server.network.vanilla.message.type.play.MessagePlayOutBossBar)1