diff --git a/mcmmo-core/src/main/java/com/gmail/nossr50/core/nbt/NBTByte.java b/mcmmo-core/src/main/java/com/gmail/nossr50/core/nbt/NBTByte.java index 93a3fab17..d484da24d 100644 --- a/mcmmo-core/src/main/java/com/gmail/nossr50/core/nbt/NBTByte.java +++ b/mcmmo-core/src/main/java/com/gmail/nossr50/core/nbt/NBTByte.java @@ -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 + + '}'; + } } diff --git a/mcmmo-core/src/main/java/com/gmail/nossr50/core/nbt/NBTByteArray.java b/mcmmo-core/src/main/java/com/gmail/nossr50/core/nbt/NBTByteArray.java index 312837442..31a733a73 100644 --- a/mcmmo-core/src/main/java/com/gmail/nossr50/core/nbt/NBTByteArray.java +++ b/mcmmo-core/src/main/java/com/gmail/nossr50/core/nbt/NBTByteArray.java @@ -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); + } } diff --git a/mcmmo-core/src/main/java/com/gmail/nossr50/core/nbt/NBTCompound.java b/mcmmo-core/src/main/java/com/gmail/nossr50/core/nbt/NBTCompound.java index 70d6d544d..a34150975 100644 --- a/mcmmo-core/src/main/java/com/gmail/nossr50/core/nbt/NBTCompound.java +++ b/mcmmo-core/src/main/java/com/gmail/nossr50/core/nbt/NBTCompound.java @@ -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 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); + } } diff --git a/mcmmo-core/src/main/java/com/gmail/nossr50/core/nbt/NBTDouble.java b/mcmmo-core/src/main/java/com/gmail/nossr50/core/nbt/NBTDouble.java index 4b3ed06be..979ba526a 100644 --- a/mcmmo-core/src/main/java/com/gmail/nossr50/core/nbt/NBTDouble.java +++ b/mcmmo-core/src/main/java/com/gmail/nossr50/core/nbt/NBTDouble.java @@ -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); + } } diff --git a/mcmmo-core/src/main/java/com/gmail/nossr50/core/nbt/NBTFloat.java b/mcmmo-core/src/main/java/com/gmail/nossr50/core/nbt/NBTFloat.java index 5bbb9a36f..98a401da5 100644 --- a/mcmmo-core/src/main/java/com/gmail/nossr50/core/nbt/NBTFloat.java +++ b/mcmmo-core/src/main/java/com/gmail/nossr50/core/nbt/NBTFloat.java @@ -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); + } } diff --git a/mcmmo-core/src/main/java/com/gmail/nossr50/core/nbt/NBTInt.java b/mcmmo-core/src/main/java/com/gmail/nossr50/core/nbt/NBTInt.java index a13ddca1a..85f87a9fa 100644 --- a/mcmmo-core/src/main/java/com/gmail/nossr50/core/nbt/NBTInt.java +++ b/mcmmo-core/src/main/java/com/gmail/nossr50/core/nbt/NBTInt.java @@ -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); + } } diff --git a/mcmmo-core/src/main/java/com/gmail/nossr50/core/nbt/NBTIntArray.java b/mcmmo-core/src/main/java/com/gmail/nossr50/core/nbt/NBTIntArray.java index fce90d9c8..d49d74412 100644 --- a/mcmmo-core/src/main/java/com/gmail/nossr50/core/nbt/NBTIntArray.java +++ b/mcmmo-core/src/main/java/com/gmail/nossr50/core/nbt/NBTIntArray.java @@ -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); + } } diff --git a/mcmmo-core/src/main/java/com/gmail/nossr50/core/nbt/NBTList.java b/mcmmo-core/src/main/java/com/gmail/nossr50/core/nbt/NBTList.java index 45b2bc8e6..706e4b68e 100644 --- a/mcmmo-core/src/main/java/com/gmail/nossr50/core/nbt/NBTList.java +++ b/mcmmo-core/src/main/java/com/gmail/nossr50/core/nbt/NBTList.java @@ -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 values; + public NBTList(@NonNull List 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 getValues() { return values; } - public void setValues(List values) { + public void setValues(@NonNull List 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 + + '}'; + } } diff --git a/mcmmo-core/src/main/java/com/gmail/nossr50/core/nbt/NBTLong.java b/mcmmo-core/src/main/java/com/gmail/nossr50/core/nbt/NBTLong.java index 20e6f50ea..35225fe47 100644 --- a/mcmmo-core/src/main/java/com/gmail/nossr50/core/nbt/NBTLong.java +++ b/mcmmo-core/src/main/java/com/gmail/nossr50/core/nbt/NBTLong.java @@ -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); + } } diff --git a/mcmmo-core/src/main/java/com/gmail/nossr50/core/nbt/NBTLongArray.java b/mcmmo-core/src/main/java/com/gmail/nossr50/core/nbt/NBTLongArray.java index feb7aee26..482ec9c6a 100644 --- a/mcmmo-core/src/main/java/com/gmail/nossr50/core/nbt/NBTLongArray.java +++ b/mcmmo-core/src/main/java/com/gmail/nossr50/core/nbt/NBTLongArray.java @@ -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); + } } diff --git a/mcmmo-core/src/main/java/com/gmail/nossr50/core/nbt/NBTShort.java b/mcmmo-core/src/main/java/com/gmail/nossr50/core/nbt/NBTShort.java index db64f624d..8b508c055 100644 --- a/mcmmo-core/src/main/java/com/gmail/nossr50/core/nbt/NBTShort.java +++ b/mcmmo-core/src/main/java/com/gmail/nossr50/core/nbt/NBTShort.java @@ -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); + } } diff --git a/mcmmo-core/src/main/java/com/gmail/nossr50/core/nbt/NBTString.java b/mcmmo-core/src/main/java/com/gmail/nossr50/core/nbt/NBTString.java index 123e82665..4f5a763c9 100644 --- a/mcmmo-core/src/main/java/com/gmail/nossr50/core/nbt/NBTString.java +++ b/mcmmo-core/src/main/java/com/gmail/nossr50/core/nbt/NBTString.java @@ -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); + } }