aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/cc/polyfrost/oneconfig/config
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/java/cc/polyfrost/oneconfig/config')
-rw-r--r--src/main/java/cc/polyfrost/oneconfig/config/core/ConfigUtils.java15
-rw-r--r--src/main/java/cc/polyfrost/oneconfig/config/elements/BasicOption.java4
2 files changed, 16 insertions, 3 deletions
diff --git a/src/main/java/cc/polyfrost/oneconfig/config/core/ConfigUtils.java b/src/main/java/cc/polyfrost/oneconfig/config/core/ConfigUtils.java
index aaa7cca..99b52e3 100644
--- a/src/main/java/cc/polyfrost/oneconfig/config/core/ConfigUtils.java
+++ b/src/main/java/cc/polyfrost/oneconfig/config/core/ConfigUtils.java
@@ -12,6 +12,7 @@ import org.jetbrains.annotations.Nullable;
import java.lang.annotation.Annotation;
import java.lang.reflect.Field;
import java.util.ArrayList;
+import java.util.Arrays;
public class ConfigUtils {
public static BasicOption getOption(Option option, Field field, Object instance) {
@@ -42,9 +43,19 @@ public class ConfigUtils {
return null;
}
- public static ArrayList<BasicOption> getClassOptions(Object object) {
+ public static ArrayList<BasicOption> getClassOptions(Object object, Class<?> parentClass) {
ArrayList<BasicOption> options = new ArrayList<>();
- for (Field field : object.getClass().getDeclaredFields()) {
+ ArrayList<Field> fields = new ArrayList<>(Arrays.asList(object.getClass().getDeclaredFields()));
+ Class<?> clazz = object.getClass();
+ while (true) {
+ clazz = clazz.getSuperclass();
+ if (clazz != null && clazz != parentClass) {
+ fields.addAll(Arrays.asList(clazz.getDeclaredFields()));
+ } else {
+ break;
+ }
+ }
+ for (Field field : fields) {
Option option = findAnnotation(field, Option.class);
if (option == null) continue;
options.add(getOption(option, field, object));
diff --git a/src/main/java/cc/polyfrost/oneconfig/config/elements/BasicOption.java b/src/main/java/cc/polyfrost/oneconfig/config/elements/BasicOption.java
index eba2f9f..2bee982 100644
--- a/src/main/java/cc/polyfrost/oneconfig/config/elements/BasicOption.java
+++ b/src/main/java/cc/polyfrost/oneconfig/config/elements/BasicOption.java
@@ -37,7 +37,9 @@ public abstract class BasicOption {
* @param object Java object to set the variable to
*/
protected void set(Object object) throws IllegalAccessException {
- if (field == null) return;
+ if (field == null) {
+ return;
+ }
field.set(parent, object);
}