Skip to content

Commit 2288676

Browse files
committed
Add a package-info file (#50)
* Add a package-info file * Update not null annotation handling --------- Co-authored-by: theEvilReaper <theEvilReaper@users.noreply.github.com>
1 parent 19b93fe commit 2288676

34 files changed

Lines changed: 131 additions & 138 deletions

src/main/java/net/theevilreaper/aves/file/FileHandler.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
package net.theevilreaper.aves.file;
22

3-
import org.jetbrains.annotations.NotNull;
43
import org.slf4j.Logger;
54
import org.slf4j.LoggerFactory;
65

@@ -37,7 +36,7 @@ public interface FileHandler {
3736
* @param object The object to save
3837
* @param <T> A generic type for the object value
3938
*/
40-
<T> void save(@NotNull Path path, @NotNull T object);
39+
<T> void save(Path path, T object);
4140

4241
/**
4342
* Load a given file and parse to the give class.
@@ -47,5 +46,5 @@ public interface FileHandler {
4746
* @param <T> is generic type for the object value
4847
* @return a {@link Optional} with the object instance
4948
*/
50-
<T> Optional<T> load(@NotNull Path path, @NotNull Class<T> clazz);
49+
<T> Optional<T> load(Path path, Class<T> clazz);
5150
}

src/main/java/net/theevilreaper/aves/file/GsonFileHandler.java

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
import com.google.gson.Gson;
44
import com.google.gson.reflect.TypeToken;
55
import net.minestom.server.utils.validate.Check;
6-
import org.jetbrains.annotations.NotNull;
76

87
import java.io.IOException;
98
import java.nio.file.Files;
@@ -33,7 +32,7 @@ public GsonFileHandler() {
3332
* Creates a new instance from the file handler.
3433
* @param gson the gson instance to deserialize or serialize data
3534
*/
36-
public GsonFileHandler(@NotNull Gson gson) {
35+
public GsonFileHandler(Gson gson) {
3736
this.gson = gson;
3837
}
3938

@@ -44,7 +43,7 @@ public GsonFileHandler(@NotNull Gson gson) {
4443
* @param <T> A generic type for the object value
4544
*/
4645
@Override
47-
public <T> void save(@NotNull Path path, @NotNull T object) {
46+
public <T> void save(Path path, T object) {
4847
Check.argCondition(Files.isDirectory(path), "Unable to save a directory. Please check the used path");
4948
try (var outputStream = Files.newBufferedWriter(path, UTF_8)) {
5049
if (!Files.exists(path)) {
@@ -65,7 +64,7 @@ public <T> void save(@NotNull Path path, @NotNull T object) {
6564
* @return a {@link Optional} with the object instance
6665
*/
6766
@Override
68-
public <T> Optional<T> load(@NotNull Path path, @NotNull Class<T> clazz) {
67+
public <T> Optional<T> load(Path path, Class<T> clazz) {
6968
Check.argCondition(Files.isDirectory(path), "Unable to load a directory. Please check the used path");
7069
if (!Files.exists(path)) {
7170
return Optional.empty();
Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package net.theevilreaper.aves.file;
22

33
import com.google.gson.reflect.TypeToken;
4-
import org.jetbrains.annotations.NotNull;
54
import org.slf4j.Logger;
65
import org.slf4j.LoggerFactory;
76

@@ -11,7 +10,8 @@
1110
import java.util.Optional;
1211

1312
/**
14-
* The class represents the base logic to load or save json files.
13+
* The class represents the base logic to load or save JSON files.
14+
*
1515
* @author theEvilReaper
1616
* @version 1.0.0
1717
* @since 1.9.0
@@ -24,19 +24,21 @@ public interface ModernFileHandler {
2424

2525
/**
2626
* Saves a given object into a file.
27-
* @param path The path where the file is located
28-
* @param object The object to save
27+
*
28+
* @param path The path where the file is located
29+
* @param object The object to save
2930
* @param typeToken the type token to serialize the object
30-
* @param <T> A generic type for the object value
31+
* @param <T> A generic type for the object value
3132
*/
32-
<T> void save(@NotNull Path path, @NotNull T object, @NotNull TypeToken<T> typeToken);
33+
<T> void save(Path path, T object, TypeToken<T> typeToken);
3334

3435
/**
3536
* Load a given file and parse to the give class.
36-
* @param path is the where the file is located
37+
*
38+
* @param path is the where the file is located
3739
* @param typeToken the type token to deserialize the object
38-
* @param <T> is generic type for the object value
40+
* @param <T> is generic type for the object value
3941
* @return a {@link Optional} with the object instance
4042
*/
41-
<T> Optional<T> load(@NotNull Path path, @NotNull TypeToken<T> typeToken);
43+
<T> Optional<T> load(Path path, TypeToken<T> typeToken);
4244
}

src/main/java/net/theevilreaper/aves/file/ModernGsonFileHandler.java

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
import com.google.gson.Gson;
44
import com.google.gson.reflect.TypeToken;
55
import net.minestom.server.utils.validate.Check;
6-
import org.jetbrains.annotations.NotNull;
76

87
import java.io.IOException;
98
import java.nio.file.Files;
@@ -31,7 +30,7 @@ public ModernGsonFileHandler() {
3130
* Creates a new instance from the file handler.
3231
* @param gson the gson instance to deserialize or serialize data
3332
*/
34-
public ModernGsonFileHandler(@NotNull Gson gson) {
33+
public ModernGsonFileHandler(Gson gson) {
3534
this.gson = gson;
3635
}
3736

@@ -42,7 +41,7 @@ public ModernGsonFileHandler(@NotNull Gson gson) {
4241
* @param <T> A generic type for the object value
4342
*/
4443
@Override
45-
public <T> void save(@NotNull Path path, @NotNull T object, @NotNull TypeToken<T> typeToken) {
44+
public <T> void save(Path path, T object, TypeToken<T> typeToken) {
4645
Check.argCondition(Files.isDirectory(path), "Unable to save a directory. Please check the used path");
4746
try (var outputStream = Files.newBufferedWriter(path, UTF_8)) {
4847
if (!Files.exists(path)) {
@@ -63,7 +62,7 @@ public <T> void save(@NotNull Path path, @NotNull T object, @NotNull TypeToken<T
6362
* @return a {@link Optional} with the object instance
6463
*/
6564
@Override
66-
public <T> Optional<T> load(@NotNull Path path, @NotNull TypeToken<T> typeToken) {
65+
public <T> Optional<T> load(Path path, TypeToken<T> typeToken) {
6766
Check.argCondition(Files.isDirectory(path), "Unable to load a directory. Please check the used path");
6867
if (!Files.exists(path)) {
6968
return Optional.empty();

src/main/java/net/theevilreaper/aves/file/gson/ItemStackGsonTypeAdapter.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414
import net.minestom.server.item.Material;
1515
import net.minestom.server.item.component.CustomModelData;
1616
import net.minestom.server.item.component.TooltipDisplay;
17-
import org.jetbrains.annotations.NotNull;
1817

1918
import java.lang.reflect.Type;
2019

@@ -30,7 +29,7 @@ public non-sealed class ItemStackGsonTypeAdapter implements JsonSerializer<ItemS
3029
private static final String CUSTOM_MODEL_DATA = "customModelData";
3130

3231
@Override
33-
public JsonElement serialize(@NotNull ItemStack itemStack, Type type, JsonSerializationContext context) {
32+
public JsonElement serialize(ItemStack itemStack, Type type, JsonSerializationContext context) {
3433
JsonObject object = new JsonObject();
3534
object.addProperty(MATERIAL, itemStack.material().name());
3635
object.addProperty("amount", itemStack.amount());
@@ -60,7 +59,7 @@ public JsonElement serialize(@NotNull ItemStack itemStack, Type type, JsonSerial
6059
}
6160

6261
@Override
63-
public ItemStack deserialize(@NotNull JsonElement jsonElement, Type type, JsonDeserializationContext context) throws JsonParseException {
62+
public ItemStack deserialize(JsonElement jsonElement, Type type, JsonDeserializationContext context) throws JsonParseException {
6463
JsonObject object = jsonElement.getAsJsonObject();
6564

6665
Material material = Material.STONE;

src/main/java/net/theevilreaper/aves/file/gson/ItemStackSerializerHelper.java

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313
import net.minestom.server.item.enchant.Enchantment;
1414
import net.minestom.server.registry.DynamicRegistry;
1515
import net.minestom.server.registry.RegistryKey;
16-
import org.jetbrains.annotations.NotNull;
1716

1817
import java.util.ArrayList;
1918
import java.util.List;
@@ -42,7 +41,7 @@ sealed interface ItemStackSerializerHelper permits ItemStackGsonTypeAdapter {
4241
* @param stack the stack to serialize
4342
* @param object the object to serialize the data
4443
*/
45-
default void serializeCustomName(@NotNull ItemStack stack, @NotNull JsonObject object) {
44+
default void serializeCustomName(ItemStack stack, JsonObject object) {
4645
if (!stack.has(DataComponents.CUSTOM_NAME)) return;
4746
final Component itemName = stack.get(DataComponents.CUSTOM_NAME, Component.empty());
4847
final String displayName = plainText().serialize(itemName);
@@ -55,7 +54,7 @@ default void serializeCustomName(@NotNull ItemStack stack, @NotNull JsonObject o
5554
* @param stack the builder to set the custom name
5655
* @param jsonObject the object to deserialize the data
5756
*/
58-
default void serializeLore(@NotNull ItemStack stack, @NotNull JsonObject jsonObject) {
57+
default void serializeLore(ItemStack stack, JsonObject jsonObject) {
5958
if (!stack.has(DataComponents.LORE)) return;
6059
final List<Component> loreLines = stack.get(DataComponents.LORE);
6160

@@ -75,7 +74,7 @@ default void serializeLore(@NotNull ItemStack stack, @NotNull JsonObject jsonObj
7574
* @param object the object to deserialize the data
7675
* @return the builder with the lore set
7776
*/
78-
default @NotNull ItemStack.Builder deserializeLore(@NotNull ItemStack.Builder builder, @NotNull JsonObject object) {
77+
default ItemStack.Builder deserializeLore(ItemStack.Builder builder, JsonObject object) {
7978
if (!object.has(LORE_KEY)) return builder;
8079

8180
JsonArray loreArray = object.getAsJsonArray(LORE_KEY);
@@ -92,7 +91,7 @@ default void serializeLore(@NotNull ItemStack stack, @NotNull JsonObject jsonObj
9291
* @param stack the stack to serialize
9392
* @param object the object to serialize the data
9493
*/
95-
default void serializeEnchantments(@NotNull ItemStack stack, @NotNull JsonObject object) {
94+
default void serializeEnchantments(ItemStack stack, JsonObject object) {
9695
if (!stack.has(DataComponents.ENCHANTMENTS)) return;
9796
JsonArray enchantsArray = new JsonArray();
9897
final EnchantmentList enchantmentList = stack.get(DataComponents.ENCHANTMENTS);
@@ -115,7 +114,7 @@ default void serializeEnchantments(@NotNull ItemStack stack, @NotNull JsonObject
115114
* @param object the object to deserialize the data
116115
* @return the builder with the enchantments set
117116
*/
118-
default @NotNull ItemStack.Builder deserializeEnchantments(@NotNull ItemStack.Builder builder, @NotNull JsonObject object) {
117+
default ItemStack.Builder deserializeEnchantments(ItemStack.Builder builder, JsonObject object) {
119118
if (!object.has(ENCHANTMENTS)) return builder;
120119
JsonArray enchantsArray = object.getAsJsonArray(ENCHANTMENTS);
121120
Map<RegistryKey<Enchantment>, Integer> enchantments = new HashMap<>();

src/main/java/net/theevilreaper/aves/file/gson/KeyGsonAdapter.java

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
import com.google.gson.stream.JsonWriter;
66
import net.kyori.adventure.key.Key;
77
import org.jetbrains.annotations.Contract;
8-
import org.jetbrains.annotations.NotNull;
98

109
import java.io.IOException;
1110
import java.util.function.BiFunction;
@@ -36,7 +35,7 @@ public class KeyGsonAdapter extends TypeAdapter<Key> {
3635

3736
private final BiFunction<String, String, Key> createKeyObject;
3837

39-
private KeyGsonAdapter(@NotNull BiFunction<String, String, Key> createKeyObject) {
38+
private KeyGsonAdapter(BiFunction<String, String, Key> createKeyObject) {
4039
this.createKeyObject = createKeyObject;
4140
}
4241

@@ -49,7 +48,7 @@ private KeyGsonAdapter() {
4948
* @return the new instance of the {@link KeyGsonAdapter}
5049
*/
5150
@Contract(value = " -> new", pure = true)
52-
public static @NotNull KeyGsonAdapter create() {
51+
public static KeyGsonAdapter create() {
5352
return new KeyGsonAdapter();
5453
}
5554

@@ -59,23 +58,20 @@ private KeyGsonAdapter() {
5958
* @return the new instance of the {@link KeyGsonAdapter}
6059
*/
6160
@Contract(value = "_ -> new", pure = true)
62-
public static @NotNull KeyGsonAdapter create(@NotNull BiFunction<String, String, Key> createKeyObject) {
61+
public static KeyGsonAdapter create(BiFunction<String, String, Key> createKeyObject) {
6362
return new KeyGsonAdapter(createKeyObject);
6463
}
6564

6665
/**
6766
* Creates a new instance of the {@link KeyGsonAdapter} with a custom key) creation function for Minestom.
6867
* @return the new instance of the {@link KeyGsonAdapter}
6968
*/
70-
public static @NotNull KeyGsonAdapter createMinestom() {
69+
public static KeyGsonAdapter createMinestom() {
7170
return new KeyGsonAdapter(Key::key);
7271
}
7372

7473
@Override
7574
public void write(JsonWriter out, Key value) throws IOException {
76-
if (value == null) {
77-
return;
78-
}
7975
out.beginObject();
8076
out.name("namespace").value(value.namespace());
8177
out.name("value").value(value.value());

src/main/java/net/theevilreaper/aves/file/gson/MiniMessageComponentGsonAdapter.java

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
import net.kyori.adventure.text.Component;
77
import net.kyori.adventure.text.minimessage.MiniMessage;
88
import org.jetbrains.annotations.Contract;
9-
import org.jetbrains.annotations.NotNull;
109

1110
import java.io.IOException;
1211

@@ -36,15 +35,12 @@ public class MiniMessageComponentGsonAdapter extends TypeAdapter<Component> {
3635
* @return the new instance of the {@link MiniMessageComponentGsonAdapter}
3736
*/
3837
@Contract(value = " -> new", pure = true)
39-
public static @NotNull MiniMessageComponentGsonAdapter create() {
38+
public static MiniMessageComponentGsonAdapter create() {
4039
return new MiniMessageComponentGsonAdapter();
4140
}
4241

4342
@Override
4443
public void write(JsonWriter out, Component value) throws IOException {
45-
if (value == null) {
46-
return;
47-
}
4844
out.beginObject();
4945
out.name("minimessage").value(MiniMessage.miniMessage().serialize(value));
5046
out.endObject();

src/main/java/net/theevilreaper/aves/file/gson/PositionGsonAdapter.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
import net.minestom.server.coordinate.Point;
1111
import net.minestom.server.coordinate.Pos;
1212
import net.minestom.server.coordinate.Vec;
13-
import org.jetbrains.annotations.NotNull;
1413

1514
import java.lang.reflect.Type;
1615

@@ -27,7 +26,7 @@ public class PositionGsonAdapter implements JsonSerializer<Point>, JsonDeseriali
2726
private static final String PITCH = "pitch";
2827

2928
@Override
30-
public Point deserialize(@NotNull JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException {
29+
public Point deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException {
3130
JsonObject object = json.getAsJsonObject();
3231
double x = object.get("x").getAsDouble();
3332
double y = object.get("y").getAsDouble();
@@ -43,7 +42,7 @@ public Point deserialize(@NotNull JsonElement json, Type typeOfT, JsonDeserializ
4342
}
4443

4544
@Override
46-
public JsonElement serialize(@NotNull Point src, Type typeOfSrc, JsonSerializationContext context) {
45+
public JsonElement serialize(Point src, Type typeOfSrc, JsonSerializationContext context) {
4746
JsonObject object = new JsonObject();
4847
object.addProperty("x", src.x());
4948
object.addProperty("y", src.y());

src/main/java/net/theevilreaper/aves/file/gson/UUIDGsonAdapter.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
import com.google.gson.TypeAdapter;
44
import com.google.gson.stream.JsonReader;
55
import com.google.gson.stream.JsonWriter;
6-
import org.jetbrains.annotations.NotNull;
76
import org.jetbrains.annotations.Nullable;
87

98
import java.io.IOException;
@@ -28,7 +27,7 @@ public final class UUIDGsonAdapter extends TypeAdapter<UUID> {
2827
* @throws IOException if an error occurs during the writing process
2928
*/
3029
@Override
31-
public void write(@NotNull JsonWriter jsonWriter, @Nullable UUID uuid) throws IOException {
30+
public void write(JsonWriter jsonWriter, @Nullable UUID uuid) throws IOException {
3231
if (uuid == null) return;
3332
jsonWriter.beginObject();
3433
jsonWriter.name("mostSigBits").value(uuid.getMostSignificantBits());
@@ -44,7 +43,7 @@ public void write(@NotNull JsonWriter jsonWriter, @Nullable UUID uuid) throws IO
4443
* @throws IOException if an error occurs during the reading process
4544
*/
4645
@Override
47-
public @NotNull UUID read(@NotNull JsonReader jsonReader) throws IOException {
46+
public UUID read(JsonReader jsonReader) throws IOException {
4847
jsonReader.beginObject();
4948
if (!jsonReader.nextName().equals("mostSigBits")) {
5049
throw new IOException("Expected mostSigBits");

0 commit comments

Comments
 (0)