diff options
4 files changed, 33 insertions, 5 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 1edd28a..d38fb73 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 @@ -170,6 +170,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(); diff --git a/common/src/main/java/dev/isxander/yacl3/impl/OptionImpl.java b/common/src/main/java/dev/isxander/yacl3/impl/OptionImpl.java index e539f73..afe9517 100644 --- a/common/src/main/java/dev/isxander/yacl3/impl/OptionImpl.java +++ b/common/src/main/java/dev/isxander/yacl3/impl/OptionImpl.java @@ -89,8 +89,12 @@ public final class OptionImpl<T> implements Option<T> { this.available = available; - if (changed) - this.triggerListeners(false); + if (changed) { + if (!available) { + this.pendingValue = binding().getValue(); + } + this.triggerListeners(!available); + } } @Override diff --git a/common/src/main/resources/assets/yet_another_config_lib/lang/tt_ru.json b/common/src/main/resources/assets/yet_another_config_lib/lang/tt_ru.json index 28fe6ce..06d005a 100644 --- a/common/src/main/resources/assets/yet_another_config_lib/lang/tt_ru.json +++ b/common/src/main/resources/assets/yet_another_config_lib/lang/tt_ru.json @@ -1,11 +1,14 @@ { "modmenu.summaryTranslation.yacl": "Төзүче нигезендә Minecraft өчен көйләүләр китапханәсе.", "modmenu.descriptionTranslation.yacl": "YetAnotherConfigLib (yacl) — нәкъ менә кирәк нәрсә. Төзүче нигезендә Minecraft өчен көйләүләр китапханәсе.", + "yacl.control.boolean.true": "Дөрес", "yacl.control.boolean.false": "Ялган", "yacl.control.action.execute": "ҮТӘҮ", + "yacl.control.text.blank": "<буш>", + "yacl.gui.save": "Үзгәрешләрне саклау", "yacl.gui.save.tooltip": "Кертелгән үзгәрешләрне даими итә.", "yacl.gui.finished.tooltip": "GUI-ны яба.", |