aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--gradle.properties2
-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
3 files changed, 30 insertions, 2 deletions
diff --git a/gradle.properties b/gradle.properties
index 5ce40ae..0d10386 100644
--- a/gradle.properties
+++ b/gradle.properties
@@ -1,6 +1,6 @@
mod_name = OneConfig
mod_id = oneconfig
-mod_version = 0.1.0-alpha1
+mod_version = 0.1.0-alpha2
loom.platform = forge
essential.defaults.loom=0
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);
}