aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--common/src/main/java/dev/isxander/yacl3/api/ConfigCategory.java48
-rw-r--r--common/src/main/java/dev/isxander/yacl3/api/OptionAddable.java36
-rw-r--r--common/src/main/java/dev/isxander/yacl3/api/OptionGroup.java43
3 files changed, 122 insertions, 5 deletions
diff --git a/common/src/main/java/dev/isxander/yacl3/api/ConfigCategory.java b/common/src/main/java/dev/isxander/yacl3/api/ConfigCategory.java
index d47b3ce..b3d68fc 100644
--- a/common/src/main/java/dev/isxander/yacl3/api/ConfigCategory.java
+++ b/common/src/main/java/dev/isxander/yacl3/api/ConfigCategory.java
@@ -6,6 +6,7 @@ import net.minecraft.network.chat.Component;
import org.jetbrains.annotations.NotNull;
import java.util.Collection;
+import java.util.function.Supplier;
/**
* Separates {@link Option}s or {@link OptionGroup}s into multiple distinct sections.
@@ -47,7 +48,7 @@ public interface ConfigCategory {
/**
* Adds an option to the root group of the category.
* To add to another group, use {@link Builder#group(OptionGroup)}.
- * To construct an option, use {@link Option#createBuilder(Class)}
+ * To construct an option, use {@link Option#createBuilder()}
*
* @see ConfigCategory#groups()
* @see OptionGroup#isRoot()
@@ -56,9 +57,52 @@ public interface ConfigCategory {
Builder option(@NotNull Option<?> option);
/**
+ * Adds an option to the root group of the category.
+ * To add to another group, use {@link Builder#group(OptionGroup)}.
+ * To construct an option, use {@link Option#createBuilder()}
+ *
+ * @param optionSupplier to be called to initialise the option. called immediately
+ * @return this
+ */
+ @Override
+ default Builder option(@NotNull Supplier<@NotNull Option<?>> optionSupplier) {
+ OptionAddable.super.option(optionSupplier);
+ return this;
+ }
+
+ /**
+ * Adds an option to the root group of the category if a condition is met.
+ * To add to another group, use {@link Builder#group(OptionGroup)}.
+ * To construct an option, use {@link Option#createBuilder()}
+ *
+ * @param condition only if true is the option added
+ * @return this
+ */
+ @Override
+ default Builder optionIf(boolean condition, @NotNull Option<?> option) {
+ OptionAddable.super.optionIf(condition, option);
+ return this;
+ }
+
+ /**
+ * Adds an option to the root group of the category if a condition is met.
+ * To add to another group, use {@link Builder#group(OptionGroup)}.
+ * To construct an option, use {@link Option#createBuilder()}
+ *
+ * @param condition only if true is the option added
+ * @param optionSupplier to be called to initialise the option. called immediately only if condition is true
+ * @return this
+ */
+ @Override
+ default Builder optionIf(boolean condition, @NotNull Supplier<@NotNull Option<?>> optionSupplier) {
+ OptionAddable.super.optionIf(condition, optionSupplier);
+ return this;
+ }
+
+ /**
* Adds multiple options to the root group of the category.
* To add to another group, use {@link Builder#groups(Collection)}.
- * To construct an option, use {@link Option#createBuilder(Class)}
+ * To construct an option, use {@link Option#createBuilder()}
*
* @see ConfigCategory#groups()
* @see OptionGroup#isRoot()
diff --git a/common/src/main/java/dev/isxander/yacl3/api/OptionAddable.java b/common/src/main/java/dev/isxander/yacl3/api/OptionAddable.java
index 97ab352..606e8ca 100644
--- a/common/src/main/java/dev/isxander/yacl3/api/OptionAddable.java
+++ b/common/src/main/java/dev/isxander/yacl3/api/OptionAddable.java
@@ -3,17 +3,49 @@ package dev.isxander.yacl3.api;
import org.jetbrains.annotations.NotNull;
import java.util.Collection;
+import java.util.function.Supplier;
public interface OptionAddable {
/**
* Adds an option to an abstract builder.
- * To construct an option, use {@link Option#createBuilder(Class)}
+ * To construct an option, use {@link Option#createBuilder()}
*/
OptionAddable option(@NotNull Option<?> option);
/**
+ * Adds an option to an abstract builder.
+ * To construct an option, use {@link Option#createBuilder()}
+ * @param optionSupplier to be called to initialise the option. called immediately
+ */
+ default OptionAddable option(@NotNull Supplier<@NotNull Option<?>> optionSupplier) {
+ return option(optionSupplier.get());
+ }
+
+ /**
+ * Adds an option to an abstract builder if a condition is met.
+ * To construct an option, use {@link Option#createBuilder()}
+ * @param condition only if true is the option added
+ * @param option the option to add
+ * @return this
+ */
+ default OptionAddable optionIf(boolean condition, @NotNull Option<?> option) {
+ return condition ? option(option) : this;
+ }
+
+ /**
+ * Adds an option to an abstract builder if a condition is met.
+ * To construct an option, use {@link Option#createBuilder()}
+ * @param condition only if true is the option added
+ * @param optionSupplier to be called to initialise the option. called immediately only if condition is true
+ * @return this
+ */
+ default OptionAddable optionIf(boolean condition, @NotNull Supplier<@NotNull Option<?>> optionSupplier) {
+ return condition ? option(optionSupplier) : this;
+ }
+
+ /**
* Adds multiple options to an abstract builder.
- * To construct an option, use {@link Option#createBuilder(Class)}
+ * To construct an option, use {@link Option#createBuilder()}
*/
OptionAddable options(@NotNull Collection<? extends Option<?>> options);
}
diff --git a/common/src/main/java/dev/isxander/yacl3/api/OptionGroup.java b/common/src/main/java/dev/isxander/yacl3/api/OptionGroup.java
index ff31966..8f183b9 100644
--- a/common/src/main/java/dev/isxander/yacl3/api/OptionGroup.java
+++ b/common/src/main/java/dev/isxander/yacl3/api/OptionGroup.java
@@ -6,6 +6,7 @@ import net.minecraft.network.chat.Component;
import org.jetbrains.annotations.NotNull;
import java.util.Collection;
+import java.util.function.Supplier;
/**
* Serves as a separator between multiple chunks of options
@@ -70,8 +71,48 @@ public interface OptionGroup {
Builder option(@NotNull Option<?> option);
/**
+ * Adds an option to this group.
+ * To construct an option, use {@link Option#createBuilder()}
+ *
+ * @param optionSupplier to be called to initialise the option. called immediately
+ * @return this
+ */
+ @Override
+ default Builder option(@NotNull Supplier<@NotNull Option<?>> optionSupplier) {
+ OptionAddable.super.option(optionSupplier);
+ return this;
+ }
+
+ /**
+ * Adds an option to this group if a condition is met.
+ * To construct an option, use {@link Option#createBuilder()}
+ *
+ * @param condition only if true is the option added
+ * @return this
+ */
+ @Override
+ default Builder optionIf(boolean condition, @NotNull Option<?> option) {
+ OptionAddable.super.optionIf(condition, option);
+ return this;
+ }
+
+ /**
+ * Adds an option to this group if a condition is met.
+ * To construct an option, use {@link Option#createBuilder()}
+ *
+ * @param condition only if true is the option added
+ * @param optionSupplier to be called to initialise the option. called immediately only if condition is true
+ * @return this
+ */
+ @Override
+ default Builder optionIf(boolean condition, @NotNull Supplier<@NotNull Option<?>> optionSupplier) {
+ OptionAddable.super.optionIf(condition, optionSupplier);
+ return this;
+ }
+
+ /**
* Adds multiple options to group.
- * To construct an option, use {@link Option#createBuilder(Class)}
+ * To construct an option, use {@link Option#createBuilder()}
*
* @see OptionGroup#options()
*/