aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorisXander <xander@isxander.dev>2023-04-04 11:19:55 +0100
committerisXander <xander@isxander.dev>2023-04-04 11:19:55 +0100
commit10bd86f0be7e5544e354fbb946962e25da413db9 (patch)
treea7496e6cd730a17c6123eb4a226b06f98dcfec15 /src
parent305a723374e2bd730a181798dfd90f7eb5fb70ac (diff)
downloadYetAnotherConfigLib-10bd86f0be7e5544e354fbb946962e25da413db9.tar.gz
YetAnotherConfigLib-10bd86f0be7e5544e354fbb946962e25da413db9.tar.bz2
YetAnotherConfigLib-10bd86f0be7e5544e354fbb946962e25da413db9.zip
🐛 Fix ListOption.Builder not having listener methods
Diffstat (limited to 'src')
-rw-r--r--src/client/java/dev/isxander/yacl/api/ListOption.java15
-rw-r--r--src/client/java/dev/isxander/yacl/impl/ListOptionImpl.java18
2 files changed, 31 insertions, 2 deletions
diff --git a/src/client/java/dev/isxander/yacl/api/ListOption.java b/src/client/java/dev/isxander/yacl/api/ListOption.java
index adbdc29..afba8ee 100644
--- a/src/client/java/dev/isxander/yacl/api/ListOption.java
+++ b/src/client/java/dev/isxander/yacl/api/ListOption.java
@@ -7,6 +7,7 @@ import org.jetbrains.annotations.ApiStatus;
import org.jetbrains.annotations.NotNull;
import java.util.*;
+import java.util.function.BiConsumer;
import java.util.function.Consumer;
import java.util.function.Function;
import java.util.function.Supplier;
@@ -132,6 +133,20 @@ public interface ListOption<T> extends OptionGroup, Option<List<T>> {
*/
Builder<T> collapsed(boolean collapsible);
+ /**
+ * Adds a listener to the option. Invoked upon changing any of the list's entries.
+ *
+ * @see Option#addListener(BiConsumer)
+ */
+ ListOption.Builder<T> listener(@NotNull BiConsumer<Option<List<T>>, List<T>> listener);
+
+ /**
+ * Adds multiple listeners to the option. Invoked upon changing of any of the list's entries.
+ *
+ * @see Option#addListener(BiConsumer)
+ */
+ ListOption.Builder<T> listeners(@NotNull Collection<BiConsumer<Option<List<T>>, List<T>>> listeners);
+
ListOption<T> build();
}
}
diff --git a/src/client/java/dev/isxander/yacl/impl/ListOptionImpl.java b/src/client/java/dev/isxander/yacl/impl/ListOptionImpl.java
index e7230b0..27e90ad 100644
--- a/src/client/java/dev/isxander/yacl/impl/ListOptionImpl.java
+++ b/src/client/java/dev/isxander/yacl/impl/ListOptionImpl.java
@@ -31,7 +31,7 @@ public final class ListOptionImpl<T> implements ListOption<T> {
private final List<BiConsumer<Option<List<T>>, List<T>>> listeners;
private final List<Runnable> refreshListeners;
- public ListOptionImpl(@NotNull Component name, @NotNull Component tooltip, @NotNull Binding<List<T>> binding, @NotNull T initialValue, @NotNull Class<T> typeClass, @NotNull Function<ListOptionEntry<T>, Controller<T>> controllerFunction, ImmutableSet<OptionFlag> flags, boolean collapsed, boolean available) {
+ public ListOptionImpl(@NotNull Component name, @NotNull Component tooltip, @NotNull Binding<List<T>> binding, @NotNull T initialValue, @NotNull Class<T> typeClass, @NotNull Function<ListOptionEntry<T>, Controller<T>> controllerFunction, ImmutableSet<OptionFlag> flags, boolean collapsed, boolean available, Collection<BiConsumer<Option<List<T>>, List<T>>> listeners) {
this.name = name;
this.tooltip = tooltip;
this.binding = binding;
@@ -43,6 +43,7 @@ public final class ListOptionImpl<T> implements ListOption<T> {
this.flags = flags;
this.available = available;
this.listeners = new ArrayList<>();
+ this.listeners.addAll(listeners);
this.refreshListeners = new ArrayList<>();
callListeners();
}
@@ -219,6 +220,7 @@ public final class ListOptionImpl<T> implements ListOption<T> {
private T initialValue;
private boolean collapsed = false;
private boolean available = true;
+ private final List<BiConsumer<Option<List<T>>, List<T>>> listeners = new ArrayList<>();
private final Class<T> typeClass;
public BuilderImpl(Class<T> typeClass) {
@@ -304,6 +306,18 @@ public final class ListOptionImpl<T> implements ListOption<T> {
}
@Override
+ public ListOption.Builder<T> listener(@NotNull BiConsumer<Option<List<T>>, List<T>> listener) {
+ this.listeners.add(listener);
+ return this;
+ }
+
+ @Override
+ public ListOption.Builder<T> listeners(@NotNull Collection<BiConsumer<Option<List<T>>, List<T>>> listeners) {
+ this.listeners.addAll(listeners);
+ return this;
+ }
+
+ @Override
public ListOption<T> build() {
Validate.notNull(controllerFunction, "`controller` must not be null");
Validate.notNull(binding, "`binding` must not be null");
@@ -318,7 +332,7 @@ public final class ListOptionImpl<T> implements ListOption<T> {
concatenatedTooltip.append(line);
}
- return new ListOptionImpl<>(name, concatenatedTooltip, binding, initialValue, typeClass, controllerFunction, ImmutableSet.copyOf(flags), collapsed, available);
+ return new ListOptionImpl<>(name, concatenatedTooltip, binding, initialValue, typeClass, controllerFunction, ImmutableSet.copyOf(flags), collapsed, available, listeners);
}
}
}