Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add decorations(Map) to component/style builders #444

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
19 changes: 19 additions & 0 deletions api/src/main/java/net/kyori/adventure/text/ComponentBuilder.java
Expand Up @@ -24,6 +24,7 @@
package net.kyori.adventure.text;

import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.function.Consumer;
import java.util.function.Function;
Expand Down Expand Up @@ -273,6 +274,24 @@ public interface ComponentBuilder<C extends BuildableComponent<C, B>, B extends
return this.decoration(decoration, TextDecoration.State.byBoolean(flag));
}

/**
* Sets decorations for this component's style using the specified {@code decorations} map.
*
* <p>If a given decoration does not have a value explicitly set, the value of that particular decoration is not changed.</p>
*
* @param decorations a map containing text decorations and their respective state.
* @return this builder
* @since 4.10.0
*/
@Contract("_ -> this")
@SuppressWarnings("unchecked")
default @NotNull B decorations(final @NotNull Map<TextDecoration, TextDecoration.State> decorations) {
for (final Map.Entry<TextDecoration, TextDecoration.State> entry : decorations.entrySet()) {
this.decoration(entry.getKey(), entry.getValue());
}
return (B) this;
}

/**
* Sets the value of a decoration on this component.
*
Expand Down
17 changes: 17 additions & 0 deletions api/src/main/java/net/kyori/adventure/text/format/Style.java
Expand Up @@ -689,6 +689,23 @@ interface Builder extends Buildable.Builder<Style> {
return this.decoration(decoration, TextDecoration.State.byBoolean(flag));
}

/**
* Sets decorations for this style using the specified {@code decorations} map.
*
* <p>If a given decoration does not have a value explicitly set, the value of that particular decoration is not changed.</p>
*
* @param decorations a map containing text decorations and their respective state.
* @return this builder.
* @since 4.10.0
*/
@Contract("_ -> this")
default @NotNull Builder decorations(final @NotNull Map<TextDecoration, TextDecoration.State> decorations) {
for (final Map.Entry<TextDecoration, TextDecoration.State> entry : decorations.entrySet()) {
this.decoration(entry.getKey(), entry.getValue());
}
return this;
}

/**
* Sets the value of a decoration.
*
Expand Down