Skip to content

Commit

Permalink
Add groupIf to ConfigCategory.Builder (#215)
Browse files Browse the repository at this point in the history
  • Loading branch information
kevinthegreat1 authored Oct 26, 2024
1 parent de5b98f commit 2dd1b1f
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 6 deletions.
40 changes: 37 additions & 3 deletions src/main/java/dev/isxander/yacl3/api/ConfigCategory.java
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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)}
Expand Down
6 changes: 3 additions & 3 deletions src/main/java/dev/isxander/yacl3/api/OptionAddable.java
Original file line number Diff line number Diff line change
Expand Up @@ -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
*/
Expand All @@ -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) {
Expand Down

0 comments on commit 2dd1b1f

Please sign in to comment.