Create my own file format

This commit is contained in:
Aria 2023-04-13 21:45:00 -07:00
parent 55dcf92fe7
commit 5ebe6eb78a
29 changed files with 558 additions and 2725 deletions

View file

@ -1,17 +0,0 @@
package dev.zontreck.ariaslib.events;
public class NBTLoadFailedEvent extends Event
{
public String fileName;
@Override
public boolean isCancellable() {
return false;
}
public NBTLoadFailedEvent(String fileName)
{
this.fileName=fileName;
}
}

View file

@ -1,24 +0,0 @@
package dev.zontreck.ariaslib.events;
import dev.zontreck.ariaslib.nbt.old.CompoundTag;
/**
* This event cannot be cancelled.
*/
public class NBTLoadedEvent extends Event
{
public CompoundTag loadedTag;
public String fileName;
@Override
public boolean isCancellable() {
return false;
}
public NBTLoadedEvent(CompoundTag tag, String fileName)
{
loadedTag=tag;
this.fileName = fileName;
}
}

View file

@ -1,24 +0,0 @@
package dev.zontreck.ariaslib.events;
import dev.zontreck.ariaslib.nbt.old.CompoundTag;
/**
* This event is cancellable. Cancelling this event will result in the saving process being interrupted, and the tag to be saved, replaced right before saving completes
*/
public class NBTSavingEvent extends Event
{
public CompoundTag tag;
public String file;
@Override
public boolean isCancellable() {
return true;
}
public NBTSavingEvent(CompoundTag current, String fileName)
{
tag=current;
file=fileName;
}
}

View file

@ -0,0 +1,36 @@
package dev.zontreck.ariaslib.file;
import java.io.*;
import java.nio.file.Path;
public class AriaIO
{
public static void write(Path fileName, Entry folder)
{
try {
DataOutputStream dos = new DataOutputStream(new FileOutputStream(fileName.toFile()));
folder.write(dos);
dos.close();
} catch (FileNotFoundException e) {
throw new RuntimeException(e);
} catch (IOException e) {
throw new RuntimeException(e);
}
}
public static Entry read(Path fileName)
{
try {
DataInputStream dis = new DataInputStream(new FileInputStream(fileName.toFile()));
return Entry.read(dis);
} catch (FileNotFoundException e) {
throw new RuntimeException(e);
} catch (IOException e) {
throw new RuntimeException(e);
}
}
public static Path resolveDataFile(String main) {
return Path.of(main+".aria");
}
}

View file

@ -0,0 +1,326 @@
package dev.zontreck.ariaslib.file;
import dev.zontreck.ariaslib.terminal.Terminal;
import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.IOException;
import java.lang.reflect.Array;
import java.util.ArrayList;
import java.util.List;
/**
* An entry in the serialized file
*/
public class Entry<K>
{
public static final byte YES = 1;
public static final byte NO = 0;
public EntryType type;
public String name;
public K value;
public Entry(K v, String name)
{
value=v;
this.name=name;
if(v instanceof String) {
type = EntryType.STRING;
}else if(v instanceof Integer)
{
type=EntryType.INT;
} else if(v instanceof List<?>)
{
type = EntryType.FOLDER;
} else if(v instanceof Boolean)
{
type = EntryType.BOOL;
} else if(v instanceof Long)
{
type = EntryType.LONG;
}else if(v instanceof Short)
{
type = EntryType.SHORT;
}else if(v instanceof Byte)
{
type = EntryType.BYTE;
}else if(v instanceof Double)
{
type = EntryType.DOUBLE;
}else if(v instanceof Float)
{
type = EntryType.FLOAT;
}else if(v instanceof int[]){
type = EntryType.INT_ARRAY;
}else if(v instanceof String[])
{
type = EntryType.STRING_ARRAY;
}else if(v instanceof byte[])
{
type = EntryType.BYTE_ARRAY;
}else if(v instanceof long[])
{
type = EntryType.LONG_ARRAY;
}
else{
type = EntryType.INVALID;
}
}
private Entry(){}
public void write(DataOutputStream dos) throws IOException {
dos.writeByte((int)type.value);
byte[] nameBytes = name.getBytes();
dos.writeInt(nameBytes.length);
dos.write(nameBytes);
switch(type)
{
case FOLDER:
{
List<Entry<?>> entries = (List<Entry<?>>) value;
dos.writeInt(entries.size());
for (Entry<?> x:
entries) {
x.write(dos);
}
break;
}
case STRING:
{
String s = (String)value;
byte[] bS = s.getBytes();
dos.writeInt(bS.length);
dos.write(bS);
break;
}
case INT:
{
dos.writeInt((int)value);
break;
}
case BOOL:
{
boolean X = (boolean)value;
if(X) dos.writeByte(YES);
else dos.writeByte(NO);
break;
}
case LONG:
{
long lng = (long)value;
dos.writeLong(lng);
break;
}
case SHORT:
{
short s = (short)value;
dos.writeShort(s);
break;
}
case BYTE:
{
dos.write((byte)value);
break;
}
case DOUBLE:
{
dos.writeDouble((double)value);
break;
}
case FLOAT:
{
dos.writeFloat((float)value);
break;
}
case INT_ARRAY:
{
int[] arr = (int[])value;
dos.writeInt(arr.length);
for (int x: arr
) {
dos.writeInt(x);
}
break;
}
case STRING_ARRAY:
{
String[] arr = (String[]) value;
dos.writeInt(arr.length);
for(String s : arr)
{
byte[] bArr = s.getBytes();
dos.writeInt(bArr.length);
dos.write(bArr);
}
break;
}
case BYTE_ARRAY:
{
byte[] arr = (byte[])value;
dos.writeInt(arr.length);
for(byte b : arr)
{
dos.write(b);
}
break;
}
case LONG_ARRAY:
{
long[] arr = (long[]) value;
dos.writeInt(arr.length);
for(long L : arr)
{
dos.writeLong(L);
}
break;
}
}
}
public static Entry read(DataInputStream dis) throws IOException {
EntryType et = EntryType.of(dis.readByte());
int nameLen = dis.readInt();
byte[] nm = dis.readNBytes(nameLen);
Entry work = new Entry<>();
work.type = et;
work.name = new String(nm);
System.out.println("Read start: " + work.name + " [ " + work.type.toString() + " ]");
switch(et)
{
case FOLDER:
{
Entry<List<Entry>> entries = (Entry<List<Entry>>) work;
entries.value = new ArrayList<>();
int numEntries = dis.readInt();
for(int i = 0; i<numEntries; i++)
{
entries.value.add(Entry.read(dis));
}
break;
}
case STRING:
{
Entry<String> w = (Entry<String>) work;
int vLen = dis.readInt();
w.value = new String(dis.readNBytes(vLen));
break;
}
case INT:
{
Entry<Integer> w = (Entry<Integer>) work;
w.value = dis.readInt();
break;
}
case BOOL:
{
Entry<Boolean> w = (Entry<Boolean>) work;
byte b = dis.readByte();
if(b == YES)w.value = true;
else w.value=false;
break;
}
case LONG:
{
Entry<Long> w = (Entry<Long>) work;
w.value = dis.readLong();
break;
}
case SHORT:
{
Entry<Short> w = (Entry<Short>) work;
w.value = dis.readShort();
break;
}
case BYTE:
{
Entry<Byte> w = (Entry<Byte>) work;
w.value = dis.readByte();
break;
}
case DOUBLE:
{
Entry<Double> w = (Entry<Double>) work;
w.value = dis.readDouble();
break;
}
case FLOAT:
{
Entry<Float> w = (Entry<Float>) work;
w.value = dis.readFloat();
break;
}
case INT_ARRAY:
{
Entry<int[]> w = (Entry<int[]>) work;
int num = dis.readInt();
w.value = new int[num];
for(int i=0;i<num;i++)
{
w.value[i] = dis.readInt();
}
break;
}
case STRING_ARRAY:
{
Entry<String[]> w = (Entry<String[]>) work;
int num = dis.readInt();
w.value = new String[num];
for(int i=0;i<num;i++)
{
int len = dis.readInt();
byte[] bStr = dis.readNBytes(len);
w.value[i] = new String(bStr);
}
break;
}
case BYTE_ARRAY:
{
Entry<byte[]> w = (Entry<byte[]>) work;
int num = dis.readInt();
w.value = new byte[num];
for(int i=0;i<num;i++)
{
w.value[i] = dis.readByte();
}
break;
}
case LONG_ARRAY:
{
Entry<long[]> w = (Entry<long[]>) work;
int num = dis.readInt();
w.value = new long[num];
for(int i=0;i<num;i++)
{
w.value[i] = dis.readLong();
}
break;
}
}
System.out.println("Read finished: " + work.name + " [ " + work.type.toString() + " ]");
return work;
}
}

