From 74bcc11c74f864eda2f5e48a3c038846c20065ba Mon Sep 17 00:00:00 2001 From: isXander Date: Sat, 15 Apr 2023 22:21:45 +0100 Subject: 2.4.1 --- .../java/dev/isxander/yacl/api/ConfigCategory.java | 6 ++++-- src/client/java/dev/isxander/yacl/api/Option.java | 10 +++++++++- .../java/dev/isxander/yacl/api/OptionAddable.java | 19 +++++++++++++++++++ .../java/dev/isxander/yacl/api/OptionGroup.java | 4 +++- .../dev/isxander/yacl/impl/ConfigCategoryImpl.java | 2 +- .../java/dev/isxander/yacl/impl/OptionImpl.java | 9 +++++++++ 6 files changed, 45 insertions(+), 5 deletions(-) create mode 100644 src/client/java/dev/isxander/yacl/api/OptionAddable.java (limited to 'src') diff --git a/src/client/java/dev/isxander/yacl/api/ConfigCategory.java b/src/client/java/dev/isxander/yacl/api/ConfigCategory.java index 0e8d1e5..7764479 100644 --- a/src/client/java/dev/isxander/yacl/api/ConfigCategory.java +++ b/src/client/java/dev/isxander/yacl/api/ConfigCategory.java @@ -36,7 +36,7 @@ public interface ConfigCategory { return new ConfigCategoryImpl.BuilderImpl(); } - interface Builder { + interface Builder extends OptionAddable { /** * Sets name of the category * @@ -52,6 +52,7 @@ public interface ConfigCategory { * @see ConfigCategory#groups() * @see OptionGroup#isRoot() */ + @Override Builder option(@NotNull Option option); /** @@ -62,7 +63,8 @@ public interface ConfigCategory { * @see ConfigCategory#groups() * @see OptionGroup#isRoot() */ - Builder options(@NotNull Collection> options); + @Override + Builder options(@NotNull Collection> options); /** * Adds an option group. diff --git a/src/client/java/dev/isxander/yacl/api/Option.java b/src/client/java/dev/isxander/yacl/api/Option.java index faa6f1c..a6c0311 100644 --- a/src/client/java/dev/isxander/yacl/api/Option.java +++ b/src/client/java/dev/isxander/yacl/api/Option.java @@ -132,7 +132,15 @@ public interface Option { * * @param tooltipGetter function to get tooltip depending on value {@link Builder#build()}. */ - @SuppressWarnings("unchecked") + Builder tooltip(@NotNull Function tooltipGetter); + + /** + * Sets the tooltip to be used by the option. + * No need to wrap the text yourself, the gui does this itself. + * + * @param tooltipGetter function to get tooltip depending on value {@link Builder#build()}. + */ + @Deprecated Builder tooltip(@NotNull Function... tooltipGetter); /** diff --git a/src/client/java/dev/isxander/yacl/api/OptionAddable.java b/src/client/java/dev/isxander/yacl/api/OptionAddable.java new file mode 100644 index 0000000..57be06c --- /dev/null +++ b/src/client/java/dev/isxander/yacl/api/OptionAddable.java @@ -0,0 +1,19 @@ +package dev.isxander.yacl.api; + +import org.jetbrains.annotations.NotNull; + +import java.util.Collection; + +public interface OptionAddable { + /** + * Adds an option to an abstract builder. + * To construct an option, use {@link Option#createBuilder(Class)} + */ + OptionAddable option(@NotNull Option option); + + /** + * Adds multiple options to an abstract builder. + * To construct an option, use {@link Option#createBuilder(Class)} + */ + OptionAddable options(@NotNull Collection> options); +} diff --git a/src/client/java/dev/isxander/yacl/api/OptionGroup.java b/src/client/java/dev/isxander/yacl/api/OptionGroup.java index 9f78071..4fe43c7 100644 --- a/src/client/java/dev/isxander/yacl/api/OptionGroup.java +++ b/src/client/java/dev/isxander/yacl/api/OptionGroup.java @@ -47,7 +47,7 @@ public interface OptionGroup { return new OptionGroupImpl.BuilderImpl(); } - interface Builder { + interface Builder extends OptionAddable { /** * Sets name of the group, can be {@link Component#empty()} to just separate options, like sodium. * @@ -70,6 +70,7 @@ public interface OptionGroup { * * @see OptionGroup#options() */ + @Override Builder option(@NotNull Option option); /** @@ -78,6 +79,7 @@ public interface OptionGroup { * * @see OptionGroup#options() */ + @Override Builder options(@NotNull Collection> options); /** diff --git a/src/client/java/dev/isxander/yacl/impl/ConfigCategoryImpl.java b/src/client/java/dev/isxander/yacl/impl/ConfigCategoryImpl.java index efbd8c9..b3d28b3 100644 --- a/src/client/java/dev/isxander/yacl/impl/ConfigCategoryImpl.java +++ b/src/client/java/dev/isxander/yacl/impl/ConfigCategoryImpl.java @@ -74,7 +74,7 @@ public final class ConfigCategoryImpl implements ConfigCategory { } @Override - public Builder options(@NotNull Collection> options) { + public Builder options(@NotNull Collection> options) { Validate.notNull(options, "`options` must not be null"); if (options.stream().anyMatch(ListOption.class::isInstance)) diff --git a/src/client/java/dev/isxander/yacl/impl/OptionImpl.java b/src/client/java/dev/isxander/yacl/impl/OptionImpl.java index d333e36..35ad620 100644 --- a/src/client/java/dev/isxander/yacl/impl/OptionImpl.java +++ b/src/client/java/dev/isxander/yacl/impl/OptionImpl.java @@ -175,8 +175,17 @@ public final class OptionImpl implements Option { return this; } + @Override + public Builder tooltip(@NotNull Function tooltipGetter) { + Validate.notNull(tooltipGetter, "`tooltipGetter` cannot be null"); + + this.tooltipGetters.add(tooltipGetter); + return this; + } + @Override @SafeVarargs + @Deprecated public final Option.Builder tooltip(@NotNull Function... tooltipGetter) { Validate.notNull(tooltipGetter, "`tooltipGetter` cannot be null"); -- cgit