Skip to content

Lesson 6 of 13 · 18m

Text Is a Component: Adventure and MiniMessage

Component trees, MiniMessage for admin-written text, audiences, and why § codes are legacy plumbing.

§aHello is not a string. It is a formatting protocol smuggled through chars, and it has been retired. Paper ships Kyori's Adventure library natively, and every modern text surface — chat, kick messages, item names, tab lists, boss bars — is a net.kyori.adventure.text.Component. The ChatColor enum and § section signs still work; they are compatibility plumbing, not an API. New code speaks components.

Building components

Component msg = Component.text("Kicked: ")
    .color(NamedTextColor.RED)
    .append(Component.text(reason, NamedTextColor.WHITE))
    .hoverEvent(HoverEvent.showText(Component.text("Appeal in /discord")))
    .clickEvent(ClickEvent.runCommand("/discord"));

player.sendMessage(msg);
player.sendActionBar(Component.text("3 hearts", NamedTextColor.DARK_RED));
player.sendTitlePart(TitlePart.TITLE, Component.text("You died"));

Style lives on the component, not in an escape code: .color(...), .decoration(TextDecoration.BOLD, true), hover and click events attached per component. A Component is a tree — children inherit and override style — and Paper renders it per player, including per-player localization via Component.translatable("key", args) when you ship language files.

MiniMessage for human-written text

When the text comes from a config file or an admin, hand them MiniMessage instead of & codes:

MiniMessage mm = MiniMessage.miniMessage();
Component welcome = mm.deserialize(
    "<gradient:#ff0000:#0000ff>Welcome back, <player>!</gradient>",
    Placeholder.unparsed("player", player.getName()));

<red>, <#1a2b3c>, <bold>, <click:run_command:/spawn>, <hover:show_text:'...'>, <gradient> — a readable tag language designed for exactly this job. Admins write MiniMessage in messages.yml; you deserialize once at load and cache the components.

Two footguns, both real. First, Placeholder.unparsed — not Placeholder.component or raw string substitution — inserts the player's name as literal text. String-replacing a name into markup means a player named <red>griefer injects tags into your template. Second, tags like <click:run_command> execute as the player who clicks: never deserialize untrusted input through MiniMessage. Player-supplied strings go through Component.text(...), full stop.

Placeholder.component("name", Component.text(...)) is the variant for substituting a styled component into a template — the right tool when the placeholder carries its own color or hover, wrong for raw names.

MiniMessage also runs the other direction: mm.serialize(component) renders a built component back to tag markup — the trick that lets messages.yml round-trip text a player clicked through.

Audiences, not sendMessage(String)

player.sendMessage("a string") is the deprecated legacy path. The modern call sits on an Audience: player.sendMessage(Component), sender.sendActionBar(...), server.broadcast(component). Audience covers players, console, and broadcast groups, so one component renders correctly everywhere — including boss bars (player.showBossBar(...)) and the player list header/footer.

ClickEvent covers more than runCommand: suggestCommand fills the player's chat box, openUrl opens a link after the client confirms, copyToClipboard drops text on the clipboard, and changePage drives book UIs — all running as the clicking player, never as you. For lists of components — online admins, parsed arguments — Component.join(JoinConfiguration.separator(Component.text(", ")), parts) flattens them the way String.join does strings.

Titles, boss bars, and the tab list

The surfaces nobody expects to be components all are. player.sendTitlePart(TitlePart.TIMES, TitleTimes.times(...)) controls fade and hold; player.showBossBar(BossBar.bossBar(component, progress, color, overlay)) builds the bar; player.sendPlayerListHeaderAndFooter(header, footer) styles the tab list. All three take components — there is no sendTitle(String) worth using anymore.

Migrating old content is one call: LegacyComponentSerializer.legacySection().deserialize("§aold text"), or legacyAmpersand() for &-style configs. Run it at load on legacy values, cache the result, never emit raw § again.

The trap that bites at scale is deserializing per send. mm.deserialize(configLine) inside a listener re-parses the markup for every player, every event. Parse once in onEnable, store the Component, and player.sendMessage(cached) — the per-player work becomes a field read, which is the difference between a plugin that matters in the profiler and one that doesn't.

Field notes

  • NamedTextColor covers the classic 16 colors; TextColor.color(0xRRGGBB) covers the rest.
  • AsyncChatEvent's renderer() is where chat formatting belongs — reshape the rendered message there, not by mutating the event's stored text.
  • player.kick(Component) renders on the disconnect screen; a kicked player's screen is one more text surface worth getting right.
  • Persist components with GsonComponentSerializer.gson() — the JSON tree keeps clicks, hovers, and colors that plain text drops.
  • player.locale() plus Component.translatable is the honest i18n path; hardcoded English is a choice, not a default.

Was this lesson helpful?

Sign in to rate

Keep reading

Related articles from the SudoSecurity blog.