Package net.glowstone.net.codec.play.game

Source Code of net.glowstone.net.codec.play.game.ChatCodec

package net.glowstone.net.codec.play.game;

import com.flowpowered.networking.Codec;
import io.netty.buffer.ByteBuf;
import net.glowstone.net.GlowBufUtils;
import net.glowstone.net.message.play.game.ChatMessage;
import net.glowstone.util.TextMessage;

import java.io.IOException;

public final class ChatCodec implements Codec<ChatMessage> {
    @Override
    public ChatMessage decode(ByteBuf buf) throws IOException {
        TextMessage message = GlowBufUtils.readChat(buf);
        int mode = buf.readByte();
        return new ChatMessage(message, mode);
    }

    @Override
    public ByteBuf encode(ByteBuf buf, ChatMessage message) throws IOException {
        GlowBufUtils.writeChat(buf, message.getText());
        buf.writeByte(message.getMode());
        return buf;
    }
}
TOP

Related Classes of net.glowstone.net.codec.play.game.ChatCodec

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.