Skip to content

Commit 4d215fe

Browse files
Add more option ifs (#286)
1 parent 7786fba commit 4d215fe

3 files changed

Lines changed: 58 additions & 2 deletions

File tree

src/main/java/dev/isxander/yacl3/api/ConfigCategory.java

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,12 +104,29 @@ default Builder optionIf(boolean condition, @NotNull Supplier<@NotNull Option<?>
104104
* To add to another group, use {@link Builder#groups(Collection)}.
105105
* To construct an option, use {@link Option#createBuilder()}
106106
*
107+
* @param options the options to add
107108
* @see ConfigCategory#groups()
108109
* @see OptionGroup#isRoot()
109110
*/
110111
@Override
111112
Builder options(@NotNull Collection<? extends Option<?>> options);
112113

114+
/**
115+
* Adds multiple options to the root group of the category if a condition is met.
116+
* To add to another group, use {@link Builder#groups(Collection)}.
117+
* To construct an option, use {@link Option#createBuilder()}
118+
*
119+
* @param condition whether to add the options
120+
* @param options the options to add
121+
* @see ConfigCategory#groups()
122+
* @see OptionGroup#isRoot()
123+
*/
124+
@Override
125+
default Builder optionsIf(boolean condition, @NotNull Collection<? extends Option<?>> options) {
126+
OptionAddable.super.optionsIf(condition, options);
127+
return this;
128+
}
129+
113130
/**
114131
* Adds an option group.
115132
* To add an option to the root group, use {@link Builder#option(Option)}
@@ -155,9 +172,23 @@ default Builder groupIf(boolean condition, @NotNull Supplier<@NotNull OptionGrou
155172
* Adds multiple option groups.
156173
* To add multiple options to the root group, use {@link Builder#options(Collection)}
157174
* To construct a group, use {@link OptionGroup#createBuilder()}
175+
*
176+
* @param groups the groups to add
158177
*/
159178
Builder groups(@NotNull Collection<OptionGroup> groups);
160179

180+
/**
181+
* Adds multiple option groups if a condition is met.
182+
* To add multiple options to the root group, use {@link Builder#optionsIf(boolean, Collection)}
183+
* To construct a group, use {@link OptionGroup#createBuilder()}
184+
*
185+
* @param condition whether to add the groups
186+
* @param groups the groups to add
187+
*/
188+
default Builder groupsIf(boolean condition, @NotNull Collection<OptionGroup> groups) {
189+
return condition ? groups(groups) : this;
190+
}
191+
161192
/**
162193
* Fetches the builder for the root group of the category.
163194
* This is the group that has no header and options are added through {@link Builder#option(Option)}.

src/main/java/dev/isxander/yacl3/api/OptionAddable.java

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,19 @@ default OptionAddable optionIf(boolean condition, @NotNull Supplier<@NotNull Opt
4646
/**
4747
* Adds multiple options to an abstract builder.
4848
* To construct an option, use {@link Option#createBuilder()}
49+
* @param options the options to add
50+
* @return this
4951
*/
5052
OptionAddable options(@NotNull Collection<? extends Option<?>> options);
53+
54+
/**
55+
* Adds multiple options to an abstract builder if a condition is met.
56+
* To construct an option, use {@link Option#createBuilder()}
57+
* @param condition whether to add the options
58+
* @param options the options to add
59+
* @return this
60+
*/
61+
default OptionAddable optionsIf(boolean condition, @NotNull Collection<? extends Option<?>> options) {
62+
return condition ? options(options) : this;
63+
}
5164
}

src/main/java/dev/isxander/yacl3/api/OptionGroup.java

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ interface Builder extends OptionAddable {
6363

6464
/**
6565
* Adds an option to group.
66-
* To construct an option, use {@link Option#createBuilder(Class)}
66+
* To construct an option, use {@link Option#createBuilder()}
6767
*
6868
* @see OptionGroup#options()
6969
*/
@@ -111,14 +111,26 @@ default Builder optionIf(boolean condition, @NotNull Supplier<@NotNull Option<?>
111111
}
112112

113113
/**
114-
* Adds multiple options to group.
114+
* Adds multiple options to this group.
115115
* To construct an option, use {@link Option#createBuilder()}
116116
*
117117
* @see OptionGroup#options()
118118
*/
119119
@Override
120120
Builder options(@NotNull Collection<? extends Option<?>> options);
121121

122+
/**
123+
* Adds multiple options to this group if a condition is met.
124+
* To construct an option, use {@link Option#createBuilder()}
125+
*
126+
* @see OptionGroup#options()
127+
*/
128+
@Override
129+
default Builder optionsIf(boolean condition, @NotNull Collection<? extends Option<?>> options) {
130+
OptionAddable.super.optionsIf(condition, options);
131+
return this;
132+
}
133+
122134
/**
123135
* Dictates if the group should be collapsed by default
124136
*

0 commit comments

Comments
 (0)