View file

@ -0,0 +1,36 @@
package dev.zontreck.ariaslib.file;
import java.util.Arrays;
import java.util.stream.Collectors;
public enum EntryType {
FOLDER(0),
STRING(1),
INT(2),
BOOL(3),
LONG(4),
SHORT(5),
BYTE(6),
DOUBLE(7),
FLOAT(8),
INT_ARRAY(9),
STRING_ARRAY(10),
BYTE_ARRAY(11),
LONG_ARRAY(12),
INVALID(255);
public byte value;
EntryType(int v)
{
value = (byte)v;
}
public static EntryType of(byte b)
{
return Arrays.stream(values())
.filter(c->c.value == b)
.collect(Collectors.toList())
.get(0);
}
}

View file

@ -0,0 +1,118 @@
package dev.zontreck.ariaslib.file;
import java.util.UUID;
public class EntryUtils {
public static Entry mkStr(String name, String value)
{
return new Entry<String>(value, name);
}
public static String getStr(Entry e)
{
Entry<String> eS = (Entry<String>) e;
return eS.value;
}
public static Entry mkInt(String name, int value)
{
return new Entry<Integer>(value, name);
}
public static int getInt(Entry e)
{
Entry<Integer> eS = (Entry<Integer>) e;
return eS.value;
}
public static Entry mkBool(String name, boolean value)
{
return new Entry<Boolean>(value, name);
}
public static boolean getBool(Entry e)
{
Entry<Boolean> eS = (Entry<Boolean>) e;
return eS.value;
}
public static Entry mkLong(String name, long value)
{
return new Entry<Long>(value, name);
}
public static long getLong(Entry e)
{
Entry<Long> eS = (Entry<Long>) e;
return eS.value;
}
public static Entry mkShort(String name, short value)
{
return new Entry<Short>(value, name);
}
public static short getShort(Entry e)
{
Entry<Short> eS = (Entry<Short>) e;
return eS.value;
}
public static Entry mkByte(String name, byte value)
{
return new Entry<Byte>(value, name);
}
public static byte getByte(Entry e)
{
Entry<Byte> eS = (Entry<Byte>) e;
return eS.value;
}
public static Entry mkDouble(String name, double value)
{
return new Entry<Double>(value, name);
}
public static double getDouble(Entry e)
{
Entry<Double> eS = (Entry<Double>) e;
return eS.value;
}
public static Entry mkFloat(String name, float value)
{
return new Entry<Float>(value, name);
}
public static float getFloat(Entry e)
{
Entry<Float> eS = (Entry<Float>) e;
return eS.value;
}
public static Entry mkIntArray(String name, int[] value)
{
return new Entry<int[]>(value, name);
}
public static int[] getIntArray(Entry e)
{
Entry<int[]> eS = (Entry<int[]>) e;
return eS.value;
}
public static Entry mkStringArray(String name, String[] value)
{
return new Entry<String[]>(value, name);
}
public static String[] getStringArray(Entry e)
{
Entry<String[]> eS = (Entry<String[]>) e;
return eS.value;
}
public static Entry mkByteArray(String name, byte[] value)
{
return new Entry<byte[]>(value, name);
}
public static byte[] getByteArray(Entry e)
{
Entry<byte[]> eS = (Entry<byte[]>) e;
return eS.value;
}
public static Entry mkUUID(String name, UUID ID)
{
long[] uid = new long[2];
uid[0] = ID.getLeastSignificantBits();
uid[1] = ID.getMostSignificantBits();
return new Entry<long[]>(uid, name);
}
public static UUID getUUID(Entry e)
{
Entry<long[]> uid = (Entry<long[]>) e;
return new UUID(uid.value[1], uid.value[0]);
}
}

View file

@ -0,0 +1,42 @@
package dev.zontreck.ariaslib.file;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
public class Folder
{
public static void add(Entry e, Entry item)
{
((Entry<List<Entry>>)e).value.add(item);
}
public static void remove(Entry e, Entry item)
{
((Entry<List<Entry>>)e).value.remove(item);
}
public static Entry getEntry(Entry item, String name)
{
List<Entry> ret = ((Entry<List<Entry>>)item).value;
if(ret.size()>0)
{
for (Entry ent :
ret) {
if(ent.name.equals(name))return ent;
}
}
return null;
}
public static int size(Entry e)
{
return ((Entry<List<Entry>>)e).value.size();
}
public static Entry<List<Entry>> getNew(String name)
{
return new Entry<>(new ArrayList<Entry>(), name);
}
}

View file

@ -1,9 +0,0 @@
package dev.zontreck.ariaslib.nbt.current;
public abstract class Tag implements Cloneable, Comparable<Tag>
{
public Tag parent;
public abstract TagType Type;
public boolean hasValue;
}

View file

@ -1,51 +0,0 @@
package dev.zontreck.ariaslib.nbt.current;
import dev.zontreck.ariaslib.nbt.old.EndTag;
import dev.zontreck.ariaslib.nbt.old.Tag;
import java.io.DataInput;
import java.io.IOException;
public interface TagType<T extends Tag>
{
T load(DataInput input) throws IOException;
void skip(DataInput input) throws IOException;
boolean hasValue();
String getName();
String getPrettyName();
static TagType<EndTag> invalid(int num)
{
return new TagType<EndTag>() {
@Override
public EndTag load(DataInput input) throws IOException {
throw new IOException("Invalid operation, this tag is invalid");
}
@Override
public void skip(DataInput input) throws IOException {
}
@Override
public String getName() {
return "INVALID";
}
@Override
public String getPrettyName() {
return "TAG_INVALID";
}
@Override
public boolean hasValue() {
return false;
}
};
}
}

View file

@ -1,42 +0,0 @@
package dev.zontreck.ariaslib.nbt.current;
import dev.zontreck.ariaslib.nbt.old.TagType;
import dev.zontreck.ariaslib.nbt.old.*;
public enum TagTypes {
End(EndTag.TYPE), // 0
Byte(ByteTag.TYPE), // 1
Short(ShortTag.TYPE), // 2
Int(IntTag.TYPE), // 3
Long(LongTag.TYPE), // 4
Float(FloatTag.TYPE), // 5
Double(DoubleTag.TYPE), // 6
ByteArray(ByteArrayTag.TYPE), // 7
String(StringTag.TYPE), // 8
List(ListTag.TYPE), // 9
Compound(CompoundTag.TYPE), // 10
IntArray(IntArrayTag.TYPE), // 11
LongArray(LongArrayTag.TYPE); // 12
//public static final TagType<?>[] TYPES = new TagType[]{EndTag.TYPE, ByteTag.TYPE};
public dev.zontreck.ariaslib.nbt.old.TagType<?> type;
/**
* Locates the type in this enum
* @param value
* @return A TagType for the requested value
*/
public static dev.zontreck.ariaslib.nbt.old.TagType<?> getType(int value)
{
if(value>values().length)
{
return End.type;
}else {
return values()[value].type;
}
}
TagTypes(TagType<?> type)
{
this.type=type;
}
}

View file

