use of net.kyori.adventure.text.minimessage.MiniMessage in project DiscordSRV by Scarsz.
the class MessageUtil method toComponent.
/**
* Converts the message to a {@link Component} using legacy or MiniMessage format.
*
* @param message the message to convert
* @param useLegacy if legacy formatting should be used (otherwise MiniMessage)
* @return the converted {@link Component}
*/
public static Component toComponent(String message, boolean useLegacy) {
if (useLegacy) {
TextComponent component = LEGACY_SERIALIZER.deserialize(message);
List<Component> children = new ArrayList<>(component.children());
children.add(0, Component.text(component.content()).style(component.style()));
component = component.content("").style(Style.empty()).children(children);
return component;
} else {
Component component = MiniMessage.get().parse(message);
component = component.replaceText(TextReplacementConfig.builder().match(DEFAULT_URL_PATTERN).replacement((url) -> (url).clickEvent(ClickEvent.openUrl(url.content()))).build());
return component;
}
}
Aggregations