package common.dimension;

import common.nbt.NBTTagCompound;

public abstract class Nameable {
	protected String customName = null;
	
	public final String getCustomName() {
		return this.customName;
	}

	public final void setCustomName(String name) {
		this.customName = name;
	}
	
	public void readNbt(NBTTagCompound tag) {
    	this.customName = tag.hasKey("CustomName", 8) ? tag.getString("CustomName") : null;
    }
    
	public void writeNbt(NBTTagCompound tag) {
    	if(this.customName != null)
    		tag.setString("CustomName", this.customName);
    }
	
	protected abstract String getNameIdentifier();
	protected abstract String getIdentifier();
	
	public final String getNameString() {
		return this.customName != null && !this.customName.isEmpty() 
				? (this.customName.startsWith("'") && this.customName.endsWith("'") && this.customName.length() > 2
				? this.customName.substring(1, this.customName.length() - 1) : 
				String.format(this.getNameIdentifier(), this.customName)) : 
				String.format(this.getNameIdentifier(), this.getIdentifier());
	}
	
//	public final Text getNameComponent() {
//		return this.customName != null && !this.customName.isEmpty() 
//				? (this.customName.startsWith("'") && this.customName.endsWith("'") && this.customName.length() > 2
//				? new Text(this.customName.substring(1, this.customName.length() - 1)) : 
//				new Text(this.getNameIdentifier(), this.customName)) : 
//				new Text(this.getNameIdentifier(), this.getIdentifier());
//	}
}