@ -1,198 +0,0 @@
package dev.zontreck.ariaslib.nbt.old;
import java.io.DataInput;
import java.io.DataOutput;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
public class ByteArrayTag implements Tag
{
public static final TagType<ByteArrayTag> TYPE = new TagType<ByteArrayTag>() {
@Override
public ByteArrayTag load(DataInput input) throws IOException {
List<Byte> lst = new ArrayList<>();
int count = input.readInt();
while(count>0)
{
lst.add(input.readByte());
count--;
}
return new ByteArrayTag(toArray(lst));
}
@Override
public void skip(DataInput input) throws IOException {
load(input);
}
@Override
public boolean hasValue() {
return true;
}
@Override
public String getName() {
return "Byte_Array";
}
@Override
public String getPrettyName() {
return "TAG_Byte_Array";
}
};
@Override
public void write(DataOutput output) throws IOException {
output.writeInt(value.length);
for (byte b : value) {
output.writeByte(b);
}
}
@Override
public int getId() {
return TAG_BYTE_ARRAY;
}
@Override
public TagType<?> getType() {
return TYPE;
}
@Override
public Tag copy() {
return new ByteArrayTag(value);
}
@Override
public String toString()
{
return String.valueOf(value);
}
@Override
public String getAsString(int indents) {
String indent = makeIndent(indents);
String indentInside = makeIndent(indents+1);
String ret = "\n" + indent + "[\n";
for (int i = 0; i< value.length; i++)
{
byte b = value[i];
ret += indentInside+String.valueOf(b);
if((i+1) != value.length)
{
ret += ", ";
}
ret+="\n";
}
ret += indent+"]";
return ret;
}
private ByteArrayTag(byte[] value)
{
this.value=value;
}
private static byte[] toArray(List<Byte> entries)
{
byte[] ret = new byte[entries.size()];
int cur=0;
for(byte b : entries)
{
ret[cur] = b;
cur++;
}
return ret;
}
public static ByteArrayTag valueOf(byte[] b)
{
return new ByteArrayTag(b);
}
private byte[] value;
@Override
public Byte asByte() {
// TODO Auto-generated method stub
throw new UnsupportedOperationException("Unimplemented method 'asByte'");
}
@Override
public Float asFloat() {
// TODO Auto-generated method stub
throw new UnsupportedOperationException("Unimplemented method 'asFloat'");
}
@Override
public String asString() {
// TODO Auto-generated method stub
throw new UnsupportedOperationException("Unimplemented method 'asString'");
}
@Override
public Integer asInt() {
// TODO Auto-generated method stub
throw new UnsupportedOperationException("Unimplemented method 'asInt'");
}
@Override
public Short asShort() {
// TODO Auto-generated method stub
throw new UnsupportedOperationException("Unimplemented method 'asShort'");
}
@Override
public Long asLong() {
// TODO Auto-generated method stub
throw new UnsupportedOperationException("Unimplemented method 'asLong'");
}
@Override
public Double asDouble() {
// TODO Auto-generated method stub
throw new UnsupportedOperationException("Unimplemented method 'asDouble'");
}
@Override
public byte[] asByteArray() {
return value;
}
@Override
public int[] asIntArray() {
// TODO Auto-generated method stub
throw new UnsupportedOperationException("Unimplemented method 'asIntArray'");
}
@Override
public long[] asLongArray() {
// TODO Auto-generated method stub
throw new UnsupportedOperationException("Unimplemented method 'asLongArray'");
}
public Tag parent;
@Override
public void setParent(Tag parent) {
this.parent=parent;
}
@Override
public Tag getParent() {
return parent;
}
}

View file

@ -1,152 +0,0 @@
package dev.zontreck.ariaslib.nbt.old;
import java.io.DataInput;
import java.io.DataOutput;
import java.io.IOException;
public class ByteTag implements Tag
{
public static final TagType<ByteTag> TYPE = new TagType<ByteTag>() {
@Override
public ByteTag load(DataInput input) throws IOException {
return ByteTag.valueOf(input.readByte());
}
@Override
public void skip(DataInput input) throws IOException {
input.skipBytes(1);
}
@Override
public boolean hasValue() {
return true;
}
@Override
public String getName() {
return "Byte";
}
@Override
public String getPrettyName() {
return "TAG_Byte";
}
};
@Override
public void write(DataOutput output) throws IOException {
output.writeByte(value);
}
@Override
public int getId() {
return TAG_BYTE;
}
@Override
public TagType<?> getType() {
return TYPE;
}
@Override
public Tag copy() {
return new ByteTag(value);
}
@Override
public String toString()
{
return String.valueOf(value);
}
@Override
public String getAsString(int indents) {
String val = String.valueOf(value);
val+="b";
return val;
}
private ByteTag(byte value)
{
this.value=value;
}
public static ByteTag valueOf(byte b)
{
return new ByteTag(b);
}
private byte value;
@Override
public Byte asByte() {
return value;
}
@Override
public Float asFloat() {
// TODO Auto-generated method stub
throw new UnsupportedOperationException("Unimplemented method 'asFloat'");
}
@Override
public String asString() {
// TODO Auto-generated method stub
throw new UnsupportedOperationException("Unimplemented method 'asString'");
}
@Override
public Integer asInt() {
// TODO Auto-generated method stub
throw new UnsupportedOperationException("Unimplemented method 'asInt'");
}
@Override
public Short asShort() {
// TODO Auto-generated method stub
throw new UnsupportedOperationException("Unimplemented method 'asShort'");
}
@Override
public Long asLong() {
// TODO Auto-generated method stub
throw new UnsupportedOperationException("Unimplemented method 'asLong'");
}
@Override
public Double asDouble() {
// TODO Auto-generated method stub
throw new UnsupportedOperationException("Unimplemented method 'asDouble'");
}
@Override
public byte[] asByteArray() {
// TODO Auto-generated method stub
throw new UnsupportedOperationException("Unimplemented method 'asByteArray'");
}
@Override
public int[] asIntArray() {
// TODO Auto-generated method stub
throw new UnsupportedOperationException("Unimplemented method 'asIntArray'");
}
@Override
public long[] asLongArray() {
// TODO Auto-generated method stub
throw new UnsupportedOperationException("Unimplemented method 'asLongArray'");
}
public Tag parent;
@Override
public void setParent(Tag parent) {
this.parent=parent;
}
@Override
public Tag getParent() {
return parent;
}
}

View file

