diff --git a/src/main/java/dev/isxander/yacl3/api/ConfigCategory.java b/src/main/java/dev/isxander/yacl3/api/ConfigCategory.java index 41f3ca9..cd6da8f 100644 --- a/src/main/java/dev/isxander/yacl3/api/ConfigCategory.java +++ b/src/main/java/dev/isxander/yacl3/api/ConfigCategory.java @@ -75,7 +75,7 @@ default Builder option(@NotNull Supplier<@NotNull Option> optionSupplier) { * 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 condition whether to add the option * @return this */ @Override @@ -89,8 +89,8 @@ default Builder optionIf(boolean condition, @NotNull Option option) { * 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 + * @param condition whether to add the option + * @param optionSupplier to be called to initialise the option. called immediately if and only if condition is true * @return this */ @Override @@ -117,6 +117,40 @@ default Builder optionIf(boolean condition, @NotNull Supplier<@NotNull Option */ Builder group(@NotNull OptionGroup group); + /** + * Adds an option group. + * To add an option to the root group, use {@link Builder#option(Option)} + * To construct a group, use {@link OptionGroup#createBuilder()} + * + * @param groupSupplier to be called to initialise the group. called immediately + */ + default Builder group(@NotNull Supplier<@NotNull OptionGroup> groupSupplier) { + return group(groupSupplier.get()); + } + + /** + * Adds an option group if a condition is met. + * To add an option to the root group, use {@link Builder#optionIf(boolean, Option)}. + * To construct a group, use {@link OptionGroup#createBuilder()} + * + * @param condition whether to add the group + */ + default Builder groupIf(boolean condition, @NotNull OptionGroup group) { + return condition ? group(group) : this; + } + + /** + * Adds an option group if a condition is met. + * To add an option to the root group, use {@link Builder#optionIf(boolean, Option)}. + * To construct a group, use {@link OptionGroup#createBuilder()} + * + * @param condition whether to add the group + * @param groupSupplier to be called to initialise the group. called immediately if and only if condition is true + */ + default Builder groupIf(boolean condition, @NotNull Supplier<@NotNull OptionGroup> groupSupplier) { + return condition ? group(groupSupplier) : this; + } + /** * Adds multiple option groups. * To add multiple options to the root group, use {@link Builder#options(Collection)} diff --git a/src/main/java/dev/isxander/yacl3/api/OptionAddable.java b/src/main/java/dev/isxander/yacl3/api/OptionAddable.java index 606e8ca..5c4cff5 100644 --- a/src/main/java/dev/isxander/yacl3/api/OptionAddable.java +++ b/src/main/java/dev/isxander/yacl3/api/OptionAddable.java @@ -24,7 +24,7 @@ default OptionAddable option(@NotNull Supplier<@NotNull Option> optionSupplie /** * 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 condition whether to add the option * @param option the option to add * @return this */ @@ -35,8 +35,8 @@ default OptionAddable optionIf(boolean condition, @NotNull Option option) { /** * 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 + * @param condition whether to add the option + * @param optionSupplier to be called to initialise the option. called immediately if and only if condition is true * @return this */ default OptionAddable optionIf(boolean condition, @NotNull Supplier<@NotNull Option> optionSupplier) {