aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/main/java/cc/polyfrost/oneconfig/config/Config.java28
-rw-r--r--src/main/java/cc/polyfrost/oneconfig/config/elements/BasicOption.java2
2 files changed, 29 insertions, 1 deletions
diff --git a/src/main/java/cc/polyfrost/oneconfig/config/Config.java b/src/main/java/cc/polyfrost/oneconfig/config/Config.java
index f640610..2ba5077 100644
--- a/src/main/java/cc/polyfrost/oneconfig/config/Config.java
+++ b/src/main/java/cc/polyfrost/oneconfig/config/Config.java
@@ -177,6 +177,34 @@ public class Config {
}
/**
+ * Disable an option if a certain condition is not met
+ *
+ * @param option The name of the field, or if the field is in a page "pageName.fieldName"
+ * @param dependentOption The option that has to be enabled
+ */
+ protected void addDependency(String option, String dependentOption) {
+ if (!optionNames.containsKey(option) || !optionNames.containsKey(dependentOption)) return;
+ optionNames.get(option).addDependency(() -> {
+ try {
+ return (boolean) optionNames.get(dependentOption).get();
+ } catch (IllegalAccessException ignored) {
+ return true;
+ }
+ });
+ }
+
+ /**
+ * Disable an option if a certain condition is not met
+ *
+ * @param option The name of the field, or if the field is in a page "pageName.fieldName"
+ * @param value The value of the dependency
+ */
+ protected void addDependency(String option, boolean value) {
+ if (!optionNames.containsKey(option)) return;
+ optionNames.get(option).addDependency(() -> value);
+ }
+
+ /**
* Register a new listener for when an option changes
*
* @param option The name of the field, or if the field is in a page "pageName.fieldName"
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 0408c0a..eba2f9f 100644
--- a/src/main/java/cc/polyfrost/oneconfig/config/elements/BasicOption.java
+++ b/src/main/java/cc/polyfrost/oneconfig/config/elements/BasicOption.java
@@ -44,7 +44,7 @@ public abstract class BasicOption {
/**
* @return value of variable as Java object
*/
- protected Object get() throws IllegalAccessException {
+ public Object get() throws IllegalAccessException {
if (field == null) return null;
return field.get(parent);
}