aboutsummaryrefslogtreecommitdiff
path: root/common/src/main/java/dev/isxander/yacl3
diff options
context:
space:
mode:
Diffstat (limited to 'common/src/main/java/dev/isxander/yacl3')
-rw-r--r--common/src/main/java/dev/isxander/yacl3/config/v2/impl/ConfigClassHandlerImpl.java26
-rw-r--r--common/src/main/java/dev/isxander/yacl3/config/v2/impl/serializer/GsonConfigSerializer.java2
2 files changed, 24 insertions, 4 deletions
diff --git a/common/src/main/java/dev/isxander/yacl3/config/v2/impl/ConfigClassHandlerImpl.java b/common/src/main/java/dev/isxander/yacl3/config/v2/impl/ConfigClassHandlerImpl.java
index c363a7d..813b3ab 100644
--- a/common/src/main/java/dev/isxander/yacl3/config/v2/impl/ConfigClassHandlerImpl.java
+++ b/common/src/main/java/dev/isxander/yacl3/config/v2/impl/ConfigClassHandlerImpl.java
@@ -1,6 +1,7 @@
package dev.isxander.yacl3.config.v2.impl;
import dev.isxander.yacl3.api.*;
+import dev.isxander.yacl3.config.ConfigEntry;
import dev.isxander.yacl3.config.v2.api.*;
import dev.isxander.yacl3.config.v2.api.autogen.AutoGen;
import dev.isxander.yacl3.config.v2.api.autogen.OptionAccess;
@@ -46,12 +47,24 @@ public class ConfigClassHandlerImpl<T> implements ConfigClassHandler<T> {
this.instance = createNewObject();
this.defaults = createNewObject();
- this.fields = Arrays.stream(configClass.getDeclaredFields())
+ detectOldAnnotation(configClass.getDeclaredFields());
+
+ this.fields = discoverFields();
+ this.serializer = serializerFactory.apply(this);
+ }
+
+ private ConfigFieldImpl<?>[] discoverFields() {
+ return Arrays.stream(configClass.getDeclaredFields())
.peek(field -> field.setAccessible(true))
.filter(field -> field.isAnnotationPresent(SerialEntry.class) || field.isAnnotationPresent(AutoGen.class))
- .map(field -> new ConfigFieldImpl<>(new ReflectionFieldAccess<>(field, instance), new ReflectionFieldAccess<>(field, defaults), this, field.getAnnotation(SerialEntry.class), field.getAnnotation(AutoGen.class)))
+ .map(field -> new ConfigFieldImpl<>(
+ new ReflectionFieldAccess<>(field, instance),
+ new ReflectionFieldAccess<>(field, defaults),
+ this,
+ field.getAnnotation(SerialEntry.class),
+ field.getAnnotation(AutoGen.class)
+ ))
.toArray(ConfigFieldImpl[]::new);
- this.serializer = serializerFactory.apply(this);
}
@Override
@@ -212,6 +225,13 @@ public class ConfigClassHandlerImpl<T> implements ConfigClassHandler<T> {
}
}
+ private void detectOldAnnotation(Field[] fields) {
+ boolean hasOldConfigEntry = Arrays.stream(fields)
+ .anyMatch(field -> field.isAnnotationPresent(ConfigEntry.class));
+
+ Validate.isTrue(!hasOldConfigEntry, "At least one field in %s is still annotated with the deprecated @ConfigEntry annotation. This is incorrect. Use @SerialEntry.".formatted(configClass.getName()));
+ }
+
public static class BuilderImpl<T> implements Builder<T> {
private final Class<T> configClass;
private ResourceLocation id;
diff --git a/common/src/main/java/dev/isxander/yacl3/config/v2/impl/serializer/GsonConfigSerializer.java b/common/src/main/java/dev/isxander/yacl3/config/v2/impl/serializer/GsonConfigSerializer.java
index a60bcb1..49f2a47 100644
--- a/common/src/main/java/dev/isxander/yacl3/config/v2/impl/serializer/GsonConfigSerializer.java
+++ b/common/src/main/java/dev/isxander/yacl3/config/v2/impl/serializer/GsonConfigSerializer.java
@@ -1,7 +1,6 @@
package dev.isxander.yacl3.config.v2.impl.serializer;
import com.google.gson.*;
-import dev.isxander.yacl3.config.GsonConfigInstance;
import dev.isxander.yacl3.config.v2.api.*;
import dev.isxander.yacl3.config.v2.api.serializer.GsonConfigSerializerBuilder;
import dev.isxander.yacl3.gui.utils.ItemRegistryHelper;
@@ -168,6 +167,7 @@ public class GsonConfigSerializer<T> extends ConfigSerializer<T> {
@Override
@Deprecated
+ @SuppressWarnings("deprecation")
public void load() {
YACLConstants.LOGGER.warn("Calling ConfigSerializer#load() directly is deprecated. Please use ConfigClassHandler#load() instead.");
config.load();