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

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

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.UpdateSignMessage;
import net.glowstone.util.TextMessage;
import org.bukkit.util.BlockVector;

import java.io.IOException;

public final class UpdateSignCodec implements Codec<UpdateSignMessage> {
    @Override
    public UpdateSignMessage decode(ByteBuf buf) throws IOException {
        BlockVector pos = GlowBufUtils.readBlockPosition(buf);
        TextMessage[] message = new TextMessage[4];
        for (int i = 0; i < message.length; ++i) {
            message[i] = GlowBufUtils.readChat(buf);
        }
        return new UpdateSignMessage(pos.getBlockX(), pos.getBlockY(), pos.getBlockZ(), message);
    }

    @Override
    public ByteBuf encode(ByteBuf buf, UpdateSignMessage message) throws IOException {
        GlowBufUtils.writeBlockPosition(buf, message.getX(), message.getY(), message.getZ());
        for (TextMessage line : message.getMessage()) {
            GlowBufUtils.writeChat(buf, line);
        }
        return buf;
    }
}
TOP

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

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.