Skip to content

Commit

Permalink
Merge pull request #444 from lynxplay/feature/component-builder-decor…
Browse files Browse the repository at this point in the history
…ation-additions

Add decorations(Map) to component/style builders
  • Loading branch information
zml2008 committed Oct 16, 2021
2 parents eea1a16 + db91520 commit 0635e12
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 0 deletions.
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 @@ -694,6 +694,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

0 comments on commit 0635e12

Please sign in to comment.