Search in sources :

Example 1 with BossBarMessage

use of net.glowstone.net.message.play.player.BossBarMessage in project Glowstone by GlowstoneMC.

the class BossBarCodec method decode.

@Override
public BossBarMessage decode(ByteBuf buffer) throws IOException {
    UUID uuid = GlowBufUtils.readUuid(buffer);
    Action action = Action.fromInt(ByteBufUtils.readVarInt(buffer));
    switch(action) {
        case ADD:
            TextMessage title = GlowBufUtils.readChat(buffer);
            float health = buffer.readFloat();
            Color color = Color.fromInt(ByteBufUtils.readVarInt(buffer));
            Division division = Division.fromInt(ByteBufUtils.readVarInt(buffer));
            byte flags = buffer.readByte();
            return new BossBarMessage(uuid, action, title, health, color, division, flags);
        case REMOVE:
            return new BossBarMessage(uuid, action);
        case UPDATE_HEALTH:
            health = buffer.readFloat();
            return new BossBarMessage(uuid, action, health);
        case UPDATE_TITLE:
            title = GlowBufUtils.readChat(buffer);
            return new BossBarMessage(uuid, action, title);
        case UPDATE_STYLE:
            color = Color.fromInt(ByteBufUtils.readVarInt(buffer));
            division = Division.fromInt(ByteBufUtils.readVarInt(buffer));
            return new BossBarMessage(uuid, action, color, division);
        case UPDATE_FLAGS:
            flags = buffer.readByte();
            return new BossBarMessage(uuid, action, flags);
    }
    //INFO: This return is dead code. We would NPE before on the action line.
    return null;
}
Also used : Action(net.glowstone.net.message.play.player.BossBarMessage.Action) Color(net.glowstone.net.message.play.player.BossBarMessage.Color) Division(net.glowstone.net.message.play.player.BossBarMessage.Division) UUID(java.util.UUID) TextMessage(net.glowstone.util.TextMessage) BossBarMessage(net.glowstone.net.message.play.player.BossBarMessage)

Aggregations

UUID (java.util.UUID)1 BossBarMessage (net.glowstone.net.message.play.player.BossBarMessage)1 Action (net.glowstone.net.message.play.player.BossBarMessage.Action)1 Color (net.glowstone.net.message.play.player.BossBarMessage.Color)1 Division (net.glowstone.net.message.play.player.BossBarMessage.Division)1 TextMessage (net.glowstone.util.TextMessage)1