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;
import java.util.Objects;
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;
}
@ -14,20 +15,31 @@ public class NBTByte implements NBTBase {
return NBTType.BYTE;
}
public String getKey() {
return key;
}
public void setKey(String key) {
this.key = key;
}
public Byte getValue() {
public byte getValue() {
return value;
}
public void setValue(Byte value) {
public void setValue(byte 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;
import org.checkerframework.checker.nullness.qual.NonNull;
import java.util.Arrays;
public class NBTByteArray implements NBTBase {
private String key;
private byte[] values;
public NBTByteArray(byte[] values) {
this.values = values;
}
@Override
public NBTType getNBTType() {
return NBTType.BYTE_ARRAY;
@ -14,14 +21,6 @@ public class NBTByteArray implements NBTBase {
return values.length;
}
public String getKey() {
return key;
}
public void setKey(String key) {
this.key = key;
}
public byte[] getValues() {
return values;
}
@ -29,4 +28,24 @@ public class NBTByteArray implements NBTBase {
public void setValues(byte[] 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;
import java.util.Collection;
import java.util.LinkedHashMap;
import java.util.Map;
import java.util.Set;
import org.checkerframework.checker.nullness.qual.NonNull;
import java.util.*;
public class NBTCompound implements NBTBase {
private String key;
@NonNull
private Map<String, NBTBase> tagMap;
public NBTCompound(String key) {
public NBTCompound() {
tagMap = new LinkedHashMap<>();
}
@ -23,14 +22,6 @@ public class NBTCompound implements NBTBase {
return tagMap.get(key);
}
public String getKey() {
return key;
}
public void setKey(String key) {
this.key = key;
}
public void addNBT(String tagKey, NBTBase nbt) {
tagMap.put(tagKey, nbt);
}
@ -50,5 +41,25 @@ public class NBTCompound implements NBTBase {
public void removeEntry(String 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;
import java.util.Objects;
public class NBTDouble implements NBTBase {
private String key;
private double value;
public NBTDouble(double value) {
this.value = value;
}
@Override
public NBTType getNBTType() {
return NBTType.DOUBLE;
}
public String getKey() {
return key;
}
public void setKey(String key) {
this.key = key;
}
public double getValue() {
return value;
}
@ -25,4 +22,24 @@ public class NBTDouble implements NBTBase {
public void setValue(double 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;
import java.util.Objects;
public class NBTFloat implements NBTBase {
private String key;
private float value;
public NBTFloat(float value) {
this.value = value;
}
@Override
public NBTType getNBTType() {
return NBTType.FLOAT;
}
public String getKey() {
return key;
}
public void setKey(String key) {
this.key = key;
}
public float getValue() {
return value;
}
@ -25,4 +22,24 @@ public class NBTFloat implements NBTBase {
public void setValue(float 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;
import java.util.Objects;
public class NBTInt implements NBTBase {
private String key;
private int value;
public NBTInt(int value) {
this.value = value;
}
@Override
public NBTType getNBTType() {
return NBTType.INT;
}
public String getKey() {
return key;
}
public void setKey(String key) {
this.key = key;
}
public int getValue() {
return value;
}
@ -25,4 +22,24 @@ public class NBTInt implements NBTBase {
public void setValue(int 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;
import org.checkerframework.checker.nullness.qual.NonNull;
import java.util.Arrays;
public class NBTIntArray implements NBTBase {
private String key;
private int[] values;
public NBTIntArray(int[] values) {
this.values = values;
}
@Override
public NBTType getNBTType() {
return NBTType.INT_ARRAY;
@ -14,14 +21,6 @@ public class NBTIntArray implements NBTBase {
return values.length;
}
public String getKey() {
return key;
}
public void setKey(String key) {
this.key = key;
}
public int[] getValues() {
return values;
}
@ -29,4 +28,24 @@ public class NBTIntArray implements NBTBase {
public void setValues(int[] 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;
import org.checkerframework.checker.nullness.qual.NonNull;
import java.util.List;
import java.util.Objects;
public class NBTList implements NBTBase {
private String key;
@NonNull
private List<? extends NBTBase> values;
public NBTList(@NonNull List<? extends NBTBase> values) {
this.values = values;
}
@Override
public NBTType getNBTType() {
return NBTType.LIST;
@ -16,19 +23,31 @@ public class NBTList implements NBTBase {
return values.size();
}
public String getKey() {
return key;
}
public void setKey(String key) {
this.key = key;
}
public List<? extends NBTBase> getValues() {
return values;
}
public void setValues(List<? extends NBTBase> values) {
public void setValues(@NonNull List<? extends NBTBase> 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;
import java.util.Objects;
public class NBTLong implements NBTBase {
private String key;
private long value;
public String getKey() {
return key;
}
public void setKey(String key) {
this.key = key;
public NBTLong(long value) {
this.value = value;
}
public long getValue() {
@ -25,4 +22,24 @@ public class NBTLong implements NBTBase {
public NBTType getNBTType() {
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;
import java.util.Arrays;
public class NBTLongArray implements NBTBase {
private String key;
private long[] values;
public NBTLongArray(long[] values) {
this.values = values;
}
@Override
public NBTType getNBTType() {
return NBTType.LONG_ARRAY;
@ -14,14 +19,6 @@ public class NBTLongArray implements NBTBase {
return values.length;
}
public String getKey() {
return key;
}
public void setKey(String key) {
this.key = key;
}
public long[] getValues() {
return values;
}
@ -29,4 +26,24 @@ public class NBTLongArray implements NBTBase {
public void setValues(long[] 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;
import java.util.Objects;
public class NBTShort implements NBTBase {
private String key;
private short value;
public NBTShort(short value) {
this.value = value;
}
@Override
public NBTType getNBTType() {
return NBTType.SHORT;
}
public String getKey() {
return key;
}
public void setKey(String key) {
this.key = key;
}
public short getValue() {
return value;
}
@ -25,4 +22,24 @@ public class NBTShort implements NBTBase {
public void setValue(short 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;
import org.checkerframework.checker.nullness.qual.NonNull;
import org.jetbrains.annotations.NotNull;
import java.util.Objects;
public class NBTString implements NBTBase {
private String key;
@NonNull
private String value;
public NBTString(@NonNull String value) {
this.value = value;
}
@Override
public NBTType getNBTType() {
return NBTType.STRING;
}
public String getKey() {
return key;
}
public void setKey(String key) {
this.key = key;
}
@NotNull
public String getValue() {
return value;
}
public void setValue(String value) {
public void setValue(@NotNull String 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);
}
}