Skip to content

Commit 1a4ce6c

Browse files
CopilotTrilleo
andauthored
Internal: Add Adventure Library section to Developer Guide
Agent-Logs-Url: https://github.com/Trilleo/PaperExamplePlugin/sessions/26c2bc7c-4623-4dc3-874e-83249804ced9 Co-authored-by: Trilleo <133519132+Trilleo@users.noreply.github.com>
1 parent 8d3caeb commit 1a4ce6c

1 file changed

Lines changed: 137 additions & 0 deletions

File tree

‎docs/DEVELOPER_GUIDE.md‎

Lines changed: 137 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -476,6 +476,143 @@ class RewardsCommand : PluginCommand(
476476

477477
---
478478

479+
## Adventure Library
480+
481+
Paper bundles the [Kyori Adventure](https://docs.advntr.dev/) library, so no extra dependency is required. Adventure
482+
replaces the legacy Bukkit chat API and provides rich, structured text through immutable `Component` objects.
483+
484+
### Component
485+
486+
`Component` is the core type. Use `Component.text(...)` to create a plain-text component, and optionally apply a
487+
colour or decoration inline:
488+
489+
```kotlin
490+
import net.kyori.adventure.text.Component
491+
import net.kyori.adventure.text.format.NamedTextColor
492+
import net.kyori.adventure.text.format.TextDecoration
493+
494+
// Plain text
495+
val plain = Component.text("Hello, world!")
496+
497+
// Coloured text
498+
val coloured = Component.text("Hello, world!", NamedTextColor.GREEN)
499+
500+
// Bold + coloured text
501+
val bold = Component.text("Hello, world!", NamedTextColor.GOLD, TextDecoration.BOLD)
502+
```
503+
504+
#### NamedTextColor
505+
506+
`NamedTextColor` exposes the 16 standard Minecraft colours as constants:
507+
508+
| Constant | In-game appearance |
509+
|:----------------|:---------------------|
510+
| `BLACK` | Black |
511+
| `DARK_BLUE` | Dark Blue |
512+
| `DARK_GREEN` | Dark Green |
513+
| `DARK_AQUA` | Dark Aqua |
514+
| `DARK_RED` | Dark Red |
515+
| `DARK_PURPLE` | Dark Purple |
516+
| `GOLD` | Gold |
517+
| `GRAY` | Gray |
518+
| `DARK_GRAY` | Dark Gray |
519+
| `BLUE` | Blue |
520+
| `GREEN` | Green |
521+
| `AQUA` | Aqua |
522+
| `RED` | Red |
523+
| `LIGHT_PURPLE` | Light Purple |
524+
| `YELLOW` | Yellow |
525+
| `WHITE` | White |
526+
527+
#### TextDecoration
528+
529+
`TextDecoration` applies visual styles to a component:
530+
531+
| Constant | Effect |
532+
|:----------------|:--------------------|
533+
| `BOLD` | Bold text |
534+
| `ITALIC` | Italic text |
535+
| `UNDERLINED` | Underlined text |
536+
| `STRIKETHROUGH` | Strikethrough text |
537+
| `OBFUSCATED` | Obfuscated (matrix) |
538+
539+
### Chaining Components
540+
541+
Use `.append(Component)` to concatenate multiple styled segments into one message:
542+
543+
```kotlin
544+
import net.kyori.adventure.text.Component
545+
import net.kyori.adventure.text.format.NamedTextColor
546+
import net.kyori.adventure.text.format.TextDecoration
547+
548+
val message = Component.text("[ExamplePlugin] ", NamedTextColor.GOLD, TextDecoration.BOLD)
549+
.append(Component.text("Welcome to the server!", NamedTextColor.YELLOW))
550+
551+
sender.sendMessage(message)
552+
```
553+
554+
### Sending Messages
555+
556+
Both `CommandSender` (players and the console) and `Player` accept a `Component` directly via `sendMessage`:
557+
558+
```kotlin
559+
// From a command
560+
sender.sendMessage(Component.text("Command executed!", NamedTextColor.GREEN))
561+
562+
// From a listener
563+
event.player.sendMessage(Component.text("You joined!", NamedTextColor.AQUA))
564+
```
565+
566+
To broadcast a message to every online player, use the Bukkit server instance:
567+
568+
```kotlin
569+
import org.bukkit.Bukkit
570+
571+
Bukkit.broadcast(Component.text("Server announcement!", NamedTextColor.GOLD))
572+
```
573+
574+
### MiniMessage
575+
576+
[MiniMessage](https://docs.advntr.dev/minimessage/index.html) is a string-based format that lets you express rich
577+
text with lightweight tags. The `ItemStack` DSL uses it internally, and you can use it anywhere you need to parse
578+
user-facing strings (e.g. from `config.yml`) into `Component` objects.
579+
580+
```kotlin
581+
import net.kyori.adventure.text.minimessage.MiniMessage
582+
583+
val mm = MiniMessage.miniMessage()
584+
585+
// Colour
586+
val red = mm.deserialize("<red>This is red text")
587+
588+
// Bold + gradient
589+
val fancy = mm.deserialize("<bold><gradient:gold:yellow>Fancy Title</gradient></bold>")
590+
591+
// Multiple colours in one line
592+
val mixed = mm.deserialize("<green>Success: <white>operation completed")
593+
594+
sender.sendMessage(fancy)
595+
```
596+
597+
#### Common MiniMessage Tags
598+
599+
| Tag | Effect |
600+
|:---------------------------------|:------------------------------------------------|
601+
| `<color_name>` / `<red>` | Named colour (same names as `NamedTextColor`) |
602+
| `<#RRGGBB>` | Hex colour |
603+
| `<bold>`, `<b>` | Bold |
604+
| `<italic>`, `<i>` | Italic |
605+
| `<underlined>`, `<u>` | Underline |
606+
| `<strikethrough>`, `<st>` | Strikethrough |
607+
| `<obfuscated>`, `<obf>` | Obfuscated |
608+
| `<gradient:color1:color2>` | Smooth gradient between two colours |
609+
| `<reset>` | Reset all active styles |
610+
| `<newline>` / `<br>` | Line break |
611+
| `<click:run_command:/cmd>` | Clickable text that runs a command |
612+
| `<hover:show_text:'...'>` | Text shown when the cursor hovers over the line |
613+
614+
---
615+
479616
## ItemStack Builder DSL
480617

481618
Building `ItemStack` instances with custom names, lore, enchantments, and flags normally requires verbose

0 commit comments

Comments
 (0)