@ -1,331 +0,0 @@
package dev.zontreck.ariaslib.nbt.old;
import java.io.DataInput;
import java.io.DataOutput;
import java.io.IOException;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import java.util.Map.Entry;
import com.google.common.collect.Maps;
public class CompoundTag implements Tag
{
public static final TagType<CompoundTag> TYPE = new TagType<CompoundTag>() {
@Override
public CompoundTag load(DataInput input) throws IOException {
CompoundTag newTag = new CompoundTag();
byte type;
while((type = input.readByte()) != TAG_END)
{
TagType<?> v = TagTypes.getType(type);
String tagName = input.readUTF();
Tag finalTag = v.load(input);
if(finalTag instanceof CompoundTag){
((CompoundTag)finalTag).setName(tagName);
}
finalTag.setParent(newTag);
newTag.put(tagName, finalTag);
}
return newTag;
}
@Override
public void skip(DataInput input) throws IOException {
load(input);
}
@Override
public String getName() {
return "Compound";
}
@Override
public String getPrettyName() {
return "TAG_Compound";
}
@Override
public boolean hasValue() {
return true;
}
};
@Override
public void write(DataOutput output) throws IOException {
if(parent==null)
{
output.writeUTF(tagName);
}
for (Map.Entry<String,Tag> it : list.entrySet()) {
// We're saving everything now
output.writeByte(it.getValue().getId());
output.writeUTF(it.getKey());
it.getValue().write(output);
}
output.writeByte(TAG_END);
}
public String tagName = "";
public void setName(String name)
{
tagName = name;
}
@Override
public int getId() {
return Tag.TAG_COMPOUND;
}
@Override
public TagType<?> getType() {
return TYPE;
}
@Override
public Tag copy() {
return new CompoundTag(new HashMap<>(list));
}
@Override
public String getAsString(int indents) {
String indent = makeIndent(indents);
String indentInside = makeIndent(indents+1);
String ret = "";
ret = "\n"+indent+getType().getPrettyName()+" ["+tagName+"] {\n";
Iterator<Entry<String,Tag>> entries = list.entrySet().iterator();
while(entries.hasNext())
{
Entry<String,Tag> entry = entries.next();
if(!(entry.getValue() instanceof CompoundTag))
ret += indentInside+entry.getValue().getType().getPrettyName() + " ["+entry.getKey()+"]: ";
ret += entry.getValue().getAsString(indents+1);
if(entries.hasNext())
{
ret+=",";
}
ret += "\n";
}
ret += indent+"}";
return ret;
}
@Override
public String toString()
{
// Return the values of getAsString
return getAsString(0);
}
private Map<String, Tag> list;
public CompoundTag()
{
list = Maps.newHashMap();
}
protected CompoundTag(Map< String, Tag > map)
{
list=map;
}
public void put(String name, Tag entry)
{
entry.setParent(this);
list.put(name, entry);
}
public void putString(String name, String value)
{
put(name, StringTag.valueOf(value));
}
public String getString(String name)
{
return list.get(name).asString();
}
public void putByte(String name, byte value)
{
put(name, ByteTag.valueOf(value));
}
public byte getByte(String name)
{
return list.get(name).asByte();
}
public void putDouble(String name, double value)
{
put(name, DoubleTag.valueOf(value));
}
public double getDouble(String name)
{
return list.get(name).asDouble();
}
public void putFloat(String name, float value)
{
put(name, FloatTag.valueOf(value));
}
public float getFloat(String name)
{
return list.get(name).asFloat();
}
public void putInt(String name, int value)
{
put(name, IntTag.valueOf(value));
}
public int getInt(String name)
{
return list.get(name).asInt();
}
public ListTag getList(String name)
{
return (ListTag)list.get(name);
}
public void putLong(String name, long value)
{
put(name, LongTag.valueOf(value));
}
public long getLong(String name)
{
return list.get(name).asLong();
}
public void putShort(String name, short value)
{
put(name, ShortTag.valueOf(value));
}
public short getShort(String name)
{
return list.get(name).asShort();
}
public void putByteArray(String name, byte[] value)
{
put(name, ByteArrayTag.valueOf(value));
}
public ByteArrayTag getByteArray(String name)
{
return (ByteArrayTag)list.get(name);
}
public void putIntArray(String name, int[] value)
{
put(name, IntArrayTag.valueOf(value));
}
public IntArrayTag getIntArray(String name)
{
return (IntArrayTag)list.get(name);
}
public void putLongArray(String name, long[] value)
{
put(name, LongArrayTag.valueOf(value));
}
public LongArrayTag getLongArray(String name)
{
return (LongArrayTag)list.get(name);
}
public void putCompound(String name, CompoundTag value)
{
put(name, value);
}
public CompoundTag getCompound(String name)
{
return (CompoundTag)list.get(name);
}
public int size()
{
return list.size();
}
public void clear()
{
list.clear();
}
@Override
public Byte asByte() {
throw new UnsupportedOperationException("Unimplemented method 'asByte'");
}
@Override
public Float asFloat() {
throw new UnsupportedOperationException("Unimplemented method 'asFloat'");
}
@Override
public String asString() {
throw new UnsupportedOperationException("Unimplemented method 'asString'");
}
@Override
public Integer asInt() {
// TODO Auto-generated method stub
throw new UnsupportedOperationException("Unimplemented method 'asInt'");
}
@Override
public Short asShort() {
// TODO Auto-generated method stub
throw new UnsupportedOperationException("Unimplemented method 'asShort'");
}
@Override
public Long asLong() {
// TODO Auto-generated method stub
throw new UnsupportedOperationException("Unimplemented method 'asLong'");
}
@Override
public Double asDouble() {
// TODO Auto-generated method stub
throw new UnsupportedOperationException("Unimplemented method 'asDouble'");
}
@Override
public byte[] asByteArray() {
// TODO Auto-generated method stub
throw new UnsupportedOperationException("Unimplemented method 'asByteArray'");
}
@Override
public int[] asIntArray() {
// TODO Auto-generated method stub
throw new UnsupportedOperationException("Unimplemented method 'asIntArray'");
}
@Override
public long[] asLongArray() {
// TODO Auto-generated method stub
throw new UnsupportedOperationException("Unimplemented method 'asLongArray'");
}
public Tag parent=null;
@Override
public void setParent(Tag parent) {
this.parent=parent;
}
@Override
public Tag getParent() {
return parent;
}
}

View file

@ -1,147 +0,0 @@
package dev.zontreck.ariaslib.nbt.old;
import java.io.DataInput;
import java.io.DataOutput;
import java.io.IOException;
public class DoubleTag implements Tag
{
public static final TagType<DoubleTag> TYPE = new TagType<DoubleTag>() {
@Override
public DoubleTag load(DataInput input) throws IOException {
return DoubleTag.valueOf(input.readDouble());
}
@Override
public void skip(DataInput input) throws IOException {
input.readDouble(); // fastest way to skip it is to read but not assign
}
@Override
public boolean hasValue() {
return true;
}
@Override
public String getName() {
return "Double";
}
@Override
public String getPrettyName() {
return "TAG_Double";
}
};
@Override
public void write(DataOutput output) throws IOException {
output.writeDouble(value);
}
@Override
public int getId() {
return TAG_DOUBLE;
}
@Override
public TagType<?> getType() {
return TYPE;
}
@Override
public Tag copy() {
return new DoubleTag(value);
}
@Override
public String getAsString(int indents) {
return String.valueOf(value);
}
private double value;
private DoubleTag(double value)
{
this.value=value;
}
@Override
public String toString()
{
return String.valueOf(value);
}
public static DoubleTag valueOf(double val)
{
return new DoubleTag(val);
}
@Override
public Byte asByte() {
throw new UnsupportedOperationException("Unimplemented method 'asByte'");
}
@Override
public Float asFloat() {
throw new UnsupportedOperationException("Unimplemented method 'asFloat'");
}
@Override
public String asString() {
throw new UnsupportedOperationException("Unimplemented method 'asString'");
}
@Override
public Integer asInt() {
// TODO Auto-generated method stub
throw new UnsupportedOperationException("Unimplemented method 'asInt'");
}
@Override
public Short asShort() {
// TODO Auto-generated method stub
throw new UnsupportedOperationException("Unimplemented method 'asShort'");
}
@Override
public Long asLong() {
// TODO Auto-generated method stub
throw new UnsupportedOperationException("Unimplemented method 'asLong'");
}
@Override
public Double asDouble() {
return value;
}
@Override
public byte[] asByteArray() {
// TODO Auto-generated method stub
throw new UnsupportedOperationException("Unimplemented method 'asByteArray'");
}
@Override
public int[] asIntArray() {
// TODO Auto-generated method stub
throw new UnsupportedOperationException("Unimplemented method 'asIntArray'");
}
@Override
public long[] asLongArray() {
// TODO Auto-generated method stub
throw new UnsupportedOperationException("Unimplemented method 'asLongArray'");
}
public Tag parent;
@Override
public void setParent(Tag parent) {
this.parent=parent;
}
@Override
public Tag getParent() {
return parent;
}
}

View file

