Skip to content

Commit

Permalink
Add ComponentBuider#decorations(Map)
Browse files Browse the repository at this point in the history
This commit introduces a new decorations method to the component builder
that takes in a map of text decorations and their state. This method
already exists on the Component interface but was previously missing on
the respective builder.

As the style builder stores the decorations in individual fields and
hence cannot natively work with the map layout, the method was
implemented as a default method on the interface and simply delegates
the map entriess to the normal decorate methods.

The main motivation for the addition of this method is the easy
application of a preset map of decorations.
  • Loading branch information
lynxplay committed Sep 13, 2021
1 parent c87c402 commit e96f5e6
Showing 1 changed file with 19 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 (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

0 comments on commit e96f5e6

Please sign in to comment.