Search in sources :

Example 1 with Style

use of net.kyori.adventure.text.format.Style 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;
    }
}
Also used : TextComponent(net.kyori.adventure.text.TextComponent) java.util(java.util) MinecraftSerializer(dev.vankka.mcdiscordreserializer.minecraft.MinecraftSerializer) Rule(dev.vankka.simpleast.core.parser.Rule) ClickEvent(net.kyori.adventure.text.event.ClickEvent) StringUtils(org.apache.commons.lang3.StringUtils) MinecraftSerializerOptions(dev.vankka.mcdiscordreserializer.minecraft.MinecraftSerializerOptions) Style(net.kyori.adventure.text.format.Style) Matcher(java.util.regex.Matcher) DiscordSRV(github.scarsz.discordsrv.DiscordSRV) Component(net.kyori.adventure.text.Component) DiscordSerializer(dev.vankka.mcdiscordreserializer.discord.DiscordSerializer) DiscordMarkdownRules(dev.vankka.mcdiscordreserializer.rules.DiscordMarkdownRules) LegacyComponentSerializer(net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer) Material(org.bukkit.Material) BukkitAudiences(net.kyori.adventure.platform.bukkit.BukkitAudiences) TextComponent(net.kyori.adventure.text.TextComponent) GsonComponentSerializer(net.kyori.adventure.text.serializer.gson.GsonComponentSerializer) CommandSender(org.bukkit.command.CommandSender) Identity(net.kyori.adventure.identity.Identity) SimpleMarkdownRules(dev.vankka.simpleast.core.simple.SimpleMarkdownRules) MiniMessage(net.kyori.adventure.text.minimessage.MiniMessage) Node(dev.vankka.simpleast.core.node.Node) Audience(net.kyori.adventure.audience.Audience) TextReplacementConfig(net.kyori.adventure.text.TextReplacementConfig) DiscordSRVMinecraftRenderer(github.scarsz.discordsrv.objects.DiscordSRVMinecraftRenderer) Pattern(java.util.regex.Pattern) Component(net.kyori.adventure.text.Component) TextComponent(net.kyori.adventure.text.TextComponent)

Aggregations

DiscordSerializer (dev.vankka.mcdiscordreserializer.discord.DiscordSerializer)1 MinecraftSerializer (dev.vankka.mcdiscordreserializer.minecraft.MinecraftSerializer)1 MinecraftSerializerOptions (dev.vankka.mcdiscordreserializer.minecraft.MinecraftSerializerOptions)1 DiscordMarkdownRules (dev.vankka.mcdiscordreserializer.rules.DiscordMarkdownRules)1 Node (dev.vankka.simpleast.core.node.Node)1 Rule (dev.vankka.simpleast.core.parser.Rule)1 SimpleMarkdownRules (dev.vankka.simpleast.core.simple.SimpleMarkdownRules)1 DiscordSRV (github.scarsz.discordsrv.DiscordSRV)1 DiscordSRVMinecraftRenderer (github.scarsz.discordsrv.objects.DiscordSRVMinecraftRenderer)1 java.util (java.util)1 Matcher (java.util.regex.Matcher)1 Pattern (java.util.regex.Pattern)1 Audience (net.kyori.adventure.audience.Audience)1 Identity (net.kyori.adventure.identity.Identity)1 BukkitAudiences (net.kyori.adventure.platform.bukkit.BukkitAudiences)1 Component (net.kyori.adventure.text.Component)1 TextComponent (net.kyori.adventure.text.TextComponent)1 TextReplacementConfig (net.kyori.adventure.text.TextReplacementConfig)1 ClickEvent (net.kyori.adventure.text.event.ClickEvent)1 Style (net.kyori.adventure.text.format.Style)1