diff options
-rw-r--r-- | build.gradle.kts | 3 | ||||
-rw-r--r-- | changelogs/2.4.1.md | 9 | ||||
-rw-r--r-- | src/client/java/dev/isxander/yacl/api/ConfigCategory.java | 6 | ||||
-rw-r--r-- | src/client/java/dev/isxander/yacl/api/Option.java | 10 | ||||
-rw-r--r-- | src/client/java/dev/isxander/yacl/api/OptionAddable.java | 19 | ||||
-rw-r--r-- | src/client/java/dev/isxander/yacl/api/OptionGroup.java | 4 | ||||
-rw-r--r-- | src/client/java/dev/isxander/yacl/impl/ConfigCategoryImpl.java | 2 | ||||
-rw-r--r-- | src/client/java/dev/isxander/yacl/impl/OptionImpl.java | 9 |
8 files changed, 56 insertions, 6 deletions
diff --git a/build.gradle.kts b/build.gradle.kts index 704d2bc..b02a9e0 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -16,7 +16,7 @@ plugins { val ciRun = System.getenv().containsKey("GITHUB_ACTIONS") group = "dev.isxander" -version = "2.4.0" +version = "2.4.1" if (ciRun) version = "$version+${grgit.branch.current().name.replace('/', '.')}-SNAPSHOT" @@ -192,6 +192,7 @@ publishing { artifactId = "yet-another-config-lib" from(components["java"]) + artifact(tasks["remapSourcesJar"]) } } diff --git a/changelogs/2.4.1.md b/changelogs/2.4.1.md new file mode 100644 index 0000000..008c0c9 --- /dev/null +++ b/changelogs/2.4.1.md @@ -0,0 +1,9 @@ +## Features + +- `OptionGroup.Builder` and `ConfigCategory.Builder` now extend `OptionAddable` so you can abstractly +add options to either of them. + +## API Changes + +- Deprecated the varargs tooltip builder method in `Option.Builder` due to unsafe varargs. There is now + an equivalent that is not varargs but a single function. 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<Option<?>> options); + @Override + Builder options(@NotNull Collection<? extends Option<?>> 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<T> { * * @param tooltipGetter function to get tooltip depending on value {@link Builder#build()}. */ - @SuppressWarnings("unchecked") + Builder<T> tooltip(@NotNull Function<T, Component> 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<T> tooltip(@NotNull Function<T, Component>... 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<? extends Option<?>> 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<? extends Option<?>> 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<Option<?>> options) { + public Builder options(@NotNull Collection<? extends Option<?>> 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 @@ -176,7 +176,16 @@ public final class OptionImpl<T> implements Option<T> { } @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"); |