@ -1,134 +0,0 @@
package dev.zontreck.ariaslib.nbt.old;
import java.io.DataInput;
import java.io.DataOutput;
import java.io.IOException;
public class EndTag implements Tag
{
public static final EndTag INSTANCE = new EndTag();
public static final TagType<EndTag> TYPE = new TagType<EndTag>() {
@Override
public EndTag load(DataInput input) throws IOException {
return EndTag.INSTANCE;
}
@Override
public void skip(DataInput input) throws IOException {
}
@Override
public String getName() {
return "End";
}
@Override
public String getPrettyName() {
return "TAG_End";
}
@Override
public boolean hasValue() {
return false;
}
};
@Override
public void write(DataOutput output) throws IOException {
// Nothing to write here! We are the end tag
}
@Override
public int getId() {
return Tag.TAG_END;
}
@Override
public TagType<?> getType() {
return TYPE;
}
@Override
public Tag copy() {
return this;
}
@Override
public String getAsString(int indents) {
return "";
}
public EndTag valueOf(Object input) {
return INSTANCE;
}
@Override
public Byte asByte() {
throw new UnsupportedOperationException("Unimplemented method 'asByte'");
}
@Override
public Float asFloat() {
throw new UnsupportedOperationException("Unimplemented method 'asFloat'");
}
@Override
public String asString() {
throw new UnsupportedOperationException("Unimplemented method 'asString'");
}
@Override
public Integer asInt() {
// TODO Auto-generated method stub
throw new UnsupportedOperationException("Unimplemented method 'asInt'");
}
@Override
public Short asShort() {
// TODO Auto-generated method stub
throw new UnsupportedOperationException("Unimplemented method 'asShort'");
}
@Override
public Long asLong() {
// TODO Auto-generated method stub
throw new UnsupportedOperationException("Unimplemented method 'asLong'");
}
@Override
public Double asDouble() {
// TODO Auto-generated method stub
throw new UnsupportedOperationException("Unimplemented method 'asDouble'");
}
@Override
public byte[] asByteArray() {
// TODO Auto-generated method stub
throw new UnsupportedOperationException("Unimplemented method 'asByteArray'");
}
@Override
public int[] asIntArray() {
// TODO Auto-generated method stub
throw new UnsupportedOperationException("Unimplemented method 'asIntArray'");
}
@Override
public long[] asLongArray() {
// TODO Auto-generated method stub
throw new UnsupportedOperationException("Unimplemented method 'asLongArray'");
}
public Tag parent;
@Override
public void setParent(Tag parent) {
this.parent=parent;
}
@Override
public Tag getParent() {
return parent;
}
}

View file

@ -1,147 +0,0 @@
package dev.zontreck.ariaslib.nbt.old;
import java.io.DataInput;
import java.io.DataOutput;
import java.io.IOException;
public class FloatTag implements Tag
{
public static final TagType<FloatTag> TYPE = new TagType<FloatTag>() {
@Override
public FloatTag load(DataInput input) throws IOException {
return FloatTag.valueOf(input.readFloat());
}
@Override
public void skip(DataInput input) throws IOException {
input.readFloat(); // fastest way to skip it is to read but not assign
}
@Override
public boolean hasValue() {
return true;
}
@Override
public String getName() {
return "Float";
}
@Override
public String getPrettyName() {
return "TAG_Float";
}
};
@Override
public void write(DataOutput output) throws IOException {
output.writeFloat(value);
}
@Override
public int getId() {
return TAG_FLOAT;
}
@Override
public TagType<?> getType() {
return TYPE;
}
@Override
public Tag copy() {
return new FloatTag(value);
}
@Override
public String getAsString(int indents) {
return String.valueOf(value) + "f";
}
private Float value;
private FloatTag(Float value)
{
this.value=value;
}
@Override
public String toString()
{
return String.valueOf(value);
}
public static FloatTag valueOf(Float val)
{
return new FloatTag(val);
}
@Override
public Byte asByte() {
throw new UnsupportedOperationException("Unimplemented method 'asByte'");
}
@Override
public Float asFloat() {
return value;
}
@Override
public String asString() {
throw new UnsupportedOperationException("Unimplemented method 'asString'");
}
@Override
public Integer asInt() {
// TODO Auto-generated method stub
throw new UnsupportedOperationException("Unimplemented method 'asInt'");
}
@Override
public Short asShort() {
// TODO Auto-generated method stub
throw new UnsupportedOperationException("Unimplemented method 'asShort'");
}
@Override
public Long asLong() {
// TODO Auto-generated method stub
throw new UnsupportedOperationException("Unimplemented method 'asLong'");
}
@Override
public Double asDouble() {
// TODO Auto-generated method stub
throw new UnsupportedOperationException("Unimplemented method 'asDouble'");
}
@Override
public byte[] asByteArray() {
// TODO Auto-generated method stub
throw new UnsupportedOperationException("Unimplemented method 'asByteArray'");
}
@Override
public int[] asIntArray() {
// TODO Auto-generated method stub
throw new UnsupportedOperationException("Unimplemented method 'asIntArray'");
}
@Override
public long[] asLongArray() {
// TODO Auto-generated method stub
throw new UnsupportedOperationException("Unimplemented method 'asLongArray'");
}
public Tag parent;
@Override
public void setParent(Tag parent) {
this.parent=parent;
}
@Override
public Tag getParent() {
return parent;
}
}

View file

@ -1,193 +0,0 @@
package dev.zontreck.ariaslib.nbt.old;
import java.io.DataInput;
import java.io.DataOutput;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
public class IntArrayTag implements Tag
{
public static final TagType<IntArrayTag> TYPE = new TagType<IntArrayTag>() {
@Override
public IntArrayTag load(DataInput input) throws IOException {
List<Integer> lst = new ArrayList<>();
int count = input.readInt();
while(count>0)
{
lst.add(input.readInt());
count--;
}
return new IntArrayTag(toArray(lst));
}
@Override
public void skip(DataInput input) throws IOException {
load(input);
}
@Override
public boolean hasValue() {
return true;
}
@Override
public String getName() {
return "Int_Array";
}
@Override
public String getPrettyName() {
return "TAG_Int_Array";
}
};
@Override
public void write(DataOutput output) throws IOException {
output.writeInt(value.length);
for (int b : value) {
output.writeInt(b);
}
}
@Override
public int getId() {
return TAG_INT_ARRAY;
}
@Override
public TagType<?> getType() {
return TYPE;
}
@Override
public Tag copy() {
return new IntArrayTag(value);
}
@Override
public String toString()
{
return String.valueOf(value);
}
@Override
public String getAsString(int indents) {
String indent = makeIndent(indents);
String indentInside = makeIndent(indents+1);
String ret = "\n"+indent + "[\n";
for (int i = 0; i< value.length; i++)
{
int b = value[i];
ret += indentInside + String.valueOf(b);
if((i+1) != value.length)
{
ret += ", ";
}
ret += "\n";
}
ret += indent+"]";
return ret;
}
private IntArrayTag(int[] value)
{
this.value=value;
}
private static int[] toArray(List<Integer> entries)
{
int[] ret = new int[entries.size()];
int cur=0;
for(int b : entries)
{
ret[cur] = b;
cur++;
}
return ret;
}
public static IntArrayTag valueOf(int[] b)
{
return new IntArrayTag(b);
}
private int[] value;
@Override
public Byte asByte() {
// TODO Auto-generated method stub
throw new UnsupportedOperationException("Unimplemented method 'asByte'");
}
@Override
public Float asFloat() {
// TODO Auto-generated method stub
throw new UnsupportedOperationException("Unimplemented method 'asFloat'");
}
@Override
public String asString() {
// TODO Auto-generated method stub
throw new UnsupportedOperationException("Unimplemented method 'asString'");
}
@Override
public Integer asInt() {
// TODO Auto-generated method stub
throw new UnsupportedOperationException("Unimplemented method 'asInt'");
}
@Override
public Short asShort() {
// TODO Auto-generated method stub
throw new UnsupportedOperationException("Unimplemented method 'asShort'");
}
@Override
public Long asLong() {
// TODO Auto-generated method stub
throw new UnsupportedOperationException("Unimplemented method 'asLong'");
}
@Override
public Double asDouble() {
// TODO Auto-generated method stub
throw new UnsupportedOperationException("Unimplemented method 'asDouble'");
}
@Override
public byte[] asByteArray() {
// TODO Auto-generated method stub
throw new UnsupportedOperationException("Unimplemented method 'asByteArray'");
}
@Override
public int[] asIntArray() {
return value;
}
@Override
public long[] asLongArray() {
// TODO Auto-generated method stub
throw new UnsupportedOperationException("Unimplemented method 'asLongArray'");
}
public Tag parent;
@Override
public void setParent(Tag parent) {
this.parent=parent;
}
@Override
public Tag getParent() {
return parent;
}
}

