package common.packet;

import java.io.IOException;

import common.network.IPlayer;
import common.network.Packet;
import common.network.PacketBuffer;
import common.util.BlockPos;

public class CPacketSign implements Packet<IPlayer>
{
    private BlockPos pos;
    private String[] lines;

    public CPacketSign()
    {
    }

    public CPacketSign(BlockPos pos, String[] lines)
    {
        this.pos = pos;
        this.lines = new String[] {
        		lines[0].length() > 50 ? lines[0].substring(0, 50) : lines[0], 
        		lines[1].length() > 50 ? lines[1].substring(0, 50) : lines[1], 
        		lines[2].length() > 50 ? lines[2].substring(0, 50) : lines[2], 
        		lines[3].length() > 50 ? lines[3].substring(0, 50) : lines[3]
        };
    }
    
    public void readPacketData(PacketBuffer buf) throws IOException
    {
        this.pos = buf.readBlockPos();
        this.lines = new String[4];

        for (int i = 0; i < 4; ++i)
        {
            this.lines[i] = buf.readStringFromBuffer(50);
        }
    }
    
    public void writePacketData(PacketBuffer buf) throws IOException
    {
        buf.writeBlockPos(this.pos);

        for (int i = 0; i < 4; ++i)
        {
            buf.writeString(this.lines[i]);
        }
    }
    
    public void processPacket(IPlayer handler)
    {
        handler.processSign(this);
    }

    public BlockPos getPosition()
    {
        return this.pos;
    }

    public String[] getLines()
    {
        return this.lines;
    }
}
