aboutsummaryrefslogtreecommitdiff
path: root/src/main/java
diff options
context:
space:
mode:
authorDeDiamondPro <67508414+DeDiamondPro@users.noreply.github.com>2022-06-10 20:35:35 +0200
committerDeDiamondPro <67508414+DeDiamondPro@users.noreply.github.com>2022-06-10 20:35:35 +0200
commitff3cfeefce2304cd52f6baa3aeea8069602a6176 (patch)
tree18b8b9ad4a5c5312dc12eddf2002d901635b7a42 /src/main/java
parent8f3d048dae3269034e4a1685eb4432b268a84880 (diff)
downloadOneConfig-ff3cfeefce2304cd52f6baa3aeea8069602a6176.tar.gz
OneConfig-ff3cfeefce2304cd52f6baa3aeea8069602a6176.tar.bz2
OneConfig-ff3cfeefce2304cd52f6baa3aeea8069602a6176.zip
more dependency options
Diffstat (limited to 'src/main/java')
-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);
}