diff options
Diffstat (limited to 'src/main/java/dev/isxander/yacl')
-rw-r--r-- | src/main/java/dev/isxander/yacl/config/ConfigEntry.java | 11 | ||||
-rw-r--r-- | src/main/java/dev/isxander/yacl/config/GsonConfigInstance.java | 14 |
2 files changed, 24 insertions, 1 deletions
diff --git a/src/main/java/dev/isxander/yacl/config/ConfigEntry.java b/src/main/java/dev/isxander/yacl/config/ConfigEntry.java new file mode 100644 index 0000000..7f04c33 --- /dev/null +++ b/src/main/java/dev/isxander/yacl/config/ConfigEntry.java @@ -0,0 +1,11 @@ +package dev.isxander.yacl.config; + +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +@Retention(RetentionPolicy.RUNTIME) +@Target(ElementType.FIELD) +public @interface ConfigEntry { +} diff --git a/src/main/java/dev/isxander/yacl/config/GsonConfigInstance.java b/src/main/java/dev/isxander/yacl/config/GsonConfigInstance.java index 6f517cc..5d19e48 100644 --- a/src/main/java/dev/isxander/yacl/config/GsonConfigInstance.java +++ b/src/main/java/dev/isxander/yacl/config/GsonConfigInstance.java @@ -43,7 +43,7 @@ public class GsonConfigInstance<T> extends ConfigInstance<T> { super(configClass); this.path = path; this.gson = builder - .excludeFieldsWithModifiers(Modifier.TRANSIENT) + .setExclusionStrategies(new ConfigExclusionStrategy()) .registerTypeHierarchyAdapter(Text.class, new Text.Serializer()) .registerTypeHierarchyAdapter(Style.class, new Style.Serializer()) .registerTypeHierarchyAdapter(Color.class, new ColorTypeAdapter()) @@ -81,6 +81,18 @@ public class GsonConfigInstance<T> extends ConfigInstance<T> { return this.path; } + private static class ConfigExclusionStrategy implements ExclusionStrategy { + @Override + public boolean shouldSkipField(FieldAttributes fieldAttributes) { + return fieldAttributes.getAnnotation(ConfigEntry.class) == null; + } + + @Override + public boolean shouldSkipClass(Class<?> aClass) { + return false; + } + } + public static class ColorTypeAdapter implements JsonSerializer<Color>, JsonDeserializer<Color> { @Override public Color deserialize(JsonElement jsonElement, Type type, JsonDeserializationContext jsonDeserializationContext) throws JsonParseException { |