Skip to content

Commit 5fc0b30

Browse files
committed
Add nullability annotations to nbt tags
1 parent e227e46 commit 5fc0b30

16 files changed

Lines changed: 76 additions & 19 deletions

File tree

api/src/main/java/com/github/retrooper/packetevents/protocol/nbt/NBT.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,14 +20,15 @@
2020

2121
import com.github.retrooper.packetevents.protocol.util.NbtCodecException;
2222
import org.jspecify.annotations.NullMarked;
23+
import org.jspecify.annotations.Nullable;
2324

2425
@NullMarked
2526
public abstract class NBT {
2627

2728
public abstract NBTType<?> getType();
2829

2930
@Override
30-
public abstract boolean equals(Object other);
31+
public abstract boolean equals(@Nullable Object other);
3132

3233
@Override
3334
public abstract int hashCode();

api/src/main/java/com/github/retrooper/packetevents/protocol/nbt/NBTByte.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,10 @@
1818

1919
package com.github.retrooper.packetevents.protocol.nbt;
2020

21+
import org.jspecify.annotations.NullMarked;
22+
import org.jspecify.annotations.Nullable;
23+
24+
@NullMarked
2125
public class NBTByte extends NBTNumber {
2226

2327
protected final byte value;
@@ -80,7 +84,7 @@ public int hashCode() {
8084
}
8185

8286
@Override
83-
public boolean equals(Object obj) {
87+
public boolean equals(@Nullable Object obj) {
8488
if (this == obj) {
8589
return true;
8690
}

api/src/main/java/com/github/retrooper/packetevents/protocol/nbt/NBTByteArray.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,12 @@
1818

1919
package com.github.retrooper.packetevents.protocol.nbt;
2020

21+
import org.jspecify.annotations.NullMarked;
22+
import org.jspecify.annotations.Nullable;
23+
2124
import java.util.Arrays;
2225

26+
@NullMarked
2327
public class NBTByteArray extends NBT {
2428

2529
protected final byte[] array;
@@ -38,7 +42,7 @@ public byte[] getValue() {
3842
}
3943

4044
@Override
41-
public boolean equals(Object obj) {
45+
public boolean equals(@Nullable Object obj) {
4246
if (this == obj) {
4347
return true;
4448
}

api/src/main/java/com/github/retrooper/packetevents/protocol/nbt/NBTCompound.java

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
import com.github.retrooper.packetevents.wrapper.PacketWrapper;
2525
import org.jetbrains.annotations.Contract;
2626
import org.jetbrains.annotations.Nullable;
27+
import org.jspecify.annotations.NullMarked;
2728

2829
import java.text.MessageFormat;
2930
import java.util.ArrayList;
@@ -34,6 +35,7 @@
3435
import java.util.Set;
3536
import java.util.function.Supplier;
3637

38+
@NullMarked
3739
public class NBTCompound extends NBT {
3840

3941
protected final Map<String, NBT> tags = new LinkedHashMap<>();
@@ -199,7 +201,7 @@ public NBT removeTag(String key) {
199201
}
200202

201203
@SuppressWarnings("unchecked")
202-
public <T extends NBT> T removeTagAndReturnIfType(String key, Class<T> type) {
204+
public <T extends NBT> @Nullable T removeTagAndReturnIfType(String key, Class<T> type) {
203205
NBT tag = removeTag(key);
204206
if (type.isInstance(tag)) {
205207
return (T) tag;
@@ -208,15 +210,15 @@ public <T extends NBT> T removeTagAndReturnIfType(String key, Class<T> type) {
208210
}
209211

210212
@SuppressWarnings("unchecked")
211-
public <T extends NBT> NBTList<T> removeTagAndReturnIfListType(String key, Class<T> type) {
213+
public <T extends NBT> @Nullable NBTList<T> removeTagAndReturnIfListType(String key, Class<T> type) {
212214
NBTList<?> list = removeTagAndReturnIfType(key, NBTList.class);
213215
if ((list != null) && type.isAssignableFrom(list.getTagsType().getNBTClass())) {
214216
return (NBTList<T>) list;
215217
}
216218
return null;
217219
}
218220

219-
public void setTag(String key, NBT tag) {
221+
public void setTag(String key, @Nullable NBT tag) {
220222
if (tag != null) {
221223
tags.put(key, tag);
222224
} else {
@@ -251,7 +253,6 @@ public boolean getBooleanOrThrow(String string) {
251253
return tag != null ? decoder.decode(tag, wrapper) : def;
252254
}
253255

254-
@Contract("_, _, !null, _ -> !null")
255256
public <T> @Nullable T getOrSupply(String key, NbtDecoder<T> decoder, Supplier<@Nullable T> def, PacketWrapper<?> wrapper) {
256257
NBT tag = this.getTagOrNull(key);
257258
return tag != null ? decoder.decode(tag, wrapper) : def.get();
@@ -333,7 +334,7 @@ public <T> void setCompactList(String key, List<T> value, NbtEncoder<T> encoder,
333334
}
334335

335336
@Override
336-
public boolean equals(Object other) {
337+
public boolean equals(@Nullable Object other) {
337338
if (other instanceof NBTCompound) {
338339
if (isEmpty() && ((NBTCompound) other).isEmpty()) {
339340
return true;

api/src/main/java/com/github/retrooper/packetevents/protocol/nbt/NBTDouble.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,10 @@
1818

1919
package com.github.retrooper.packetevents.protocol.nbt;
2020

21+
import org.jspecify.annotations.NullMarked;
22+
import org.jspecify.annotations.Nullable;
23+
24+
@NullMarked
2125
public class NBTDouble extends NBTNumber {
2226

2327
protected final double value;
@@ -72,7 +76,7 @@ public int hashCode() {
7276
}
7377

7478
@Override
75-
public boolean equals(Object obj) {
79+
public boolean equals(@Nullable Object obj) {
7680
if (this == obj) {
7781
return true;
7882
}

api/src/main/java/com/github/retrooper/packetevents/protocol/nbt/NBTEnd.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,10 @@
1818

1919
package com.github.retrooper.packetevents.protocol.nbt;
2020

21+
import org.jspecify.annotations.NullMarked;
22+
import org.jspecify.annotations.Nullable;
23+
24+
@NullMarked
2125
public class NBTEnd extends NBT {
2226

2327
public static final NBTEnd INSTANCE = new NBTEnd();
@@ -28,7 +32,7 @@ public NBTType<NBTEnd> getType() {
2832
}
2933

3034
@Override
31-
public boolean equals(Object obj) {
35+
public boolean equals(@Nullable Object obj) {
3236
if (this == obj) {
3337
return true;
3438
}

api/src/main/java/com/github/retrooper/packetevents/protocol/nbt/NBTFloat.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,10 @@
1818

1919
package com.github.retrooper.packetevents.protocol.nbt;
2020

21+
import org.jspecify.annotations.NullMarked;
22+
import org.jspecify.annotations.Nullable;
23+
24+
@NullMarked
2125
public class NBTFloat extends NBTNumber {
2226

2327
protected final float value;
@@ -67,7 +71,7 @@ public double getAsDouble() {
6771
}
6872

6973
@Override
70-
public boolean equals(Object obj) {
74+
public boolean equals(@Nullable Object obj) {
7175
if (this == obj) {
7276
return true;
7377
}

api/src/main/java/com/github/retrooper/packetevents/protocol/nbt/NBTInt.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,10 @@
1818

1919
package com.github.retrooper.packetevents.protocol.nbt;
2020

21+
import org.jspecify.annotations.NullMarked;
22+
import org.jspecify.annotations.Nullable;
23+
24+
@NullMarked
2125
public class NBTInt extends NBTNumber {
2226

2327
protected final int value;
@@ -67,7 +71,7 @@ public double getAsDouble() {
6771
}
6872

6973
@Override
70-
public boolean equals(Object obj) {
74+
public boolean equals(@Nullable Object obj) {
7175
if (this == obj) {
7276
return true;
7377
}

api/src/main/java/com/github/retrooper/packetevents/protocol/nbt/NBTIntArray.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,12 @@
1818

1919
package com.github.retrooper.packetevents.protocol.nbt;
2020

21+
import org.jspecify.annotations.NullMarked;
22+
import org.jspecify.annotations.Nullable;
23+
2124
import java.util.Arrays;
2225

26+
@NullMarked
2327
public class NBTIntArray extends NBT {
2428

2529
protected final int[] array;
@@ -38,7 +42,7 @@ public int[] getValue() {
3842
}
3943

4044
@Override
41-
public boolean equals(Object obj) {
45+
public boolean equals(@Nullable Object obj) {
4246
if (this == obj) {
4347
return true;
4448
}

api/src/main/java/com/github/retrooper/packetevents/protocol/nbt/NBTList.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,16 @@
1818

1919
package com.github.retrooper.packetevents.protocol.nbt;
2020

21+
import org.jspecify.annotations.NullMarked;
22+
import org.jspecify.annotations.Nullable;
23+
2124
import java.text.MessageFormat;
2225
import java.util.ArrayList;
2326
import java.util.Collections;
2427
import java.util.List;
2528
import java.util.Objects;
2629

30+
@NullMarked
2731
public class NBTList<T extends NBT> extends NBT {
2832

2933
protected final NBTType<T> type;
@@ -167,7 +171,7 @@ public List<? extends NBT> unwrapTags() {
167171

168172
@SuppressWarnings("unchecked")
169173
@Override
170-
public boolean equals(Object obj) {
174+
public boolean equals(@Nullable Object obj) {
171175
if (this == obj) {
172176
return true;
173177
}

0 commit comments

Comments
 (0)