View file

@ -1,146 +0,0 @@
package dev.zontreck.ariaslib.nbt.old;
import java.io.DataInput;
import java.io.DataOutput;
import java.io.IOException;
public class IntTag implements Tag
{
public static final TagType<IntTag> TYPE = new TagType<IntTag>() {
@Override
public IntTag load(DataInput input) throws IOException {
return IntTag.valueOf(input.readInt());
}
@Override
public void skip(DataInput input) throws IOException {
input.readInt(); // fastest way to skip it is to read but not assign
}
@Override
public boolean hasValue() {
return true;
}
@Override
public String getName() {
return "Int";
}
@Override
public String getPrettyName() {
return "TAG_Int";
}
};
@Override
public void write(DataOutput output) throws IOException {
output.writeFloat(value);
}
@Override
public int getId() {
return TAG_INT;
}
@Override
public TagType<?> getType() {
return TYPE;
}
@Override
public Tag copy() {
return new IntTag(value);
}
@Override
public String getAsString(int indents) {
return String.valueOf(value);
}
private int value;
private IntTag(int value)
{
this.value=value;
}
@Override
public String toString()
{
return String.valueOf(value);
}
public static IntTag valueOf(int val)
{
return new IntTag(val);
}
@Override
public Byte asByte() {
throw new UnsupportedOperationException("Unimplemented method 'asByte'");
}
@Override
public Float asFloat() {
throw new UnsupportedOperationException("Unimplemented method 'asFloat'");
}
@Override
public String asString() {
throw new UnsupportedOperationException("Unimplemented method 'asString'");
}
@Override
public Integer asInt() {
return value;
}
@Override
public Short asShort() {
// TODO Auto-generated method stub
throw new UnsupportedOperationException("Unimplemented method 'asShort'");
}
@Override
public Long asLong() {
// TODO Auto-generated method stub
throw new UnsupportedOperationException("Unimplemented method 'asLong'");
}
@Override
public Double asDouble() {
// TODO Auto-generated method stub
throw new UnsupportedOperationException("Unimplemented method 'asDouble'");
}
@Override
public byte[] asByteArray() {
// TODO Auto-generated method stub
throw new UnsupportedOperationException("Unimplemented method 'asByteArray'");
}
@Override
public int[] asIntArray() {
// TODO Auto-generated method stub
throw new UnsupportedOperationException("Unimplemented method 'asIntArray'");
}
@Override
public long[] asLongArray() {
// TODO Auto-generated method stub
throw new UnsupportedOperationException("Unimplemented method 'asLongArray'");
}
public Tag parent;
@Override
public void setParent(Tag parent) {
this.parent=parent;
}
@Override
public Tag getParent() {
return parent;
}
}

View file

@ -1,229 +0,0 @@
package dev.zontreck.ariaslib.nbt.old;
import java.io.DataInput;
import java.io.DataOutput;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import com.google.common.collect.Lists;
public class ListTag implements Tag
{
public static final TagType<ListTag> TYPE = new TagType<ListTag>() {
@Override
public ListTag load(DataInput input) throws IOException {
ListTag newTag = new ListTag();
byte type = input.readByte();
int count = input.readInt();
if(type == 0)
{
return newTag;
}
else{
// Read the entries
TagType<?> typ = TagTypes.getType(type);
while(count>0)
{
Tag entry = typ.load(input);
entry.setParent(newTag);
newTag.add(entry);
count--;
}
}
return newTag;
}
@Override
public void skip(DataInput input) throws IOException {
load(input);
}
@Override
public String getName() {
return "List";
}
@Override
public String getPrettyName() {
return "TAG_List";
}
@Override
public boolean hasValue() {
return true;
}
};
@Override
public void write(DataOutput output) throws IOException {
for (Tag tag : list) {
tag.write(output);
}
}
@Override
public int getId() {
return Tag.TAG_LIST;
}
@Override
public TagType<?> getType() {
return TYPE;
}
@Override
public Tag copy() {
return this;
}
@Override
public String getAsString(int indents) {
String indent = makeIndent(indents);
String indentInside = makeIndent(indents+1);
String ret = "\n" + indent +"[\n";
for (int i = 0; i< list.size(); i++)
{
Tag b = list.get(i);
ret += indentInside+b.getAsString(indents+1);
if((i+1) != list.size())
{
ret += ", ";
}
ret += "\n";
}
ret +=indent+ "]";
return ret;
}
@Override
public String toString()
{
// Return the values of getAsString
return getAsString(0);
}
private List<Tag> list;
private byte type = TAG_END;
public ListTag()
{
list = new ArrayList<>();
type = TAG_END;
}
public int size()
{
return list.size();
}
public boolean add(Tag value)
{
if(type == TAG_END || type == (byte)value.getId())
{
type = (byte)value.getId();
value.setParent(this);
list.add(value);
return true;
} else return false;
}
public Tag get(int num)
{
return list.get(num);
}
public void remove(int num)
{
list.remove(num);
}
public int indexOf(Tag tag)
{
return list.indexOf(tag);
}
public void clear()
{
list= Lists.newArrayList();
type=TAG_END;
}
@Override
public Byte asByte() {
throw new UnsupportedOperationException("Unimplemented method 'asByte'");
}
@Override
public Float asFloat() {
throw new UnsupportedOperationException("Unimplemented method 'asFloat'");
}
@Override
public String asString() {
throw new UnsupportedOperationException("Unimplemented method 'asString'");
}
@Override
public Integer asInt() {
// TODO Auto-generated method stub
throw new UnsupportedOperationException("Unimplemented method 'asInt'");
}
@Override
public Short asShort() {
// TODO Auto-generated method stub
throw new UnsupportedOperationException("Unimplemented method 'asShort'");
}
@Override
public Long asLong() {
// TODO Auto-generated method stub
throw new UnsupportedOperationException("Unimplemented method 'asLong'");
}
@Override
public Double asDouble() {
// TODO Auto-generated method stub
throw new UnsupportedOperationException("Unimplemented method 'asDouble'");
}
@Override
public byte[] asByteArray() {
// TODO Auto-generated method stub
throw new UnsupportedOperationException("Unimplemented method 'asByteArray'");
}
@Override
public int[] asIntArray() {
// TODO Auto-generated method stub
throw new UnsupportedOperationException("Unimplemented method 'asIntArray'");
}
@Override
public long[] asLongArray() {
// TODO Auto-generated method stub
throw new UnsupportedOperationException("Unimplemented method 'asLongArray'");
}
public Tag parent;
@Override
public void setParent(Tag parent) {
this.parent=parent;
}
@Override
public Tag getParent() {
return parent;
}
}

View file

