Search in sources :

Example 1 with MessagePlayOutSetOpLevel

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

the class CodecPlayOutEntityStatus method encode.

@Override
public ByteBuffer encode(CodecContext context, Message message) throws CodecException {
    final int entityId;
    final int action;
    if (message instanceof MessagePlayOutSetReducedDebug) {
        entityId = context.getChannel().attr(CodecPlayOutPlayerJoinGame.PLAYER_ENTITY_ID).get();
        action = ((MessagePlayOutSetReducedDebug) message).isReduced() ? 22 : 23;
    } else if (message instanceof MessagePlayOutSetOpLevel) {
        entityId = context.getChannel().attr(CodecPlayOutPlayerJoinGame.PLAYER_ENTITY_ID).get();
        action = 24 + Math.max(0, Math.min(4, ((MessagePlayOutSetOpLevel) message).getOpLevel()));
    } else if (message instanceof MessagePlayOutEntityStatus) {
        entityId = ((MessagePlayOutEntityStatus) message).getEntityId();
        action = ((MessagePlayOutEntityStatus) message).getStatus();
    } else if (message instanceof MessagePlayInOutFinishUsingItem) {
        entityId = context.getChannel().attr(CodecPlayOutPlayerJoinGame.PLAYER_ENTITY_ID).get();
        action = 9;
    } else {
        throw new CodecException("Unsupported message type: " + message.getClass().getName());
    }
    return context.byteBufAlloc().buffer(LENGTH).writeInteger(entityId).writeByte((byte) action);
}
Also used : MessagePlayInOutFinishUsingItem(org.lanternpowered.server.network.vanilla.message.type.play.MessagePlayInOutFinishUsingItem) MessagePlayOutEntityStatus(org.lanternpowered.server.network.vanilla.message.type.play.MessagePlayOutEntityStatus) MessagePlayOutSetReducedDebug(org.lanternpowered.server.network.vanilla.message.type.play.MessagePlayOutSetReducedDebug) CodecException(io.netty.handler.codec.CodecException) MessagePlayOutSetOpLevel(org.lanternpowered.server.network.vanilla.message.type.play.MessagePlayOutSetOpLevel)

Aggregations

CodecException (io.netty.handler.codec.CodecException)1 MessagePlayInOutFinishUsingItem (org.lanternpowered.server.network.vanilla.message.type.play.MessagePlayInOutFinishUsingItem)1 MessagePlayOutEntityStatus (org.lanternpowered.server.network.vanilla.message.type.play.MessagePlayOutEntityStatus)1 MessagePlayOutSetOpLevel (org.lanternpowered.server.network.vanilla.message.type.play.MessagePlayOutSetOpLevel)1 MessagePlayOutSetReducedDebug (org.lanternpowered.server.network.vanilla.message.type.play.MessagePlayOutSetReducedDebug)1