diff options
author | isXander <isxander@users.noreply.github.com> | 2022-09-18 22:25:56 +0100 |
---|---|---|
committer | isXander <isxander@users.noreply.github.com> | 2022-09-18 22:25:56 +0100 |
commit | 4936ff3f170a4dba808e41169bf13cfa046f0769 (patch) | |
tree | 6e790de73fee90fc7d85d2354a90133593b54442 /src/main/java | |
parent | 405576acaa6e4a9887040a296f8988422351ea3e (diff) | |
download | YetAnotherConfigLib-4936ff3f170a4dba808e41169bf13cfa046f0769.tar.gz YetAnotherConfigLib-4936ff3f170a4dba808e41169bf13cfa046f0769.tar.bz2 YetAnotherConfigLib-4936ff3f170a4dba808e41169bf13cfa046f0769.zip |
instant application property
Diffstat (limited to 'src/main/java')
-rw-r--r-- | src/main/java/dev/isxander/yacl/api/Option.java | 20 |
1 files changed, 19 insertions, 1 deletions
diff --git a/src/main/java/dev/isxander/yacl/api/Option.java b/src/main/java/dev/isxander/yacl/api/Option.java index b17743e..1df90a8 100644 --- a/src/main/java/dev/isxander/yacl/api/Option.java +++ b/src/main/java/dev/isxander/yacl/api/Option.java @@ -123,6 +123,8 @@ public interface Option<T> { private boolean available = true; + private boolean instant = false; + private final Set<OptionFlag> flags = new HashSet<>(); private final Class<T> typeClass; @@ -250,6 +252,17 @@ public interface Option<T> { } /** + * Instantly invokes the binder's setter when modified in the GUI. + * Prevents the user from undoing the change + * <p> + * Does not support {@link Option#flags()}! + */ + public Builder<T> instant(boolean instant) { + this.instant = instant; + return this; + } + + /** * Dictates whether the option should require a restart. * {@link Option#requiresRestart()} */ @@ -264,6 +277,7 @@ public interface Option<T> { public Option<T> build() { Validate.notNull(controlGetter, "`control` must not be null when building `Option`"); Validate.notNull(binding, "`binding` must not be null when building `Option`"); + Validate.isTrue(!instant || flags.isEmpty(), "instant application does not support option flags"); Function<T, Text> concatenatedTooltipGetter = value -> { MutableText concatenatedTooltip = Text.empty(); @@ -278,7 +292,11 @@ public interface Option<T> { return concatenatedTooltip; }; - return new OptionImpl<>(name, concatenatedTooltipGetter, controlGetter, binding, available, ImmutableSet.copyOf(flags), typeClass); + OptionImpl<T> option = new OptionImpl<>(name, concatenatedTooltipGetter, controlGetter, binding, available, ImmutableSet.copyOf(flags), typeClass); + if (instant) { + option.addListener((opt, pendingValue) -> opt.applyValue()); + } + return option; } } } |