Skip to content

Commit 570b7e9

Browse files
committed
feat: allow setting null option values to clear any set state
1 parent abac15b commit 570b7e9

File tree

2 files changed

+8
-7
lines changed

2 files changed

+8
-7
lines changed

src/main/java/net/kyori/option/OptionState.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ interface Builder {
142142
* @param <V> the value type
143143
* @since 1.0.0
144144
*/
145-
<V> Builder value(final Option<V> option, final V value);
145+
<V> Builder value(final Option<V> option, final @Nullable V value);
146146

147147
/**
148148
* Apply all values from the existing option state.

src/main/java/net/kyori/option/OptionStateImpl.java

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -176,15 +176,16 @@ public OptionState build() {
176176
}
177177

178178
@Override
179-
public <V> Builder value(final Option<V> option, final V value) {
180-
if (!this.schema.has(option)) {
179+
public <V> Builder value(final Option<V> option, final @Nullable V value) {
180+
if (!this.schema.has(requireNonNull(option, "option"))) {
181181
throw new IllegalStateException("Option '" + option.id() + "' was not present in active schema");
182182
}
183183

184-
this.values.put(
185-
requireNonNull(option, "flag"),
186-
requireNonNull(value, "value")
187-
);
184+
if (value == null) {
185+
this.values.remove(option);
186+
} else {
187+
this.values.put(option, value);
188+
}
188189
return this;
189190
}
190191

0 commit comments

Comments
 (0)