Class ChatFormatBuilder
java.lang.Object
ovh.mythmc.social.api.chat.format.ChatFormatBuilder
Builds the prefix component for a
ChatChannel.
A format is assembled by appending SocialInjectedValue slots in
order.
Static text components are wrapped with append(TextComponent), while
context-dependent elements can use
appendConditional(TextComponent, java.util.function.Predicate)
or arbitrary SocialInjectedValue instances via
injectValue(SocialInjectedValue).
-
Method Summary
Modifier and TypeMethodDescriptionappend(@NotNull TextComponent component) Appends a static text component as a literal injected value.append(@NotNull TextComponent component, int index) Inserts a static text component as a literal injected value at the given index.appendConditional(@NotNull TextComponent component, @NotNull Predicate<SocialParserContext> predicate) Appends a conditional text component; it is only rendered whenpredicateevaluates totruefor the current parser context.appendConditional(@NotNull TextComponent component, @NotNull Predicate<SocialParserContext> predicate, int index) Inserts a conditional text component at the given index; it is only rendered whenpredicateevaluates totruefor the current parser context.Appends a single space as a literal injected value.static ChatFormatBuilderempty()Creates an empty format with no injected values.static ChatFormatBuilderfrom(@NotNull TextComponent base) Creates a format pre-populated with the given text component.injectValue(@NotNull SocialInjectedValue<?, ?> injectedValue) Appends a single injected value to the end of this format.injectValue(@NotNull SocialInjectedValue<?, ?> injectedValue, int index) Inserts a single injected value at the given index.injectValues(@NotNull Iterable<? extends SocialInjectedValue<?, ?>> injectedValues) Appends each of the given injected values to this format.preRenderPrefix(@NotNull SocialUser target, @NotNull Iterable<? extends ChatRendererFeature> supportedFeatures, @NotNull SocialRegisteredMessageContext message, @NotNull SocialParserContext parser) Evaluates all renderer features and then renders the full prefix component.
-
Method Details
-
empty
Creates an empty format with no injected values.- Returns:
- an empty builder
-
from
Creates a format pre-populated with the given text component.- Parameters:
base- the initial component- Returns:
- a builder with the component appended
-
injectValues
public ChatFormatBuilder injectValues(@NotNull @NotNull Iterable<? extends SocialInjectedValue<?, ?>> injectedValues) Appends each of the given injected values to this format.- Parameters:
injectedValues- the values to append- Returns:
- this builder
-
injectValue
Appends a single injected value to the end of this format.- Parameters:
injectedValue- the value to append- Returns:
- this builder
-
injectValue
public ChatFormatBuilder injectValue(@NotNull @NotNull SocialInjectedValue<?, ?> injectedValue, int index) Inserts a single injected value at the given index.- Parameters:
injectedValue- the value to insertindex- the position to insert at- Returns:
- this builder
-
append
Inserts a static text component as a literal injected value at the given index.- Parameters:
component- the component to insertindex- the position to insert at- Returns:
- this builder
-
append
Appends a static text component as a literal injected value.- Parameters:
component- the component to append- Returns:
- this builder
-
appendConditional
public ChatFormatBuilder appendConditional(@NotNull @NotNull TextComponent component, @NotNull @NotNull Predicate<SocialParserContext> predicate, int index) Inserts a conditional text component at the given index; it is only rendered whenpredicateevaluates totruefor the current parser context.- Parameters:
component- the component to show when the predicate matchespredicate- the condition under which the component is renderedindex- the position to insert at- Returns:
- this builder
-
appendConditional
public ChatFormatBuilder appendConditional(@NotNull @NotNull TextComponent component, @NotNull @NotNull Predicate<SocialParserContext> predicate) Appends a conditional text component; it is only rendered whenpredicateevaluates totruefor the current parser context.- Parameters:
component- the component to show when the predicate matchespredicate- the condition under which the component is rendered- Returns:
- this builder
-
appendSpace
Appends a single space as a literal injected value.- Returns:
- this builder
-
preRenderPrefix
public Component preRenderPrefix(@NotNull @NotNull SocialUser target, @NotNull @NotNull Iterable<? extends ChatRendererFeature> supportedFeatures, @NotNull @NotNull SocialRegisteredMessageContext message, @NotNull @NotNull SocialParserContext parser) Evaluates all renderer features and then renders the full prefix component.This is called internally by
ChatChannel.prefix(SocialUser, SocialRegisteredMessageContext, SocialParserContext)implementations and should not normally be invoked directly from plugin code.- Parameters:
target- the player the prefix is being rendered forsupportedFeatures- the renderer features active on the channelmessage- the registered message contextparser- the parser context, which receives the injected values- Returns:
- the fully resolved prefix component
-