Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -27,18 +27,22 @@
import java.util.Collections;
import java.util.List;
import java.util.ListIterator;
import java.util.Map;
import java.util.Set;
import java.util.function.Consumer;
import java.util.function.Function;
import net.kyori.adventure.key.Key;
import net.kyori.adventure.text.event.ClickEvent;
import net.kyori.adventure.text.event.HoverEvent;
import net.kyori.adventure.text.event.HoverEventSource;
import net.kyori.adventure.text.format.ShadowColor;
import net.kyori.adventure.text.format.Style;
import net.kyori.adventure.text.format.TextColor;
import net.kyori.adventure.text.format.TextDecoration;
import net.kyori.adventure.util.ARGBLike;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.jetbrains.annotations.Unmodifiable;

import static java.util.Objects.requireNonNull;

Expand Down Expand Up @@ -216,13 +220,23 @@ private void prepareChildren() {
return (B) this;
}

@Override
public @Nullable Key font() {
return this.styleBuilder().font();
}

@Override
@SuppressWarnings("unchecked")
public @NotNull B font(final @Nullable Key font) {
this.styleBuilder().font(font);
return (B) this;
}

@Override
public @Nullable TextColor color() {
return this.styleBuilder().color();
}

@Override
@SuppressWarnings("unchecked")
public @NotNull B color(final @Nullable TextColor color) {
Expand All @@ -237,6 +251,11 @@ private void prepareChildren() {
return (B) this;
}

@Override
public @Nullable ShadowColor shadowColor() {
return this.styleBuilder().shadowColor();
}

@Override
@SuppressWarnings("unchecked")
public @NotNull B shadowColor(final @Nullable ARGBLike argb) {
Expand All @@ -251,6 +270,21 @@ private void prepareChildren() {
return (B) this;
}

@Override
public TextDecoration.@NotNull State decoration(final @NotNull TextDecoration decoration) {
return this.styleBuilder().decoration(decoration);
}

@Override
public @Unmodifiable @NotNull Map<TextDecoration, TextDecoration.State> decorations() {
return this.styleBuilder().decorations();
}

@Override
public boolean hasDecoration(final @NotNull TextDecoration decoration) {
return this.styleBuilder().hasDecoration(decoration);
}

@Override
@SuppressWarnings("unchecked")
public @NotNull B decoration(final @NotNull TextDecoration decoration, final TextDecoration.@NotNull State state) {
Expand All @@ -265,20 +299,35 @@ private void prepareChildren() {
return (B) this;
}

@Override
public @Nullable ClickEvent clickEvent() {
return this.styleBuilder().clickEvent();
}

@Override
@SuppressWarnings("unchecked")
public @NotNull B clickEvent(final @Nullable ClickEvent event) {
this.styleBuilder().clickEvent(event);
return (B) this;
}

@Override
public @Nullable HoverEvent<?> hoverEvent() {
return this.styleBuilder().hoverEvent();
}

@Override
@SuppressWarnings("unchecked")
public @NotNull B hoverEvent(final @Nullable HoverEventSource<?> source) {
this.styleBuilder().hoverEvent(source);
return (B) this;
}

@Override
public @Nullable String insertion() {
return this.styleBuilder().insertion();
}

@Override
@SuppressWarnings("unchecked")
public @NotNull B insertion(final @Nullable String insertion) {
Expand Down
79 changes: 78 additions & 1 deletion api/src/main/java/net/kyori/adventure/text/ComponentBuilder.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,16 +31,20 @@
import net.kyori.adventure.builder.AbstractBuilder;
import net.kyori.adventure.key.Key;
import net.kyori.adventure.text.event.ClickEvent;
import net.kyori.adventure.text.event.HoverEvent;
import net.kyori.adventure.text.event.HoverEventSource;
import net.kyori.adventure.text.format.MutableStyleSetter;
import net.kyori.adventure.text.format.ShadowColor;
import net.kyori.adventure.text.format.Style;
import net.kyori.adventure.text.format.StyleGetter;
import net.kyori.adventure.text.format.TextColor;
import net.kyori.adventure.text.format.TextDecoration;
import net.kyori.adventure.util.Buildable;
import org.jetbrains.annotations.ApiStatus;
import org.jetbrains.annotations.Contract;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.jetbrains.annotations.Unmodifiable;

/**
* A component builder.
Expand All @@ -50,7 +54,7 @@
* @since 4.0.0
*/
@ApiStatus.NonExtendable
public interface ComponentBuilder<C extends BuildableComponent<C, B>, B extends ComponentBuilder<C, B>> extends AbstractBuilder<C>, Buildable.Builder<C>, ComponentBuilderApplicable, ComponentLike, MutableStyleSetter<B> {
public interface ComponentBuilder<C extends BuildableComponent<C, B>, B extends ComponentBuilder<C, B>> extends AbstractBuilder<C>, Buildable.Builder<C>, ComponentBuilderApplicable, ComponentLike, MutableStyleSetter<B>, StyleGetter {
/**
* Appends a component to this component.
*
Expand Down Expand Up @@ -209,6 +213,15 @@ public interface ComponentBuilder<C extends BuildableComponent<C, B>, B extends
@Contract("_ -> this")
@NotNull B style(final @NotNull Consumer<Style.Builder> consumer);

/**
* {@inheritDoc}
*
* @since 4.25.0
* @sinceMinecraft 1.16
*/
@Override
@Nullable Key font();

/**
* Sets the font of this component.
*
Expand All @@ -220,6 +233,14 @@ public interface ComponentBuilder<C extends BuildableComponent<C, B>, B extends
@Override
@NotNull B font(final @Nullable Key font);

/**
* {@inheritDoc}
*
* @since 4.25.0
*/
@Override
@Nullable TextColor color();

/**
* Sets the color of this component.
*
Expand All @@ -242,6 +263,38 @@ public interface ComponentBuilder<C extends BuildableComponent<C, B>, B extends
@Override
@NotNull B colorIfAbsent(final @Nullable TextColor color);

/**
* {@inheritDoc}
*
* @since 4.25.0
*/
@Override
@Nullable ShadowColor shadowColor();

/**
* {@inheritDoc}
*
* @since 4.25.0
*/
@Override
boolean hasDecoration(final @NotNull TextDecoration decoration);

/**
* {@inheritDoc}
*
* @since 4.25.0
*/
@Override
TextDecoration.@NotNull State decoration(final @NotNull TextDecoration decoration);

/**
* {@inheritDoc}
*
* @since 4.25.0
*/
@Override
@Unmodifiable @NotNull Map<TextDecoration, TextDecoration.State> decorations();

/**
* Sets the state of a set of decorations to {@code flag} on this component.
*
Expand Down Expand Up @@ -341,6 +394,14 @@ public interface ComponentBuilder<C extends BuildableComponent<C, B>, B extends
@Override
@NotNull B decorationIfAbsent(final @NotNull TextDecoration decoration, final TextDecoration.@NotNull State state);

/**
* {@inheritDoc}
*
* @since 4.25.0
*/
@Override
@Nullable ClickEvent clickEvent();

/**
* Sets the click event of this component.
*
Expand All @@ -352,6 +413,14 @@ public interface ComponentBuilder<C extends BuildableComponent<C, B>, B extends
@Override
@NotNull B clickEvent(final @Nullable ClickEvent event);

/**
* {@inheritDoc}
*
* @since 4.25.0
*/
@Override
@Nullable HoverEvent<?> hoverEvent();

/**
* Sets the hover event of this component.
*
Expand All @@ -363,6 +432,14 @@ public interface ComponentBuilder<C extends BuildableComponent<C, B>, B extends
@Override
@NotNull B hoverEvent(final @Nullable HoverEventSource<?> source);

/**
* {@inheritDoc}
*
* @since 4.25.0
*/
@Override
@Nullable String insertion();

/**
* Sets the string to be inserted when this component is shift-clicked.
*
Expand Down
77 changes: 76 additions & 1 deletion api/src/main/java/net/kyori/adventure/text/format/Style.java
Original file line number Diff line number Diff line change
Expand Up @@ -682,7 +682,16 @@ public enum Strategy {
*
* @since 4.0.0
*/
interface Builder extends AbstractBuilder<Style>, Buildable.Builder<Style>, MutableStyleSetter<Builder> {
interface Builder extends AbstractBuilder<Style>, Buildable.Builder<Style>, MutableStyleSetter<Builder>, StyleGetter {
/**
* {@inheritDoc}
*
* @since 4.25.0
* @sinceMinecraft 1.16
*/
@Override
@Nullable Key font();

/**
* Sets the font.
*
Expand All @@ -695,6 +704,14 @@ interface Builder extends AbstractBuilder<Style>, Buildable.Builder<Style>, Muta
@Contract("_ -> this")
@NotNull Builder font(final @Nullable Key font);

/**
* {@inheritDoc}
*
* @since 4.25.0
*/
@Override
@Nullable TextColor color();

/**
* Sets the color.
*
Expand All @@ -717,6 +734,40 @@ interface Builder extends AbstractBuilder<Style>, Buildable.Builder<Style>, Muta
@Contract("_ -> this")
@NotNull Builder colorIfAbsent(final @Nullable TextColor color);

/**
* {@inheritDoc}
*
* @since 4.25.0
*/
@Override
@Nullable ShadowColor shadowColor();

/**
* {@inheritDoc}
*
* @since 4.25.0
*/
@Override
default boolean hasDecoration(final @NotNull TextDecoration decoration) {
return StyleGetter.super.hasDecoration(decoration);
}

/**
* {@inheritDoc}
*
* @since 4.25.0
*/
@Override
TextDecoration.@NotNull State decoration(final @NotNull TextDecoration decoration);

/**
* {@inheritDoc}
*
* @since 4.25.0
*/
@Override
@Unmodifiable @NotNull Map<TextDecoration, TextDecoration.State> decorations();

/**
* Sets {@code decoration} to {@link TextDecoration.State#TRUE}.
*
Expand Down Expand Up @@ -800,6 +851,14 @@ interface Builder extends AbstractBuilder<Style>, Buildable.Builder<Style>, Muta
@Contract("_, _ -> this")
@NotNull Builder decorationIfAbsent(final @NotNull TextDecoration decoration, final TextDecoration.@NotNull State state);

/**
* {@inheritDoc}
*
* @since 4.25.0
*/
@Override
@Nullable ClickEvent clickEvent();

/**
* Sets the click event.
*
Expand All @@ -811,6 +870,14 @@ interface Builder extends AbstractBuilder<Style>, Buildable.Builder<Style>, Muta
@Contract("_ -> this")
@NotNull Builder clickEvent(final @Nullable ClickEvent event);

/**
* {@inheritDoc}
*
* @since 4.25.0
*/
@Override
@Nullable HoverEvent<?> hoverEvent();

/**
* Sets the hover event.
*
Expand All @@ -822,6 +889,14 @@ interface Builder extends AbstractBuilder<Style>, Buildable.Builder<Style>, Muta
@Contract("_ -> this")
@NotNull Builder hoverEvent(final @Nullable HoverEventSource<?> source);

/**
* {@inheritDoc}
*
* @since 4.25.0
*/
@Override
@Nullable String insertion();

/**
* Sets the string to be inserted.
*
Expand Down
Loading