package common.packet;

import java.io.IOException;

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

public class SPacketDimensionName implements Packet<IClientPlayer> {
	private String fullName;
	private String customName;

	public SPacketDimensionName() {
	}

	public SPacketDimensionName(Dimension dim) {
		this.fullName = dim.getFormattedName(true);
		this.customName = dim.getCustomName() != null && dim.getCustomName().length() > 64 ? dim.getCustomName().substring(0, 64) : 
			dim.getCustomName();
	}

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

	public void readPacketData(PacketBuffer buf) throws IOException {
		this.fullName = buf.readStringFromBuffer(64);
		this.customName = buf.readStringFromBuffer(64);
		this.customName = this.customName.isEmpty() ? null : this.customName;
	}

	public void writePacketData(PacketBuffer buf) throws IOException {
		buf.writeString(this.fullName);
		buf.writeString(this.customName == null ? "" : this.customName);
	}

	public String getFullName() {
		return this.fullName;
	}

	public String getCustomName() {
		return this.customName;
	}
}