@ -1,196 +0,0 @@
package dev.zontreck.ariaslib.nbt.old;
import java.io.DataInput;
import java.io.DataOutput;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
public class LongArrayTag implements Tag
{
public static final TagType<LongArrayTag> TYPE = new TagType<LongArrayTag>() {
@Override
public LongArrayTag load(DataInput input) throws IOException {
List<Long> lst = new ArrayList<>();
int count = input.readInt();
while(count>0)
{
lst.add(input.readLong());
count--;
}
return new LongArrayTag(toArray(lst));
}
@Override
public void skip(DataInput input) throws IOException {
load(input);
}
@Override
public boolean hasValue() {
return true;
}
@Override
public String getName() {
return "Long_Array";
}
@Override
public String getPrettyName() {
return "TAG_Long_Array";
}
};
@Override
public void write(DataOutput output) throws IOException {
output.writeInt(value.length);
for (long b : value) {
output.writeLong(b);
}
}
@Override
public int getId() {
return TAG_LONG_ARRAY;
}
@Override
public TagType<?> getType() {
return TYPE;
}
@Override
public Tag copy() {
return new LongArrayTag(value);
}
@Override
public String toString()
{
return String.valueOf(value);
}
@Override
public String getAsString(int indents) {
String indent = makeIndent(indents);
String indentInside = makeIndent(indents+1);
String ret = "\n" + indent + "[\n";
for (int i = 0; i< value.length; i++)
{
long b = value[i];
ret += String.valueOf(b);
if((i+1) != value.length)
{
ret += ", ";
}
ret += "\n";
}
ret +=indent+ "]";
return ret;
}
private LongArrayTag(long[] value)
{
this.value=value;
}
private static long[] toArray(List<Long> entries)
{
long[] ret = new long[entries.size()];
int cur=0;
for(long b : entries)
{
ret[cur] = b;
cur++;
}
return ret;
}
public static LongArrayTag valueOf(long[] b)
{
return new LongArrayTag(b);
}
private long[] value;
@Override
public Byte asByte() {
// TODO Auto-generated method stub
throw new UnsupportedOperationException("Unimplemented method 'asByte'");
}
@Override
public Float asFloat() {
// TODO Auto-generated method stub
throw new UnsupportedOperationException("Unimplemented method 'asFloat'");
}
@Override
public String asString() {
// TODO Auto-generated method stub
throw new UnsupportedOperationException("Unimplemented method 'asString'");
}
@Override
public Integer asInt() {
// TODO Auto-generated method stub
throw new UnsupportedOperationException("Unimplemented method 'asInt'");
}
@Override
public Short asShort() {
// TODO Auto-generated method stub
throw new UnsupportedOperationException("Unimplemented method 'asShort'");
}
@Override
public Long asLong() {
// TODO Auto-generated method stub
throw new UnsupportedOperationException("Unimplemented method 'asLong'");
}
@Override
public Double asDouble() {
// TODO Auto-generated method stub
throw new UnsupportedOperationException("Unimplemented method 'asDouble'");
}
@Override
public byte[] asByteArray() {
// TODO Auto-generated method stub
throw new UnsupportedOperationException("Unimplemented method 'asByteArray'");
}
@Override
public int[] asIntArray() {
// TODO Auto-generated method stub
throw new UnsupportedOperationException("Unimplemented method 'asIntArray'");
}
@Override
public long[] asLongArray() {
return value;
}
public Tag parent;
@Override
public void setParent(Tag parent) {
this.parent=parent;
}
@Override
public Tag getParent() {
return parent;
}
}

View file

@ -1,146 +0,0 @@
package dev.zontreck.ariaslib.nbt.old;
import java.io.DataInput;
import java.io.DataOutput;
import java.io.IOException;
public class LongTag implements Tag
{
public static final TagType<LongTag> TYPE = new TagType<LongTag>() {
@Override
public LongTag load(DataInput input) throws IOException {
return LongTag.valueOf(input.readLong());
}
@Override
public void skip(DataInput input) throws IOException {
input.readLong(); // fastest way to skip it is to read but not assign
}
@Override
public boolean hasValue() {
return true;
}
@Override
public String getName() {
return "Long";
}
@Override
public String getPrettyName() {
return "TAG_Long";
}
};
@Override
public void write(DataOutput output) throws IOException {
output.writeLong(value);
}
@Override
public int getId() {
return TAG_LONG;
}
@Override
public TagType<?> getType() {
return TYPE;
}
@Override
public Tag copy() {
return new LongTag(value);
}
@Override
public String getAsString(int indents) {
return String.valueOf(value);
}
private Long value;
private LongTag(Long value)
{
this.value=value;
}
@Override
public String toString()
{
return String.valueOf(value);
}
public static LongTag valueOf(Long val)
{
return new LongTag(val);
}
@Override
public Byte asByte() {
throw new UnsupportedOperationException("Unimplemented method 'asByte'");
}
@Override
public Float asFloat() {
throw new UnsupportedOperationException("Unimplemented method 'asFloat'");
}
@Override
public String asString() {
throw new UnsupportedOperationException("Unimplemented method 'asString'");
}
@Override
public Integer asInt() {
// TODO Auto-generated method stub
throw new UnsupportedOperationException("Unimplemented method 'asInt'");
}
@Override
public Short asShort() {
// TODO Auto-generated method stub
throw new UnsupportedOperationException("Unimplemented method 'asShort'");
}
@Override
public Long asLong() {
return value;
}
@Override
public Double asDouble() {
// TODO Auto-generated method stub
throw new UnsupportedOperationException("Unimplemented method 'asDouble'");
}
@Override
public byte[] asByteArray() {
// TODO Auto-generated method stub
throw new UnsupportedOperationException("Unimplemented method 'asByteArray'");
}
@Override
public int[] asIntArray() {
// TODO Auto-generated method stub
throw new UnsupportedOperationException("Unimplemented method 'asIntArray'");
}
@Override
public long[] asLongArray() {
// TODO Auto-generated method stub
throw new UnsupportedOperationException("Unimplemented method 'asLongArray'");
}
public Tag parent;
@Override
public void setParent(Tag parent) {
this.parent=parent;
}
@Override
public Tag getParent() {
return parent;
}
}

View file

@ -1,62 +0,0 @@
package dev.zontreck.ariaslib.nbt.old;
import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import dev.zontreck.ariaslib.events.EventBus;
import dev.zontreck.ariaslib.events.NBTLoadFailedEvent;
import dev.zontreck.ariaslib.events.NBTLoadedEvent;
import dev.zontreck.ariaslib.events.NBTSavingEvent;
public class NBTIO {
public static CompoundTag read(File file) throws FileNotFoundException, IOException
{
try{
FileInputStream fis = new FileInputStream(file);
CompoundTag tag;
DataInputStream dis = new DataInputStream(fis);
// Start loading
// We can only be a compound tag
dis.skipBytes(1); // Skip the compound tag type bit
String name = dis.readUTF();
tag = (CompoundTag) TagTypes.Compound.type.load(dis);
tag.setName(name);
EventBus.BUS.post(new NBTLoadedEvent(tag, file.getName()));
// Complete
return tag;
}catch(Exception e) {
EventBus.BUS.post(new NBTLoadFailedEvent(file.getName()));
return new CompoundTag();
}
}
public static void write(File file, CompoundTag tag) throws IOException
{
FileOutputStream fos = new FileOutputStream(file);
DataOutputStream dos = new DataOutputStream(fos);
NBTSavingEvent event = new NBTSavingEvent(tag, file.getName());
if(EventBus.BUS.post(event)){
tag=event.tag;
}
// Write a unnamed tag
dos.writeByte(Tag.TAG_COMPOUND);
tag.write(dos);
dos.flush();
fos.close();
}
}

View file

@ -1,147 +0,0 @@
package dev.zontreck.ariaslib.nbt.old;
import java.io.DataInput;
import java.io.DataOutput;
import java.io.IOException;
public class ShortTag implements Tag
{
public static final TagType<ShortTag> TYPE = new TagType<ShortTag>() {
@Override
public ShortTag load(DataInput input) throws IOException {
return ShortTag.valueOf(input.readShort());
}
@Override
public void skip(DataInput input) throws IOException {
input.readShort(); // fastest way to skip it is to read but not assign
}
@Override
public boolean hasValue() {
return true;
}
@Override
public String getName() {
return "Short";
}
@Override
public String getPrettyName() {
return "TAG_Short";
}
};
@Override
public void write(DataOutput output) throws IOException {
output.writeFloat(value);
}
@Override
public int getId() {
return TAG_SHORT;
}
@Override
public TagType<?> getType() {
return TYPE;
}
@Override
public Tag copy() {
return new ShortTag(value);
}
@Override
public String getAsString(int indents) {
return String.valueOf(value);
}
private short value;
private ShortTag(short value)
{
this.value=value;
}
@Override
public String toString()
{
return String.valueOf(value);
}
public static ShortTag valueOf(short val)
{
return new ShortTag(val);
}
@Override
public Byte asByte() {
throw new UnsupportedOperationException("Unimplemented method 'asByte'");
}
@Override
public Float asFloat() {
throw new UnsupportedOperationException("Unimplemented method 'asFloat'");
}
@Override
public String asString() {
throw new UnsupportedOperationException("Unimplemented method 'asString'");
}
@Override
public Integer asInt() {
// TODO Auto-generated method stub
throw new UnsupportedOperationException("Unimplemented method 'asInt'");
}
@Override
public Short asShort() {
return value;
}
@Override
public Long asLong() {
// TODO Auto-generated method stub
throw new UnsupportedOperationException("Unimplemented method 'asLong'");
}
@Override
public Double asDouble() {
// TODO Auto-generated method stub
throw new UnsupportedOperationException("Unimplemented method 'asDouble'");
}
@Override
public byte[] asByteArray() {
// TODO Auto-generated method stub
throw new UnsupportedOperationException("Unimplemented method 'asByteArray'");
}
@Override
public int[] asIntArray() {
// TODO Auto-generated method stub
throw new UnsupportedOperationException("Unimplemented method 'asIntArray'");
}
@Override
public long[] asLongArray() {
// TODO Auto-generated method stub
throw new UnsupportedOperationException("Unimplemented method 'asLongArray'");
}
public Tag parent;
@Override
public void setParent(Tag parent) {
this.parent=parent;
}
@Override
public Tag getParent() {
return parent;
}
}

