aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/dev/isxander
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/java/dev/isxander')
-rw-r--r--src/main/java/dev/isxander/yacl3/api/ConfigCategory.java7
-rw-r--r--src/main/java/dev/isxander/yacl3/impl/ConfigCategoryImpl.java41
2 files changed, 48 insertions, 0 deletions
diff --git a/src/main/java/dev/isxander/yacl3/api/ConfigCategory.java b/src/main/java/dev/isxander/yacl3/api/ConfigCategory.java
index b3d68fc..41f3ca9 100644
--- a/src/main/java/dev/isxander/yacl3/api/ConfigCategory.java
+++ b/src/main/java/dev/isxander/yacl3/api/ConfigCategory.java
@@ -125,6 +125,13 @@ public interface ConfigCategory {
Builder groups(@NotNull Collection<OptionGroup> groups);
/**
+ * Fetches the builder for the root group of the category.
+ * This is the group that has no header and options are added through {@link Builder#option(Option)}.
+ * In its default implementation, this builder is severely limited and a lot of methods are unsupported.
+ */
+ OptionGroup.Builder rootGroupBuilder();
+
+ /**
* Sets the tooltip to be used by the category.
* Can be invoked twice to append more lines.
* No need to wrap the text yourself, the gui does this itself.
diff --git a/src/main/java/dev/isxander/yacl3/impl/ConfigCategoryImpl.java b/src/main/java/dev/isxander/yacl3/impl/ConfigCategoryImpl.java
index 400abf6..c73d647 100644
--- a/src/main/java/dev/isxander/yacl3/impl/ConfigCategoryImpl.java
+++ b/src/main/java/dev/isxander/yacl3/impl/ConfigCategoryImpl.java
@@ -46,6 +46,8 @@ public final class ConfigCategoryImpl implements ConfigCategory {
private Component name;
private final List<Option<?>> rootOptions = new ArrayList<>();
+ private final RootGroupBuilder rootGroupBuilder = new RootGroupBuilder();
+
private final List<OptionGroup> groups = new ArrayList<>();
private final List<Component> tooltipLines = new ArrayList<>();
@@ -107,6 +109,11 @@ public final class ConfigCategoryImpl implements ConfigCategory {
}
@Override
+ public OptionGroup.Builder rootGroupBuilder() {
+ return rootGroupBuilder;
+ }
+
+ @Override
public ConfigCategory build() {
Validate.notNull(name, "`name` must not be null to build `ConfigCategory`");
@@ -130,5 +137,39 @@ public final class ConfigCategoryImpl implements ConfigCategory {
return new ConfigCategoryImpl(name, ImmutableList.copyOf(combinedGroups), concatenatedTooltip);
}
+
+ private class RootGroupBuilder implements OptionGroup.Builder {
+ @Override
+ public OptionGroup.Builder name(@NotNull Component name) {
+ throw new UnsupportedOperationException("Cannot set name of root group!");
+ }
+
+ @Override
+ public OptionGroup.Builder description(@NotNull OptionDescription description) {
+ throw new UnsupportedOperationException("Cannot set name of root group!");
+ }
+
+ @Override
+ public OptionGroup.Builder option(@NotNull Option<?> option) {
+ ConfigCategoryImpl.BuilderImpl.this.option(option);
+ return this;
+ }
+
+ @Override
+ public OptionGroup.Builder options(@NotNull Collection<? extends Option<?>> options) {
+ ConfigCategoryImpl.BuilderImpl.this.options(options);
+ return this;
+ }
+
+ @Override
+ public OptionGroup.Builder collapsed(boolean collapsible) {
+ throw new UnsupportedOperationException("Cannot set collapsible of root group!");
+ }
+
+ @Override
+ public OptionGroup build() {
+ throw new UnsupportedOperationException("Cannot build root group!");
+ }
+ }
}
}