package common.packet;

import java.io.IOException;

import common.network.IClientPlayer;
import common.network.Packet;
import common.network.PacketBuffer;

public class SPacketMessage implements Packet<IClientPlayer> {
	public static enum Type {
		CONSOLE, CHAT, FEED, HOTBAR;
	}
	
	private String message;
	private Type type;

	public SPacketMessage() {
	}

	public SPacketMessage(String message, Type type) {
		this.message = message;
		this.type = type;
	}

	public void readPacketData(PacketBuffer buf) throws IOException {
		this.message = buf.readString(32767);
		this.type = buf.readEnumValue(Type.class);
	}

	public void writePacketData(PacketBuffer buf) throws IOException {
		buf.writeString(this.message);
		buf.writeEnumValue(this.type);
	}

	public void processPacket(IClientPlayer handler) {
		handler.handleMessage(this);
	}

	public String getMessage() {
		return this.message;
	}

	public Type getType() {
		return this.type;
	}
}
