Flesh out NBT types

This commit is contained in:
nossr50 2019-10-31 20:15:36 -07:00
parent 9911c406f8
commit 25a9c75a5a
12 changed files with 321 additions and 117 deletions

View File

@ -1,11 +1,12 @@
package com.gmail.nossr50.core.nbt; package com.gmail.nossr50.core.nbt;
import java.util.Objects;
public class NBTByte implements NBTBase { public class NBTByte implements NBTBase {
private String key; private byte value;
private Byte value;
public NBTByte(Byte value) { public NBTByte(byte value) {
this.value = value; this.value = value;
} }
@ -14,20 +15,31 @@ public class NBTByte implements NBTBase {
return NBTType.BYTE; return NBTType.BYTE;
} }
public String getKey() { public byte getValue() {
return key;
}
public void setKey(String key) {
this.key = key;
}
public Byte getValue() {
return value; return value;
} }
public void setValue(Byte value) { public void setValue(byte value) {
this.value = value; this.value = value;
} }
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
NBTByte nbtByte = (NBTByte) o;
return value == nbtByte.value;
}
@Override
public int hashCode() {
return Objects.hash(value);
}
@Override
public String toString() {
return "NBTByte{" +
"value=" + value +
'}';
}
} }

View File

@ -1,10 +1,17 @@
package com.gmail.nossr50.core.nbt; package com.gmail.nossr50.core.nbt;
import org.checkerframework.checker.nullness.qual.NonNull;
import java.util.Arrays;
public class NBTByteArray implements NBTBase { public class NBTByteArray implements NBTBase {
private String key;
private byte[] values; private byte[] values;
public NBTByteArray(byte[] values) {
this.values = values;
}
@Override @Override
public NBTType getNBTType() { public NBTType getNBTType() {
return NBTType.BYTE_ARRAY; return NBTType.BYTE_ARRAY;
@ -14,14 +21,6 @@ public class NBTByteArray implements NBTBase {
return values.length; return values.length;
} }
public String getKey() {
return key;
}
public void setKey(String key) {
this.key = key;
}
public byte[] getValues() { public byte[] getValues() {
return values; return values;
} }
@ -29,4 +28,24 @@ public class NBTByteArray implements NBTBase {
public void setValues(byte[] values) { public void setValues(byte[] values) {
this.values = values; this.values = values;
} }
@Override
public String toString() {
return "NBTByteArray{" +
"values=" + Arrays.toString(values) +
'}';
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
NBTByteArray that = (NBTByteArray) o;
return Arrays.equals(values, that.values);
}
@Override
public int hashCode() {
return Arrays.hashCode(values);
}
} }

View File

@ -1,16 +1,15 @@
package com.gmail.nossr50.core.nbt; package com.gmail.nossr50.core.nbt;
import java.util.Collection; import org.checkerframework.checker.nullness.qual.NonNull;
import java.util.LinkedHashMap;
import java.util.Map; import java.util.*;
import java.util.Set;
public class NBTCompound implements NBTBase { public class NBTCompound implements NBTBase {
private String key; @NonNull
private Map<String, NBTBase> tagMap; private Map<String, NBTBase> tagMap;
public NBTCompound(String key) { public NBTCompound() {
tagMap = new LinkedHashMap<>(); tagMap = new LinkedHashMap<>();
} }
@ -23,14 +22,6 @@ public class NBTCompound implements NBTBase {
return tagMap.get(key); return tagMap.get(key);
} }
public String getKey() {
return key;
}
public void setKey(String key) {
this.key = key;
}
public void addNBT(String tagKey, NBTBase nbt) { public void addNBT(String tagKey, NBTBase nbt) {
tagMap.put(tagKey, nbt); tagMap.put(tagKey, nbt);
} }
@ -50,5 +41,25 @@ public class NBTCompound implements NBTBase {
public void removeEntry(String tagKey) { public void removeEntry(String tagKey) {
tagMap.remove(tagKey); tagMap.remove(tagKey);
} }
@Override
public String toString() {
return "NBTCompound{" +
"tagMap=" + tagMap +
'}';
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
NBTCompound that = (NBTCompound) o;
return tagMap.equals(that.tagMap);
}
@Override
public int hashCode() {
return Objects.hash(tagMap);
}
} }

View File

@ -1,23 +1,20 @@
package com.gmail.nossr50.core.nbt; package com.gmail.nossr50.core.nbt;
import java.util.Objects;
public class NBTDouble implements NBTBase { public class NBTDouble implements NBTBase {
private String key;
private double value; private double value;
public NBTDouble(double value) {
this.value = value;
}
@Override @Override
public NBTType getNBTType() { public NBTType getNBTType() {
return NBTType.DOUBLE; return NBTType.DOUBLE;
} }
public String getKey() {
return key;
}
public void setKey(String key) {
this.key = key;
}
public double getValue() { public double getValue() {
return value; return value;
} }
@ -25,4 +22,24 @@ public class NBTDouble implements NBTBase {
public void setValue(double value) { public void setValue(double value) {
this.value = value; this.value = value;
} }
@Override
public String toString() {
return "NBTDouble{" +
"value=" + value +
'}';
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
NBTDouble nbtDouble = (NBTDouble) o;
return Double.compare(nbtDouble.value, value) == 0;
}
@Override
public int hashCode() {
return Objects.hash(value);
}
} }

View File

@ -1,23 +1,20 @@
package com.gmail.nossr50.core.nbt; package com.gmail.nossr50.core.nbt;
import java.util.Objects;
public class NBTFloat implements NBTBase { public class NBTFloat implements NBTBase {
private String key;
private float value; private float value;
public NBTFloat(float value) {
this.value = value;
}
@Override @Override
public NBTType getNBTType() { public NBTType getNBTType() {
return NBTType.FLOAT; return NBTType.FLOAT;
} }
public String getKey() {
return key;
}
public void setKey(String key) {
this.key = key;
}
public float getValue() { public float getValue() {
return value; return value;
} }
@ -25,4 +22,24 @@ public class NBTFloat implements NBTBase {
public void setValue(float value) { public void setValue(float value) {
this.value = value; this.value = value;
} }
@Override
public String toString() {
return "NBTFloat{" +
"value=" + value +
'}';
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
NBTFloat nbtFloat = (NBTFloat) o;
return Float.compare(nbtFloat.value, value) == 0;
}
@Override
public int hashCode() {
return Objects.hash(value);
}
} }

View File

@ -1,23 +1,20 @@
package com.gmail.nossr50.core.nbt; package com.gmail.nossr50.core.nbt;
import java.util.Objects;
public class NBTInt implements NBTBase { public class NBTInt implements NBTBase {
private String key;
private int value; private int value;
public NBTInt(int value) {
this.value = value;
}
@Override @Override
public NBTType getNBTType() { public NBTType getNBTType() {
return NBTType.INT; return NBTType.INT;
} }
public String getKey() {
return key;
}
public void setKey(String key) {
this.key = key;
}
public int getValue() { public int getValue() {
return value; return value;
} }
@ -25,4 +22,24 @@ public class NBTInt implements NBTBase {
public void setValue(int value) { public void setValue(int value) {
this.value = value; this.value = value;
} }
@Override
public String toString() {
return "NBTInt{" +
"value=" + value +
'}';
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
NBTInt nbtInt = (NBTInt) o;
return value == nbtInt.value;
}
@Override
public int hashCode() {
return Objects.hash(value);
}
} }

View File

@ -1,10 +1,17 @@
package com.gmail.nossr50.core.nbt; package com.gmail.nossr50.core.nbt;
import org.checkerframework.checker.nullness.qual.NonNull;
import java.util.Arrays;
public class NBTIntArray implements NBTBase { public class NBTIntArray implements NBTBase {
private String key;
private int[] values; private int[] values;
public NBTIntArray(int[] values) {
this.values = values;
}
@Override @Override
public NBTType getNBTType() { public NBTType getNBTType() {
return NBTType.INT_ARRAY; return NBTType.INT_ARRAY;
@ -14,14 +21,6 @@ public class NBTIntArray implements NBTBase {
return values.length; return values.length;
} }
public String getKey() {
return key;
}
public void setKey(String key) {
this.key = key;
}
public int[] getValues() { public int[] getValues() {
return values; return values;
} }
@ -29,4 +28,24 @@ public class NBTIntArray implements NBTBase {
public void setValues(int[] values) { public void setValues(int[] values) {
this.values = values; this.values = values;
} }
@Override
public String toString() {
return "NBTIntArray{" +
"values=" + Arrays.toString(values) +
'}';
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
NBTIntArray that = (NBTIntArray) o;
return Arrays.equals(values, that.values);
}
@Override
public int hashCode() {
return Arrays.hashCode(values);
}
} }

View File

@ -1,12 +1,19 @@
package com.gmail.nossr50.core.nbt; package com.gmail.nossr50.core.nbt;
import org.checkerframework.checker.nullness.qual.NonNull;
import java.util.List; import java.util.List;
import java.util.Objects;
public class NBTList implements NBTBase { public class NBTList implements NBTBase {
private String key; @NonNull
private List<? extends NBTBase> values; private List<? extends NBTBase> values;
public NBTList(@NonNull List<? extends NBTBase> values) {
this.values = values;
}
@Override @Override
public NBTType getNBTType() { public NBTType getNBTType() {
return NBTType.LIST; return NBTType.LIST;
@ -16,19 +23,31 @@ public class NBTList implements NBTBase {
return values.size(); return values.size();
} }
public String getKey() {
return key;
}
public void setKey(String key) {
this.key = key;
}
public List<? extends NBTBase> getValues() { public List<? extends NBTBase> getValues() {
return values; return values;
} }
public void setValues(List<? extends NBTBase> values) { public void setValues(@NonNull List<? extends NBTBase> values) {
this.values = values; this.values = values;
} }
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
NBTList nbtList = (NBTList) o;
return values.equals(nbtList.values);
}
@Override
public int hashCode() {
return Objects.hash(values);
}
@Override
public String toString() {
return "NBTList{" +
"values=" + values +
'}';
}
} }

View File

@ -1,16 +1,13 @@
package com.gmail.nossr50.core.nbt; package com.gmail.nossr50.core.nbt;
import java.util.Objects;
public class NBTLong implements NBTBase { public class NBTLong implements NBTBase {
private String key;
private long value; private long value;
public String getKey() { public NBTLong(long value) {
return key; this.value = value;
}
public void setKey(String key) {
this.key = key;
} }
public long getValue() { public long getValue() {
@ -25,4 +22,24 @@ public class NBTLong implements NBTBase {
public NBTType getNBTType() { public NBTType getNBTType() {
return NBTType.LONG; return NBTType.LONG;
} }
@Override
public String toString() {
return "NBTLong{" +
"value=" + value +
'}';
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
NBTLong nbtLong = (NBTLong) o;
return value == nbtLong.value;
}
@Override
public int hashCode() {
return Objects.hash(value);
}
} }

View File

@ -1,10 +1,15 @@
package com.gmail.nossr50.core.nbt; package com.gmail.nossr50.core.nbt;
import java.util.Arrays;
public class NBTLongArray implements NBTBase { public class NBTLongArray implements NBTBase {
private String key;
private long[] values; private long[] values;
public NBTLongArray(long[] values) {
this.values = values;
}
@Override @Override
public NBTType getNBTType() { public NBTType getNBTType() {
return NBTType.LONG_ARRAY; return NBTType.LONG_ARRAY;
@ -14,14 +19,6 @@ public class NBTLongArray implements NBTBase {
return values.length; return values.length;
} }
public String getKey() {
return key;
}
public void setKey(String key) {
this.key = key;
}
public long[] getValues() { public long[] getValues() {
return values; return values;
} }
@ -29,4 +26,24 @@ public class NBTLongArray implements NBTBase {
public void setValues(long[] values) { public void setValues(long[] values) {
this.values = values; this.values = values;
} }
@Override
public String toString() {
return "NBTLongArray{" +
"values=" + Arrays.toString(values) +
'}';
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
NBTLongArray that = (NBTLongArray) o;
return Arrays.equals(values, that.values);
}
@Override
public int hashCode() {
return Arrays.hashCode(values);
}
} }

View File

@ -1,23 +1,20 @@
package com.gmail.nossr50.core.nbt; package com.gmail.nossr50.core.nbt;
import java.util.Objects;
public class NBTShort implements NBTBase { public class NBTShort implements NBTBase {
private String key;
private short value; private short value;
public NBTShort(short value) {
this.value = value;
}
@Override @Override
public NBTType getNBTType() { public NBTType getNBTType() {
return NBTType.SHORT; return NBTType.SHORT;
} }
public String getKey() {
return key;
}
public void setKey(String key) {
this.key = key;
}
public short getValue() { public short getValue() {
return value; return value;
} }
@ -25,4 +22,24 @@ public class NBTShort implements NBTBase {
public void setValue(short value) { public void setValue(short value) {
this.value = value; this.value = value;
} }
@Override
public String toString() {
return "NBTShort{" +
"value=" + value +
'}';
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
NBTShort nbtShort = (NBTShort) o;
return value == nbtShort.value;
}
@Override
public int hashCode() {
return Objects.hash(value);
}
} }

View File

@ -1,28 +1,50 @@
package com.gmail.nossr50.core.nbt; package com.gmail.nossr50.core.nbt;
import org.checkerframework.checker.nullness.qual.NonNull;
import org.jetbrains.annotations.NotNull;
import java.util.Objects;
public class NBTString implements NBTBase { public class NBTString implements NBTBase {
private String key; @NonNull
private String value; private String value;
public NBTString(@NonNull String value) {
this.value = value;
}
@Override @Override
public NBTType getNBTType() { public NBTType getNBTType() {
return NBTType.STRING; return NBTType.STRING;
} }
public String getKey() { @NotNull
return key;
}
public void setKey(String key) {
this.key = key;
}
public String getValue() { public String getValue() {
return value; return value;
} }
public void setValue(String value) { public void setValue(@NotNull String value) {
this.value = value; this.value = value;
} }
@Override
public String toString() {
return "NBTString{" +
"value='" + value + '\'' +
'}';
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
NBTString nbtString = (NBTString) o;
return value.equals(nbtString.value);
}
@Override
public int hashCode() {
return Objects.hash(value);
}
} }