View file

@ -1,148 +0,0 @@
package dev.zontreck.ariaslib.nbt.old;
import java.io.DataInput;
import java.io.DataOutput;
import java.io.IOException;
public class StringTag implements Tag{
public static final TagType<StringTag> TYPE = new TagType<StringTag>() {
@Override
public StringTag load(DataInput input) throws IOException {
return StringTag.valueOf(input.readUTF());
}
@Override
public void skip(DataInput input) throws IOException {
input.readUTF();
}
@Override
public String getName() {
return "String";
}
@Override
public String getPrettyName() {
return "TAG_String";
}
@Override
public boolean hasValue() {
return true;
}
};
@Override
public void write(DataOutput output) throws IOException {
output.writeUTF(toString());
}
@Override
public int getId() {
return TAG_STRING;
}
@Override
public TagType<?> getType() {
return TYPE;
}
@Override
public Tag copy() {
return new StringTag(value);
}
@Override
public String getAsString(int indents) {
return "\""+value+"\"";
}
@Override
public String toString()
{
return value;
}
public static StringTag valueOf(String input) {
if(input instanceof String)
{
return new StringTag(input);
} else return null;
}
private StringTag(String input)
{
this.value=input;
}
private String value;
@Override
public Byte asByte() {
throw new UnsupportedOperationException("Unimplemented method 'asByte'");
}
@Override
public Float asFloat() {
throw new UnsupportedOperationException("Unimplemented method 'asFloat'");
}
@Override
public String asString() {
return value;
}
@Override
public Integer asInt() {
// TODO Auto-generated method stub
throw new UnsupportedOperationException("Unimplemented method 'asInt'");
}
@Override
public Short asShort() {
// TODO Auto-generated method stub
throw new UnsupportedOperationException("Unimplemented method 'asShort'");
}
@Override
public Long asLong() {
// TODO Auto-generated method stub
throw new UnsupportedOperationException("Unimplemented method 'asLong'");
}
@Override
public Double asDouble() {
// TODO Auto-generated method stub
throw new UnsupportedOperationException("Unimplemented method 'asDouble'");
}
@Override
public byte[] asByteArray() {
// TODO Auto-generated method stub
throw new UnsupportedOperationException("Unimplemented method 'asByteArray'");
}
@Override
public int[] asIntArray() {
// TODO Auto-generated method stub
throw new UnsupportedOperationException("Unimplemented method 'asIntArray'");
}
@Override
public long[] asLongArray() {
// TODO Auto-generated method stub
throw new UnsupportedOperationException("Unimplemented method 'asLongArray'");
}
public Tag parent;
@Override
public void setParent(Tag parent) {
this.parent=parent;
}
@Override
public Tag getParent() {
return parent;
}
}

View file

@ -1,76 +0,0 @@
package dev.zontreck.ariaslib.nbt.old;
import java.io.DataOutput;
import java.io.IOException;
public interface Tag {
/*
* The type values were taken from Minecraft's documented format.
*/
byte TAG_END = 0;
byte TAG_BYTE = 1;
byte TAG_SHORT = 2;
byte TAG_INT = 3;
byte TAG_LONG = 4;
byte TAG_FLOAT = 5;
byte TAG_DOUBLE = 6;
byte TAG_BYTE_ARRAY = 7;
byte TAG_STRING = 8;
byte TAG_LIST = 9;
byte TAG_COMPOUND = 10;
byte TAG_INT_ARRAY = 11;
byte TAG_LONG_ARRAY = 12;
int OBJECT_HEADER = 64;
int ARRAY_HEADER = 96;
int OBJECT_REFERENCE = 32;
int STRING_SIZE = 224;
byte TAG_ANY_NUMERIC = 99;
int MAX_DEPTH = 512;
// End of direct minecraft values
int TAG_INVALID = 1024;
void setParent(Tag parent);
Tag getParent();
default boolean canHaveName(){
if(getParent() instanceof ListTag) return false;
else return true;
}
default String makeIndent(int num)
{
String ret = "";
int id = num;
while(id>0)
{
ret += " ";
id--;
}
return ret;
}
void write(DataOutput output) throws IOException;
int getId();
TagType<?> getType();
Tag copy();
String getAsString(int indents);
// Value specific functions
Byte asByte();
Float asFloat();
String asString();
Integer asInt();
Short asShort();
Long asLong();
Double asDouble();
byte[] asByteArray();
int[] asIntArray();
long[] asLongArray();
}

View file

@ -1,48 +0,0 @@
package dev.zontreck.ariaslib.nbt.old;
import java.io.DataInput;
import java.io.IOException;
public interface TagType <T extends Tag>
{
T load(DataInput input) throws IOException;
void skip(DataInput input) throws IOException;
boolean hasValue();
String getName();
String getPrettyName();
static TagType<EndTag> invalid(int num)
{
return new TagType<EndTag>() {
@Override
public EndTag load(DataInput input) throws IOException {
throw new IOException("Invalid operation, this tag is invalid");
}
@Override
public void skip(DataInput input) throws IOException {
}
@Override
public String getName() {
return "INVALID";
}
@Override
public String getPrettyName() {
return "TAG_INVALID";
}
@Override
public boolean hasValue() {
return false;
}
};
}
}

View file

@ -1,39 +0,0 @@
package dev.zontreck.ariaslib.nbt.old;
public enum TagTypes {
End(EndTag.TYPE), // 0
Byte(ByteTag.TYPE), // 1
Short(ShortTag.TYPE), // 2
Int(IntTag.TYPE), // 3
Long(LongTag.TYPE), // 4
Float(FloatTag.TYPE), // 5
Double(DoubleTag.TYPE), // 6
ByteArray(ByteArrayTag.TYPE), // 7
String(StringTag.TYPE), // 8
List(ListTag.TYPE), // 9
Compound(CompoundTag.TYPE), // 10
IntArray(IntArrayTag.TYPE), // 11
LongArray(LongArrayTag.TYPE); // 12
//public static final TagType<?>[] TYPES = new TagType[]{EndTag.TYPE, ByteTag.TYPE};
public TagType<?> type;
/**
* Locates the type in this enum
* @param value
* @return A TagType for the requested value
*/
public static TagType<?> getType(int value)
{
if(value>values().length)
{
return End.type;
}else {
return values()[value].type;
}
}
TagTypes(TagType<?> type)
{
this.type=type;
}
}

View file

@ -1,19 +0,0 @@
LibAC NBT
====
This was heavily inspired by the NBT File format used by minecraft for the ability to save things reliably at a compact size.
Disclaimer
====
The code used here is of my own creation, as i tried to model it after the NBT format in use in minecraft, due to me wanting a format that i was familiar with using the API of while writing mods.
However, i made the decision to make it not binary compatible with Minecraft. I am sure with some tweaks it would be, but my decision is final as this format will be expanded upon in the future to deviate from the standard minecraft NBT.
Planned Changes
=========
I plan to add more data types, including a actual List implementation.
Another change that is planned, is optimizing this a little bit more, and adding other tag types.