aboutsummaryrefslogtreecommitdiff
path: root/src/client/java/dev/isxander/yacl/impl
diff options
context:
space:
mode:
Diffstat (limited to 'src/client/java/dev/isxander/yacl/impl')
-rw-r--r--src/client/java/dev/isxander/yacl/impl/ButtonOptionImpl.java218
-rw-r--r--src/client/java/dev/isxander/yacl/impl/ConfigCategoryImpl.java137
-rw-r--r--src/client/java/dev/isxander/yacl/impl/GenericBindingImpl.java35
-rw-r--r--src/client/java/dev/isxander/yacl/impl/LabelOptionImpl.java154
-rw-r--r--src/client/java/dev/isxander/yacl/impl/ListOptionEntryImpl.java149
-rw-r--r--src/client/java/dev/isxander/yacl/impl/ListOptionImpl.java338
-rw-r--r--src/client/java/dev/isxander/yacl/impl/OptionGroupImpl.java129
-rw-r--r--src/client/java/dev/isxander/yacl/impl/OptionImpl.java304
-rw-r--r--src/client/java/dev/isxander/yacl/impl/PlaceholderCategoryImpl.java99
-rw-r--r--src/client/java/dev/isxander/yacl/impl/YetAnotherConfigLibImpl.java122
10 files changed, 0 insertions, 1685 deletions
diff --git a/src/client/java/dev/isxander/yacl/impl/ButtonOptionImpl.java b/src/client/java/dev/isxander/yacl/impl/ButtonOptionImpl.java
deleted file mode 100644
index 33cb474..0000000
--- a/src/client/java/dev/isxander/yacl/impl/ButtonOptionImpl.java
+++ /dev/null
@@ -1,218 +0,0 @@
-package dev.isxander.yacl.impl;
-
-import com.google.common.collect.ImmutableSet;
-import dev.isxander.yacl.api.*;
-import dev.isxander.yacl.gui.YACLScreen;
-import net.minecraft.network.chat.Component;
-import net.minecraft.network.chat.MutableComponent;
-import org.apache.commons.lang3.Validate;
-import org.jetbrains.annotations.ApiStatus;
-import org.jetbrains.annotations.NotNull;
-import org.jetbrains.annotations.Nullable;
-
-import java.util.ArrayList;
-import java.util.List;
-import java.util.function.BiConsumer;
-import java.util.function.Consumer;
-import java.util.function.Function;
-
-@ApiStatus.Internal
-public final class ButtonOptionImpl implements ButtonOption {
- private final Component name;
- private final Component tooltip;
- private final BiConsumer<YACLScreen, ButtonOption> action;
- private boolean available;
- private final Controller<BiConsumer<YACLScreen, ButtonOption>> controller;
- private final Binding<BiConsumer<YACLScreen, ButtonOption>> binding;
-
- public ButtonOptionImpl(
- @NotNull Component name,
- @Nullable Component tooltip,
- @NotNull BiConsumer<YACLScreen, ButtonOption> action,
- boolean available,
- @NotNull Function<ButtonOption, Controller<BiConsumer<YACLScreen, ButtonOption>>> controlGetter
- ) {
- this.name = name;
- this.tooltip = tooltip;
- this.action = action;
- this.available = available;
- this.controller = controlGetter.apply(this);
- this.binding = new EmptyBinderImpl();
- }
-
- @Override
- public @NotNull Component name() {
- return name;
- }
-
- @Override
- public @NotNull Component tooltip() {
- return tooltip;
- }
-
- @Override
- public BiConsumer<YACLScreen, ButtonOption> action() {
- return action;
- }
-
- @Override
- public boolean available() {
- return available;
- }
-
- @Override
- public void setAvailable(boolean available) {
- this.available = available;
- }
-
- @Override
- public @NotNull Controller<BiConsumer<YACLScreen, ButtonOption>> controller() {
- return controller;
- }
-
- @Override
- public @NotNull Binding<BiConsumer<YACLScreen, ButtonOption>> binding() {
- return binding;
- }
-
- @Override
- public @NotNull Class<BiConsumer<YACLScreen, ButtonOption>> typeClass() {
- throw new UnsupportedOperationException();
- }
-
- @Override
- public @NotNull ImmutableSet<OptionFlag> flags() {
- return ImmutableSet.of();
- }
-
- @Override
- public boolean changed() {
- return false;
- }
-
- @Override
- public @NotNull BiConsumer<YACLScreen, ButtonOption> pendingValue() {
- throw new UnsupportedOperationException();
- }
-
- @Override
- public void requestSet(BiConsumer<YACLScreen, ButtonOption> value) {
- throw new UnsupportedOperationException();
- }
-
- @Override
- public boolean applyValue() {
- return false;
- }
-
- @Override
- public void forgetPendingValue() {
-
- }
-
- @Override
- public void requestSetDefault() {
-
- }
-
- @Override
- public boolean isPendingValueDefault() {
- throw new UnsupportedOperationException();
- }
-
- @Override
- public void addListener(BiConsumer<Option<BiConsumer<YACLScreen, ButtonOption>>, BiConsumer<YACLScreen, ButtonOption>> changedListener) {
-
- }
-
- private static class EmptyBinderImpl implements Binding<BiConsumer<YACLScreen, ButtonOption>> {
- @Override
- public void setValue(BiConsumer<YACLScreen, ButtonOption> value) {
-
- }
-
- @Override
- public BiConsumer<YACLScreen, ButtonOption> getValue() {
- throw new UnsupportedOperationException();
- }
-
- @Override
- public BiConsumer<YACLScreen, ButtonOption> defaultValue() {
- throw new UnsupportedOperationException();
- }
- }
-
- @ApiStatus.Internal
- public static final class BuilderImpl implements ButtonOption.Builder {
- private Component name;
- private final List<Component> tooltipLines = new ArrayList<>();
- private boolean available = true;
- private Function<ButtonOption, Controller<BiConsumer<YACLScreen, ButtonOption>>> controlGetter;
- private BiConsumer<YACLScreen, ButtonOption> action;
-
- @Override
- public ButtonOption.Builder name(@NotNull Component name) {
- Validate.notNull(name, "`name` cannot be null");
-
- this.name = name;
- return this;
- }
-
- @Override
- public ButtonOption.Builder tooltip(@NotNull Component... tooltips) {
- Validate.notNull(tooltips, "`tooltips` cannot be empty");
-
- tooltipLines.addAll(List.of(tooltips));
- return this;
- }
-
- @Override
- public ButtonOption.Builder action(@NotNull BiConsumer<YACLScreen, ButtonOption> action) {
- Validate.notNull(action, "`action` cannot be null");
-
- this.action = action;
- return this;
- }
-
- @Override
- @Deprecated
- public ButtonOption.Builder action(@NotNull Consumer<YACLScreen> action) {
- Validate.notNull(action, "`action` cannot be null");
-
- this.action = (screen, button) -> action.accept(screen);
- return this;
- }
-
- @Override
- public ButtonOption.Builder available(boolean available) {
- this.available = available;
- return this;
- }
-
- @Override
- public ButtonOption.Builder controller(@NotNull Function<ButtonOption, Controller<BiConsumer<YACLScreen, ButtonOption>>> control) {
- Validate.notNull(control, "`control` cannot be null");
-
- this.controlGetter = control;
- return this;
- }
-
- @Override
- public ButtonOption build() {
- Validate.notNull(name, "`name` must not be null when building `Option`");
- Validate.notNull(controlGetter, "`control` must not be null when building `Option`");
- Validate.notNull(action, "`action` must not be null when building `Option`");
-
- MutableComponent concatenatedTooltip = Component.empty();
- boolean first = true;
- for (Component line : tooltipLines) {
- if (!first) concatenatedTooltip.append("\n");
- first = false;
-
- concatenatedTooltip.append(line);
- }
-
- return new ButtonOptionImpl(name, concatenatedTooltip, action, available, controlGetter);
- }
- }
-}
diff --git a/src/client/java/dev/isxander/yacl/impl/ConfigCategoryImpl.java b/src/client/java/dev/isxander/yacl/impl/ConfigCategoryImpl.java
deleted file mode 100644
index 2d39eb9..0000000
--- a/src/client/java/dev/isxander/yacl/impl/ConfigCategoryImpl.java
+++ /dev/null
@@ -1,137 +0,0 @@
-package dev.isxander.yacl.impl;
-
-import com.google.common.collect.ImmutableList;
-import dev.isxander.yacl.api.ConfigCategory;
-import dev.isxander.yacl.api.ListOption;
-import dev.isxander.yacl.api.Option;
-import dev.isxander.yacl.api.OptionGroup;
-import dev.isxander.yacl.impl.utils.YACLConstants;
-import net.minecraft.network.chat.Component;
-import net.minecraft.network.chat.ComponentContents;
-import net.minecraft.network.chat.MutableComponent;
-import org.apache.commons.lang3.Validate;
-import org.jetbrains.annotations.ApiStatus;
-import org.jetbrains.annotations.NotNull;
-
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.List;
-
-@ApiStatus.Internal
-public final class ConfigCategoryImpl implements ConfigCategory {
- private final Component name;
- private final ImmutableList<OptionGroup> groups;
- private final Component tooltip;
-
- public ConfigCategoryImpl(Component name, ImmutableList<OptionGroup> groups, Component tooltip) {
- this.name = name;
- this.groups = groups;
- this.tooltip = tooltip;
- }
-
- @Override
- public @NotNull Component name() {
- return name;
- }
-
- @Override
- public @NotNull ImmutableList<OptionGroup> groups() {
- return groups;
- }
-
- @Override
- public @NotNull Component tooltip() {
- return tooltip;
- }
-
- @ApiStatus.Internal
- public static final class BuilderImpl implements Builder {
- private Component name;
-
- private final List<Option<?>> rootOptions = new ArrayList<>();
- private final List<OptionGroup> groups = new ArrayList<>();
-
- private final List<Component> tooltipLines = new ArrayList<>();
-
- @Override
- public Builder name(@NotNull Component name) {
- Validate.notNull(name, "`name` cannot be null");
-
- this.name = name;
- return this;
- }
-
- @Override
- public Builder option(@NotNull Option<?> option) {
- Validate.notNull(option, "`option` must not be null");
-
- if (option instanceof ListOption<?> listOption) {
- YACLConstants.LOGGER.warn("Adding list option as an option is not supported! Rerouting to group!");
- return group(listOption);
- }
-
- this.rootOptions.add(option);
- return this;
- }
-
- @Override
- public Builder options(@NotNull Collection<? extends Option<?>> options) {
- Validate.notNull(options, "`options` must not be null");
-
- if (options.stream().anyMatch(ListOption.class::isInstance))
- throw new UnsupportedOperationException("List options must not be added as an option but a group!");
-
- this.rootOptions.addAll(options);
- return this;
- }
-
- @Override
- public Builder group(@NotNull OptionGroup group) {
- Validate.notNull(group, "`group` must not be null");
-
- this.groups.add(group);
- return this;
- }
-
- @Override
- public Builder groups(@NotNull Collection<OptionGroup> groups) {
- Validate.notEmpty(groups, "`groups` must not be empty");
-
- this.groups.addAll(groups);
- return this;
- }
-
- @Override
- public Builder tooltip(@NotNull Component... tooltips) {
- Validate.notEmpty(tooltips, "`tooltips` cannot be empty");
-
- tooltipLines.addAll(List.of(tooltips));
- return this;
- }
-
- @Override
- public ConfigCategory build() {
- Validate.notNull(name, "`name` must not be null to build `ConfigCategory`");
-
- List<OptionGroup> combinedGroups = new ArrayList<>();
- combinedGroups.add(new OptionGroupImpl(Component.empty(), Component.empty(), ImmutableList.copyOf(rootOptions), false, true));
- combinedGroups.addAll(groups);
-
- Validate.notEmpty(combinedGroups, "at least one option must be added to build `ConfigCategory`");
-
- MutableComponent concatenatedTooltip = Component.empty();
- boolean first = true;
- for (Component line : tooltipLines) {
- if (line.getContents() == ComponentContents.EMPTY)
- continue;
-
- if (!first) concatenatedTooltip.append("\n");
- first = false;
-
- concatenatedTooltip.append(line);
- }
-
- return new ConfigCategoryImpl(name, ImmutableList.copyOf(combinedGroups), concatenatedTooltip);
- }
- }
-}
diff --git a/src/client/java/dev/isxander/yacl/impl/GenericBindingImpl.java b/src/client/java/dev/isxander/yacl/impl/GenericBindingImpl.java
deleted file mode 100644
index 0d668c6..0000000
--- a/src/client/java/dev/isxander/yacl/impl/GenericBindingImpl.java
+++ /dev/null
@@ -1,35 +0,0 @@
-package dev.isxander.yacl.impl;
-
-import dev.isxander.yacl.api.Binding;
-
-import java.util.function.Consumer;
-import java.util.function.Supplier;
-
-public final class GenericBindingImpl<T> implements Binding<T> {
- private final T def;
- private final Supplier<T> getter;
- private final Consumer<T> setter;
-
- public GenericBindingImpl(T def, Supplier<T> getter, Consumer<T> setting) {
- this.def = def;
- this.getter = getter;
- this.setter = setting;
- }
-
-
- @Override
- public void setValue(T value) {
- setter.accept(value);
- }
-
- @Override
- public T getValue() {
- return getter.get();
- }
-
- @Override
- public T defaultValue() {
- return def;
- }
-
-}
diff --git a/src/client/java/dev/isxander/yacl/impl/LabelOptionImpl.java b/src/client/java/dev/isxander/yacl/impl/LabelOptionImpl.java
deleted file mode 100644
index b6c3c09..0000000
--- a/src/client/java/dev/isxander/yacl/impl/LabelOptionImpl.java
+++ /dev/null
@@ -1,154 +0,0 @@
-package dev.isxander.yacl.impl;
-
-import com.google.common.collect.ImmutableSet;
-import dev.isxander.yacl.api.*;
-import dev.isxander.yacl.gui.controllers.LabelController;
-import net.minecraft.network.chat.Component;
-import net.minecraft.network.chat.MutableComponent;
-import org.apache.commons.lang3.Validate;
-import org.jetbrains.annotations.ApiStatus;
-import org.jetbrains.annotations.NotNull;
-
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.Iterator;
-import java.util.List;
-import java.util.function.BiConsumer;
-
-@ApiStatus.Internal
-public final class LabelOptionImpl implements LabelOption {
- private final Component label;
- private final Component name = Component.literal("Label Option");
- private final Component tooltip = Component.empty();
- private final LabelController labelController;
- private final Binding<Component> binding;
-
- public LabelOptionImpl(Component label) {
- this.label = label;
- this.labelController = new LabelController(this);
- this.binding = Binding.immutable(label);
- }
-
- @Override
- public @NotNull Component label() {
- return label;
- }
-
- @Override
- public @NotNull Component name() {
- return name;
- }
-
- @Override
- public @NotNull Component tooltip() {
- return tooltip;
- }
-
- @Override
- public @NotNull Controller<Component> controller() {
- return labelController;
- }
-
- @Override
- public @NotNull Binding<Component> binding() {
- return binding;
- }
-
- @Override
- public boolean available() {
- return true;
- }
-
- @Override
- public void setAvailable(boolean available) {
- throw new UnsupportedOperationException("Label options cannot be disabled.");
- }
-
- @Override
- public @NotNull Class<Component> typeClass() {
- return Component.class;
- }
-
- @Override
- public @NotNull ImmutableSet<OptionFlag> flags() {
- return ImmutableSet.of();
- }
-
- @Override
- public boolean changed() {
- return false;
- }
-
- @Override
- public @NotNull Component pendingValue() {
- return label;
- }
-
- @Override
- public void requestSet(Component value) {
-
- }
-
- @Override
- public boolean applyValue() {
- return false;
- }
-
- @Override
- public void forgetPendingValue() {
-
- }
-
- @Override
- public void requestSetDefault() {
-
- }
-
- @Override
- public boolean isPendingValueDefault() {
- return true;
- }
-
- @Override
- public boolean canResetToDefault() {
- return false;
- }
-
- @Override
- public void addListener(BiConsumer<Option<Component>, Component> changedListener) {
-
- }
-
- @ApiStatus.Internal
- public static final class BuilderImpl implements LabelOption.Builder {
- private final List<Component> lines = new ArrayList<>();
-
- @Override
- public dev.isxander.yacl.api.LabelOption.Builder line(@NotNull Component line) {
- Validate.notNull(line, "`line` must not be null");
-
- this.lines.add(line);
- return this;
- }
-
- @Override
- public dev.isxander.yacl.api.LabelOption.Builder lines(@NotNull Collection<? extends Component> lines) {
- this.lines.addAll(lines);
- return this;
- }
-
- @Override
- public LabelOption build() {
- MutableComponent text = Component.empty();
- Iterator<Component> iterator = lines.iterator();
- while (iterator.hasNext()) {
- text.append(iterator.next());
-
- if (iterator.hasNext())
- text.append("\n");
- }
-
- return new LabelOptionImpl(text);
- }
- }
-}
diff --git a/src/client/java/dev/isxander/yacl/impl/ListOptionEntryImpl.java b/src/client/java/dev/isxander/yacl/impl/ListOptionEntryImpl.java
deleted file mode 100644
index c15efe6..0000000
--- a/src/client/java/dev/isxander/yacl/impl/ListOptionEntryImpl.java
+++ /dev/null
@@ -1,149 +0,0 @@
-package dev.isxander.yacl.impl;
-
-import dev.isxander.yacl.api.*;
-import dev.isxander.yacl.api.utils.Dimension;
-import dev.isxander.yacl.gui.AbstractWidget;
-import dev.isxander.yacl.gui.YACLScreen;
-import dev.isxander.yacl.gui.controllers.ListEntryWidget;
-import net.minecraft.network.chat.Component;
-import org.jetbrains.annotations.ApiStatus;
-import org.jetbrains.annotations.NotNull;
-
-import java.util.function.BiConsumer;
-import java.util.function.Function;
-
-@ApiStatus.Internal
-public final class ListOptionEntryImpl<T> implements ListOptionEntry<T> {
- private final ListOptionImpl<T> group;
-
- private T value;
-
- private final Binding<T> binding;
- private final Controller<T> controller;
-
- ListOptionEntryImpl(ListOptionImpl<T> group, T initialValue, @NotNull Function<ListOptionEntry<T>, Controller<T>> controlGetter) {
- this.group = group;
- this.value = initialValue;
- this.binding = new EntryBinding();
- this.controller = new EntryController<>(controlGetter.apply(this), this);
- }
-
- @Override
- public @NotNull Component name() {
- return Component.empty();
- }
-
- @Override
- public @NotNull Component tooltip() {
- return Component.empty();
- }
-
- @Override
- public @NotNull Controller<T> controller() {
- return controller;
- }
-
- @Override
- public @NotNull Binding<T> binding() {
- return binding;
- }
-
- @Override
- public boolean available() {
- return parentGroup().available();
- }
-
- @Override
- public void setAvailable(boolean available) {
-
- }
-
- @Override
- public ListOption<T> parentGroup() {
- return group;
- }
-
- @Override
- public boolean changed() {
- return false;
- }
-
- @Override
- public @NotNull T pendingValue() {
- return value;
- }
-
- @Override
- public void requestSet(T value) {
- binding.setValue(value);
- }
-
- @Override
- public boolean applyValue() {
- return false;
- }
-
- @Override
- public void forgetPendingValue() {
-
- }
-
- @Override
- public void requestSetDefault() {
-
- }
-
- @Override
- public boolean isPendingValueDefault() {
- return false;
- }
-
- @Override
- public boolean canResetToDefault() {
- return false;
- }
-
- @Override
- public void addListener(BiConsumer<Option<T>, T> changedListener) {
-
- }
-
- /**
- * Open in case mods need to find the real controller type.
- */
- @ApiStatus.Internal
- public record EntryController<T>(Controller<T> controller, ListOptionEntryImpl<T> entry) implements Controller<T> {
- @Override
- public Option<T> option() {
- return controller.option();
- }
-
- @Override
- public Component formatValue() {
- return controller.formatValue();
- }
-
- @Override
- public AbstractWidget provideWidget(YACLScreen screen, Dimension<Integer> widgetDimension) {
- return new ListEntryWidget(screen, entry, controller.provideWidget(screen, widgetDimension));
- }
- }
-
- private class EntryBinding implements Binding<T> {
- @Override
- public void setValue(T newValue) {
- value = newValue;
- group.callListeners();
- }
-
- @Override
- public T getValue() {
- return value;
- }
-
- @Override
- public T defaultValue() {
- throw new UnsupportedOperationException();
- }
- }
-}
diff --git a/src/client/java/dev/isxander/yacl/impl/ListOptionImpl.java b/src/client/java/dev/isxander/yacl/impl/ListOptionImpl.java
deleted file mode 100644
index 27e90ad..0000000
--- a/src/client/java/dev/isxander/yacl/impl/ListOptionImpl.java
+++ /dev/null
@@ -1,338 +0,0 @@
-package dev.isxander.yacl.impl;
-
-import com.google.common.collect.ImmutableList;
-import com.google.common.collect.ImmutableSet;
-import dev.isxander.yacl.api.*;
-import net.minecraft.network.chat.Component;
-import net.minecraft.network.chat.MutableComponent;
-import org.apache.commons.lang3.Validate;
-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;
-import java.util.stream.Collectors;
-
-@ApiStatus.Internal
-public final class ListOptionImpl<T> implements ListOption<T> {
- private final Component name;
- private final Component tooltip;
- private final Binding<List<T>> binding;
- private final T initialValue;
- private final List<ListOptionEntry<T>> entries;
- private final boolean collapsed;
- private boolean available;
- private final Class<T> typeClass;
- private final ImmutableSet<OptionFlag> flags;
- private final EntryFactory entryFactory;
- 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, Collection<BiConsumer<Option<List<T>>, List<T>>> listeners) {
- this.name = name;
- this.tooltip = tooltip;
- this.binding = binding;
- this.initialValue = initialValue;
- this.entryFactory = new EntryFactory(controllerFunction);
- this.entries = createEntries(binding().getValue());
- this.collapsed = collapsed;
- this.typeClass = typeClass;
- this.flags = flags;
- this.available = available;
- this.listeners = new ArrayList<>();
- this.listeners.addAll(listeners);
- this.refreshListeners = new ArrayList<>();
- callListeners();
- }
-
- @Override
- public @NotNull Component name() {
- return this.name;
- }
-
- @Override
- public @NotNull Component tooltip() {
- return this.tooltip;
- }
-
- @Override
- public @NotNull ImmutableList<ListOptionEntry<T>> options() {
- return ImmutableList.copyOf(entries);
- }
-
- @Override
- public @NotNull Controller<List<T>> controller() {
- throw new UnsupportedOperationException();
- }
-
- @Override
- public @NotNull Binding<List<T>> binding() {
- return binding;
- }
-
- @Override
- public @NotNull Class<List<T>> typeClass() {
- throw new UnsupportedOperationException();
- }
-
- @Override
- public @NotNull Class<T> elementTypeClass() {
- return typeClass;
- }
-
- @Override
- public boolean collapsed() {
- return collapsed;
- }
-
- @Override
- public @NotNull ImmutableSet<OptionFlag> flags() {
- return flags;
- }
-
- @Override
- public @NotNull ImmutableList<T> pendingValue() {
- return ImmutableList.copyOf(entries.stream().map(Option::pendingValue).toList());
- }
-
- @Override
- public void insertEntry(int index, ListOptionEntry<?> entry) {
- entries.add(index, (ListOptionEntry<T>) entry);
- onRefresh();
- }
-
- @Override
- public ListOptionEntry<T> insertNewEntryToTop() {
- ListOptionEntry<T> newEntry = entryFactory.create(initialValue);
- entries.add(0, newEntry);
- onRefresh();
- return newEntry;
- }
-
- @Override
- public void removeEntry(ListOptionEntry<?> entry) {
- if (entries.remove(entry))
- onRefresh();
- }
-
- @Override
- public int indexOf(ListOptionEntry<?> entry) {
- return entries.indexOf(entry);
- }
-
- @Override
- public void requestSet(List<T> value) {
- entries.clear();
- entries.addAll(createEntries(value));
- onRefresh();
- }
-
- @Override
- public boolean changed() {
- return !binding().getValue().equals(pendingValue());
- }
-
- @Override
- public boolean applyValue() {
- if (changed()) {
- binding().setValue(pendingValue());
- return true;
- }
- return false;
- }
-
- @Override
- public void forgetPendingValue() {
- requestSet(binding().getValue());
- }
-
- @Override
- public void requestSetDefault() {
- requestSet(binding().defaultValue());
- }
-
- @Override
- public boolean isPendingValueDefault() {
- return binding().defaultValue().equals(pendingValue());
- }
-
- @Override
- public boolean available() {
- return available;
- }
-
- @Override
- public void setAvailable(boolean available) {
- this.available = available;
- }
-
- @Override
- public void addListener(BiConsumer<Option<List<T>>, List<T>> changedListener) {
- this.listeners.add(changedListener);
- }
-
- @Override
- public void addRefreshListener(Runnable changedListener) {
- this.refreshListeners.add(changedListener);
- }
-
- @Override
- public boolean isRoot() {
- return false;
- }
-
- private List<ListOptionEntry<T>> createEntries(Collection<T> values) {
- return values.stream().map(entryFactory::create).collect(Collectors.toList());
- }
-
- void callListeners() {
- List<T> pendingValue = pendingValue();
- this.listeners.forEach(listener -> listener.accept(this, pendingValue));
- }
-
- private void onRefresh() {
- refreshListeners.forEach(Runnable::run);
- callListeners();
- }
-
- private class EntryFactory {
- private final Function<ListOptionEntry<T>, Controller<T>> controllerFunction;
-
- private EntryFactory(Function<ListOptionEntry<T>, Controller<T>> controllerFunction) {
- this.controllerFunction = controllerFunction;
- }
-
- public ListOptionEntry<T> create(T initialValue) {
- return new ListOptionEntryImpl<>(ListOptionImpl.this, initialValue, controllerFunction);
- }
- }
-
- @ApiStatus.Internal
- public static final class BuilderImpl<T> implements ListOption.Builder<T> {
- private Component name = Component.empty();
- private final List<Component> tooltipLines = new ArrayList<>();
- private Function<ListOptionEntry<T>, Controller<T>> controllerFunction;
- private Binding<List<T>> binding = null;
- private final Set<OptionFlag> flags = new HashSet<>();
- 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) {
- this.typeClass = typeClass;
- }
-
- @Override
- public ListOption.Builder<T> name(@NotNull Component name) {
- Validate.notNull(name, "`name` must not be null");
-
- this.name = name;
- return this;
- }
-
- @Override
- public ListOption.Builder<T> tooltip(@NotNull Component... tooltips) {
- Validate.notEmpty(tooltips, "`tooltips` cannot be empty");
-
- tooltipLines.addAll(List.of(tooltips));
- return this;
- }
-
- @Override
- public ListOption.Builder<T> initial(@NotNull T initialValue) {
- Validate.notNull(initialValue, "`initialValue` cannot be empty");
-
- this.initialValue = initialValue;
- return this;
- }
-
- @Override
- public ListOption.Builder<T> controller(@NotNull Function<ListOptionEntry<T>, Controller<T>> control) {
- Validate.notNull(control, "`control` cannot be null");
-
- this.controllerFunction = control;
- return this;
- }
-
- @Override
- public ListOption.Builder<T> binding(@NotNull Binding<List<T>> binding) {
- Validate.notNull(binding, "`binding` cannot be null");
-
- this.binding = binding;
- return this;
- }
-
- @Override
- public ListOption.Builder<T> binding(@NotNull List<T> def, @NotNull Supplier<@NotNull List<T>> getter, @NotNull Consumer<@NotNull List<T>> setter) {
- Validate.notNull(def, "`def` must not be null");
- Validate.notNull(getter, "`getter` must not be null");
- Validate.notNull(setter, "`setter` must not be null");
-
- this.binding = Binding.generic(def, getter, setter);
- return this;
- }
-
- @Override
- public ListOption.Builder<T> available(boolean available) {
- this.available = available;
- return this;
- }
-
- @Override
- public ListOption.Builder<T> flag(@NotNull OptionFlag... flag) {
- Validate.notNull(flag, "`flag` must not be null");
-
- this.flags.addAll(Arrays.asList(flag));
- return this;
- }
-
- @Override
- public ListOption.Builder<T> flags(@NotNull Collection<OptionFlag> flags) {
- Validate.notNull(flags, "`flags` must not be null");
-
- this.flags.addAll(flags);
- return this;
- }
-
- @Override
- public ListOption.Builder<T> collapsed(boolean collapsible) {
- this.collapsed = collapsible;
- return this;
- }
-
- @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");
- Validate.notNull(initialValue, "`initialValue` must not be null");
-
- MutableComponent concatenatedTooltip = Component.empty();
- boolean first = true;
- for (Component line : tooltipLines) {
- if (!first) concatenatedTooltip.append("\n");
- first = false;
-
- concatenatedTooltip.append(line);
- }
-
- return new ListOptionImpl<>(name, concatenatedTooltip, binding, initialValue, typeClass, controllerFunction, ImmutableSet.copyOf(flags), collapsed, available, listeners);
- }
- }
-}
diff --git a/src/client/java/dev/isxander/yacl/impl/OptionGroupImpl.java b/src/client/java/dev/isxander/yacl/impl/OptionGroupImpl.java
deleted file mode 100644
index 68f53a0..0000000
--- a/src/client/java/dev/isxander/yacl/impl/OptionGroupImpl.java
+++ /dev/null
@@ -1,129 +0,0 @@
-package dev.isxander.yacl.impl;
-
-import com.google.common.collect.ImmutableList;
-import dev.isxander.yacl.api.ListOption;
-import dev.isxander.yacl.api.Option;
-import dev.isxander.yacl.api.OptionGroup;
-import net.minecraft.network.chat.Component;
-import net.minecraft.network.chat.ComponentContents;
-import net.minecraft.network.chat.MutableComponent;
-import org.apache.commons.lang3.Validate;
-import org.jetbrains.annotations.ApiStatus;
-import org.jetbrains.annotations.NotNull;
-
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.List;
-
-@ApiStatus.Internal
-public final class OptionGroupImpl implements OptionGroup {
- private final @NotNull Component name;
- private final @NotNull Component tooltip;
- private final ImmutableList<? extends Option<?>> options;
- private final boolean collapsed;
- private final boolean isRoot;
-
- public OptionGroupImpl(@NotNull Component name, @NotNull Component tooltip, ImmutableList<? extends Option<?>> options, boolean collapsed, boolean isRoot) {
- this.name = name;
- this.tooltip = tooltip;
- this.options = options;
- this.collapsed = collapsed;
- this.isRoot = isRoot;
- }
-
- @Override
- public @NotNull Component name() {
- return name;
- }
-
- @Override
- public @NotNull Component tooltip() {
- return tooltip;
- }
-
- @Override
- public @NotNull ImmutableList<? extends Option<?>> options() {
- return options;
- }
-
- @Override
- public boolean collapsed() {
- return collapsed;
- }
-
- @Override
- public boolean isRoot() {
- return isRoot;
- }
-
- @ApiStatus.Internal
- public static final class BuilderImpl implements OptionGroup.Builder {
- private Component name = Component.empty();
- private final List<Component> tooltipLines = new ArrayList<>();
- private final List<Option<?>> options = new ArrayList<>();
- private boolean collapsed = false;
-
- @Override
- public Builder name(@NotNull Component name) {
- Validate.notNull(name, "`name` must not be null");
-
- this.name = name;
- return this;
- }
-
- @Override
- public Builder tooltip(@NotNull Component... tooltips) {
- Validate.notEmpty(tooltips, "`tooltips` cannot be empty");
-
- tooltipLines.addAll(List.of(tooltips));
- return this;
- }
-
- @Override
- public Builder option(@NotNull Option<?> option) {
- Validate.notNull(option, "`option` must not be null");
-
- if (option instanceof ListOption<?>)
- throw new UnsupportedOperationException("List options must not be added as an option but a group!");
-
- this.options.add(option);
- return this;
- }
-
- @Override
- public Builder options(@NotNull Collection<? extends Option<?>> options) {
- Validate.notEmpty(options, "`options` must not be empty");
-
- if (options.stream().anyMatch(ListOption.class::isInstance))
- throw new UnsupportedOperationException("List options must not be added as an option but a group!");
-
- this.options.addAll(options);
- return this;
- }
-
- @Override
- public Builder collapsed(boolean collapsible) {
- this.collapsed = collapsible;
- return this;
- }
-
- @Override
- public OptionGroup build() {
- Validate.notEmpty(options, "`options` must not be empty to build `OptionGroup`");
-
- MutableComponent concatenatedTooltip = Component.empty();
- boolean first = true;
- for (Component line : tooltipLines) {
- if (line.getContents() == ComponentContents.EMPTY)
- continue;
-
- if (!first) concatenatedTooltip.append("\n");
- first = false;
-
- concatenatedTooltip.append(line);
- }
-
- return new OptionGroupImpl(name, concatenatedTooltip, ImmutableList.copyOf(options), collapsed, false);
- }
- }
-}
diff --git a/src/client/java/dev/isxander/yacl/impl/OptionImpl.java b/src/client/java/dev/isxander/yacl/impl/OptionImpl.java
deleted file mode 100644
index 644abc9..0000000
--- a/src/client/java/dev/isxander/yacl/impl/OptionImpl.java
+++ /dev/null
@@ -1,304 +0,0 @@
-package dev.isxander.yacl.impl;
-
-import com.google.common.collect.ImmutableSet;
-import dev.isxander.yacl.api.Binding;
-import dev.isxander.yacl.api.Controller;
-import dev.isxander.yacl.api.Option;
-import dev.isxander.yacl.api.OptionFlag;
-import net.minecraft.ChatFormatting;
-import net.minecraft.network.chat.Component;
-import net.minecraft.network.chat.ComponentContents;
-import net.minecraft.network.chat.MutableComponent;
-import org.apache.commons.lang3.Validate;
-import org.jetbrains.annotations.ApiStatus;
-import org.jetbrains.annotations.NotNull;
-import org.jetbrains.annotations.Nullable;
-
-import java.util.*;
-import java.util.function.BiConsumer;
-import java.util.function.Consumer;
-import java.util.function.Function;
-import java.util.function.Supplier;
-import java.util.stream.Stream;
-
-@ApiStatus.Internal
-public final class OptionImpl<T> implements Option<T> {
- private final Component name;
- private Component tooltip;
- private final Controller<T> controller;
- private final Binding<T> binding;
- private boolean available;
-
- private final ImmutableSet<OptionFlag> flags;
-
- private final Class<T> typeClass;
-
- private T pendingValue;
-
- private final List<BiConsumer<Option<T>, T>> listeners;
-
- public OptionImpl(
- @NotNull Component name,
- @Nullable Function<T, Component> tooltipGetter,
- @NotNull Function<Option<T>, Controller<T>> controlGetter,
- @NotNull Binding<T> binding,
- boolean available,
- ImmutableSet<OptionFlag> flags,
- @NotNull Class<T> typeClass,
- @NotNull Collection<BiConsumer<Option<T>, T>> listeners
- ) {
- this.name = name;
- this.binding = binding;
- this.available = available;
- this.flags = flags;
- this.typeClass = typeClass;
- this.listeners = new ArrayList<>(listeners);
- this.controller = controlGetter.apply(this);
-
- addListener((opt, pending) -> tooltip = tooltipGetter.apply(pending));
- requestSet(binding().getValue());
- }
-
- @Override
- public @NotNull Component name() {
- return name;
- }
-
- @Override
- public @NotNull Component tooltip() {
- return tooltip;
- }
-
- @Override
- public @NotNull Controller<T> controller() {
- return controller;
- }
-
- @Override
- public @NotNull Binding<T> binding() {
- return binding;
- }
-
- @Override
- public boolean available() {
- return available;
- }
-
- @Override
- public void setAvailable(boolean available) {
- this.available = available;
- }
-
- @Override
- public @NotNull Class<T> typeClass() {
- return typeClass;
- }
-
- @Override
- public @NotNull ImmutableSet<OptionFlag> flags() {
- return flags;
- }
-
- @Override
- public boolean changed() {
- return !binding().getValue().equals(pendingValue);
- }
-
- @Override
- public @NotNull T pendingValue() {
- return pendingValue;
- }
-
- @Override
- public void requestSet(T value) {
- pendingValue = value;
- listeners.forEach(listener -> listener.accept(this, pendingValue));
- }
-
- @Override
- public boolean applyValue() {
- if (changed()) {
- binding().setValue(pendingValue);
- return true;
- }
- return false;
- }
-
- @Override
- public void forgetPendingValue() {
- requestSet(binding().getValue());
- }
-
- @Override
- public void requestSetDefault() {
- requestSet(binding().defaultValue());
- }
-
- @Override
- public boolean isPendingValueDefault() {
- return binding().defaultValue().equals(pendingValue());
- }
-
- @Override
- public void addListener(BiConsumer<Option<T>, T> changedListener) {
- this.listeners.add(changedListener);
- }
-
- @ApiStatus.Internal
- public static class BuilderImpl<T> implements Option.Builder<T> {
- private Component name = Component.literal("Name not specified!").withStyle(ChatFormatting.RED);
-
- private final List<Function<T, Component>> tooltipGetters = new ArrayList<>();
-
- private Function<Option<T>, Controller<T>> controlGetter;
-
- private Binding<T> binding;
-
- private boolean available = true;
-
- private boolean instant = false;
-
- private final Set<OptionFlag> flags = new HashSet<>();
-
- private final Class<T> typeClass;
-
- private final List<BiConsumer<Option<T>, T>> listeners = new ArrayList<>();
-
- public BuilderImpl(Class<T> typeClass) {
- this.typeClass = typeClass;
- }
-
- @Override
- public Option.Builder<T> name(@NotNull Component name) {
- Validate.notNull(name, "`name` cannot be null");
-
- this.name = name;
- return this;
- }
-
- @Override
- public Builder<T> tooltip(@NotNull Function<T, Component> tooltipGetter) {
- Validate.notNull(tooltipGetter, "`tooltipGetter` cannot be null");
-
- this.tooltipGetters.add(tooltipGetter);
- return this;
- }
-
- @Override
- @SafeVarargs
- @Deprecated
- public final Option.Builder<T> tooltip(@NotNull Function<T, Component>... tooltipGetter) {
- Validate.notNull(tooltipGetter, "`tooltipGetter` cannot be null");
-
- this.tooltipGetters.addAll(List.of(tooltipGetter));
- return this;
- }
-
- @Override
- public Option.Builder<T> tooltip(@NotNull Component... tooltips) {
- var tooltipFunctions = Arrays.stream(tooltips)
- .map(t -> (Function<T, Component>) opt -> t)
- .toList();
-
- this.tooltipGetters.addAll(tooltipFunctions);
- return this;
- }
-
- @Override
- public Option.Builder<T> controller(@NotNull Function<Option<T>, Controller<T>> control) {
- Validate.notNull(control, "`control` cannot be null");
-
- this.controlGetter = control;
- return this;
- }
-
- @Override
- public Option.Builder<T> binding(@NotNull Binding<T> binding) {
- Validate.notNull(binding, "`binding` cannot be null");
-
- this.binding = binding;
- return this;
- }
-
- @Override
- public Option.Builder<T> binding(@NotNull T def, @NotNull Supplier<@NotNull T> getter, @NotNull Consumer<@NotNull T> setter) {
- Validate.notNull(def, "`def` must not be null");
- Validate.notNull(getter, "`getter` must not be null");
- Validate.notNull(setter, "`setter` must not be null");
-
- this.binding = Binding.generic(def, getter, setter);
- return this;
- }
-
- @Override
- public Option.Builder<T> available(boolean available) {
- this.available = available;
- return this;
- }
-
- @Override
- public Option.Builder<T> flag(@NotNull OptionFlag... flag) {
- Validate.notNull(flag, "`flag` must not be null");
-
- this.flags.addAll(Arrays.asList(flag));
- return this;
- }
-
- @Override
- public Option.Builder<T> flags(@NotNull Collection<OptionFlag> flags) {
- Validate.notNull(flags, "`flags` must not be null");
-
- this.flags.addAll(flags);
- return this;
- }
-
- @Override
- public Option.Builder<T> instant(boolean instant) {
- this.instant = instant;
- return this;
- }
-
- @Override
- public Option.Builder<T> listener(@NotNull BiConsumer<Option<T>, T> listener) {
- this.listeners.add(listener);
- return this;
- }
-
- @Override
- public Option.Builder<T> listeners(@NotNull Collection<BiConsumer<Option<T>, T>> listeners) {
- this.listeners.addAll(listeners);
- return this;
- }
-
- @Override
- 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, Component> concatenatedTooltipGetter = value -> {
- MutableComponent concatenatedTooltip = Component.empty();
- boolean first = true;
- for (Function<T, Component> line : tooltipGetters) {
- Component lineComponent = line.apply(value);
-
- if (lineComponent.getContents() == ComponentContents.EMPTY)
- continue;
-
- if (!first) concatenatedTooltip.append("\n");
- first = false;
-
- concatenatedTooltip.append(lineComponent);
- }
-
- return concatenatedTooltip;
- };
-
- if (instant) {
- listeners.add((opt, pendingValue) -> opt.applyValue());
- }
-
- return new OptionImpl<>(name, concatenatedTooltipGetter, controlGetter, binding, available, ImmutableSet.copyOf(flags), typeClass, listeners);
- }
- }
-}
diff --git a/src/client/java/dev/isxander/yacl/impl/PlaceholderCategoryImpl.java b/src/client/java/dev/isxander/yacl/impl/PlaceholderCategoryImpl.java
deleted file mode 100644
index 0b77466..0000000
--- a/src/client/java/dev/isxander/yacl/impl/PlaceholderCategoryImpl.java
+++ /dev/null
@@ -1,99 +0,0 @@
-package dev.isxander.yacl.impl;
-
-import com.google.common.collect.ImmutableList;
-import dev.isxander.yacl.api.OptionGroup;
-import dev.isxander.yacl.api.PlaceholderCategory;
-import dev.isxander.yacl.gui.YACLScreen;
-import net.minecraft.client.Minecraft;
-import net.minecraft.client.gui.screens.Screen;
-import net.minecraft.network.chat.Component;
-import net.minecraft.network.chat.MutableComponent;
-import org.apache.commons.lang3.Validate;
-import org.jetbrains.annotations.ApiStatus;
-import org.jetbrains.annotations.NotNull;
-
-import java.util.ArrayList;
-import java.util.List;
-import java.util.function.BiFunction;
-
-@ApiStatus.Internal
-public final class PlaceholderCategoryImpl implements PlaceholderCategory {
- private final Component name;
- private final BiFunction<Minecraft, YACLScreen, Screen> screen;
- private final Component tooltip;
-
- public PlaceholderCategoryImpl(Component name, BiFunction<Minecraft, YACLScreen, Screen> screen, Component tooltip) {
- this.name = name;
- this.screen = screen;
- this.tooltip = tooltip;
- }
-
- @Override
- public @NotNull ImmutableList<OptionGroup> groups() {
- return ImmutableList.of();
- }
-
- @Override
- public @NotNull Component name() {
- return name;
- }
-
- @Override
- public BiFunction<Minecraft, YACLScreen, Screen> screen() {
- return screen;
- }
-
- @Override
- public @NotNull Component tooltip() {
- return tooltip;
- }
-
- @ApiStatus.Internal
- public static final class BuilderImpl implements PlaceholderCategory.Builder {
- private Component name;
-
- private final List<Component> tooltipLines = new ArrayList<>();
-
- private BiFunction<Minecraft, YACLScreen, Screen> screenFunction;
-
- @Override
- public Builder name(@NotNull Component name) {
- Validate.notNull(name, "`name` cannot be null");
-
- this.name = name;
- return this;
- }
-
- @Override
- public Builder tooltip(@NotNull Component... tooltips) {
- Validate.notEmpty(tooltips, "`tooltips` cannot be empty");
-
- tooltipLines.addAll(List.of(tooltips));
- return this;
- }
-
- @Override
- public Builder screen(@NotNull BiFunction<Minecraft, YACLScreen, Screen> screenFunction) {
- Validate.notNull(screenFunction, "`screenFunction` cannot be null");
-
- this.screenFunction = screenFunction;
- return this;
- }
-
- @Override
- public PlaceholderCategory build() {
- Validate.notNull(name, "`name` must not be null to build `ConfigCategory`");
-
- MutableComponent concatenatedTooltip = Component.empty();
- boolean first = true;
- for (Component line : tooltipLines) {
- if (!first) concatenatedTooltip.append("\n");
- first = false;
-
- concatenatedTooltip.append(line);
- }
-
- return new PlaceholderCategoryImpl(name, screenFunction, concatenatedTooltip);
- }
- }
-}
diff --git a/src/client/java/dev/isxander/yacl/impl/YetAnotherConfigLibImpl.java b/src/client/java/dev/isxander/yacl/impl/YetAnotherConfigLibImpl.java
deleted file mode 100644
index 21c776a..0000000
--- a/src/client/java/dev/isxander/yacl/impl/YetAnotherConfigLibImpl.java
+++ /dev/null
@@ -1,122 +0,0 @@
-package dev.isxander.yacl.impl;
-
-import com.google.common.collect.ImmutableList;
-import dev.isxander.yacl.api.ConfigCategory;
-import dev.isxander.yacl.api.PlaceholderCategory;
-import dev.isxander.yacl.api.YetAnotherConfigLib;
-import dev.isxander.yacl.gui.YACLScreen;
-import dev.isxander.yacl.impl.utils.YACLConstants;
-import net.minecraft.client.gui.screens.Screen;
-import net.minecraft.network.chat.Component;
-import org.apache.commons.lang3.Validate;
-import org.jetbrains.annotations.ApiStatus;
-import org.jetbrains.annotations.NotNull;
-
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.List;
-import java.util.function.Consumer;
-
-@ApiStatus.Internal
-public final class YetAnotherConfigLibImpl implements YetAnotherConfigLib {
- private final Component title;
- private final ImmutableList<ConfigCategory> categories;
- private final Runnable saveFunction;
- private final Consumer<YACLScreen> initConsumer;
-
- private boolean generated = false;
-
- public YetAnotherConfigLibImpl(Component title, ImmutableList<ConfigCategory> categories, Runnable saveFunction, Consumer<YACLScreen> initConsumer) {
- this.title = title;
- this.categories = categories;
- this.saveFunction = saveFunction;
- this.initConsumer = initConsumer;
- }
-
- @Override
- public Screen generateScreen(Screen parent) {
- if (generated)
- throw new UnsupportedOperationException("To prevent memory leaks, you should only generate a Screen once per instance. Please re-build the instance to generate another GUI.");
-
- YACLConstants.LOGGER.info("Generating YACL screen");
- generated = true;
- return new YACLScreen(this, parent);
- }
-
- @Override
- public Component title() {
- return title;
- }
-
- @Override
- public ImmutableList<ConfigCategory> categories() {
- return categories;
- }
-
- @Override
- public Runnable saveFunction() {
- return saveFunction;
- }
-
- @Override
- public Consumer<YACLScreen> initConsumer() {
- return initConsumer;
- }
-
- @ApiStatus.Internal
- public static final class BuilderImpl implements YetAnotherConfigLib.Builder {
- private Component title;
- private final List<ConfigCategory> categories = new ArrayList<>();
- private Runnable saveFunction = () -> {};
- private Consumer<YACLScreen> initConsumer = screen -> {};
-
- @Override
- public YetAnotherConfigLib.Builder title(@NotNull Component title) {
- Validate.notNull(title, "`title` cannot be null");
-
- this.title = title;
- return this;
- }
-
- @Override
- public YetAnotherConfigLib.Builder category(@NotNull ConfigCategory category) {
- Validate.notNull(category, "`category` cannot be null");
-
- this.categories.add(category);
- return this;
- }
-
- @Override
- public YetAnotherConfigLib.Builder categories(@NotNull Collection<? extends ConfigCategory> categories) {
- Validate.notNull(categories, "`categories` cannot be null");
-
- this.categories.addAll(categories);
- return this;
- }
-
- @Override
- public YetAnotherConfigLib.Builder save(@NotNull Runnable saveFunction) {
- Validate.notNull(saveFunction, "`saveFunction` cannot be null");
-
- this.saveFunction = saveFunction;
- return this;
- }
-
- @Override
- public YetAnotherConfigLib.Builder screenInit(@NotNull Consumer<YACLScreen> initConsumer) {
- Validate.notNull(initConsumer, "`initConsumer` cannot be null");
-
- this.initConsumer = initConsumer;
- return this;
- }
-
- @Override
- public YetAnotherConfigLib build() {
- Validate.notNull(title, "`title must not be null to build `YetAnotherConfigLib`");
- Validate.notEmpty(categories, "`categories` must not be empty to build `YetAnotherConfigLib`");
- Validate.isTrue(!categories.stream().allMatch(category -> category instanceof PlaceholderCategory), "At least one regular category is required to build `YetAnotherConfigLib`");
-
- return new YetAnotherConfigLibImpl(title, ImmutableList.copyOf(categories), saveFunction, initConsumer);
- }
- }
-}