package com.github.to2mbn.to2nbt;

import java.io.DataInput;
import java.io.DataOutput;
import java.io.IOException;
import org.json.JSONObject;

abstract public class NBT implements Cloneable {

	protected static NBT createNewByType(byte id) {
		switch (id) {
			case NBTByte.ID:
				return new NBTByte();

			case NBTShort.ID:
				return new NBTShort();

			case NBTInt.ID:
				return new NBTInt();

			case NBTLong.ID:
				return new NBTLong();

			case NBTFloat.ID:
				return new NBTFloat();

			case NBTDouble.ID:
				return new NBTDouble();

			case NBTByteArray.ID:
				return new NBTByteArray();

			case NBTString.ID:
				return new NBTString();

			case NBTList.ID:
				return new NBTList();

			case NBTCompound.ID:
				return new NBTCompound();

			case NBTIntArray.ID:
				return new NBTIntArray();

			default:
				return null;
		}
	}

	@Override
	abstract public NBT clone();

	abstract protected byte getId();

	abstract protected void write(DataOutput out) throws IOException;

	abstract protected void read(DataInput in) throws IOException;

	abstract public Object unwrap();

	@Override
	public String toString() {
		return new JSONObject(unwrap()).toString();
	}

	@Override
	public boolean equals(Object another) {
		if (!(another instanceof NBT)) {
			return false;
		}
		return getId() == ((NBT) another).getId();
	}

	@Override
	public int hashCode() {
		return getId();
	}

}

@@ -109,16 +109,117 @@
 eption;%0A
+import java.util.Collection;%0Aimport java.util.List;%0Aimport java.util.Map;%0Aimport org.json.JSONArray;%0A
 import o
@@ -1234,51 +1234,402 @@
 %7B%0A%09%09
-return new JSONObject(unwrap()).toString();
+Object unwrapped = unwrap();%0A%09%09if (unwrapped instanceof Map) %7B%0A%09%09%09return new JSONObject((Map%3C?, ?%3E) unwrapped).toString();%0A%09%09%7D else if (unwrapped instanceof Collection) %7B%0A%09%09%09return new JSONArray((List%3C?%3E) unwrapped).toString();%0A%09%09%7D else if (unwrapped.getClass().isArray()) %7B%0A%09%09%09return new JSONArray((List%3C?%3E) unwrapped).toString();%0A%09%09%7D else %7B%0A%09%09%09return new JSONObject(unwrapped).toString();%0A%09%09%7D
 %0A%09%7D%0A

fix toString()