aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/cc/polyfrost/oneconfig/config
diff options
context:
space:
mode:
authorWyvest <45589059+Wyvest@users.noreply.github.com>2022-06-24 23:44:58 +0700
committerWyvest <45589059+Wyvest@users.noreply.github.com>2022-06-24 23:44:58 +0700
commitf1830199d99b666f28c2b3b246f688f102adb427 (patch)
tree07fba5e7fce5e523223e8fc9da70f7783d7f15f9 /src/main/java/cc/polyfrost/oneconfig/config
parentd4463b33342ccb5ea86c2a2c9da37b9b861b6674 (diff)
downloadOneConfig-f1830199d99b666f28c2b3b246f688f102adb427.tar.gz
OneConfig-f1830199d99b666f28c2b3b246f688f102adb427.tar.bz2
OneConfig-f1830199d99b666f28c2b3b246f688f102adb427.zip
TextHud revamp
add docs to Hud fix config not saving when exiting prematurely some new events
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);
}