Adventure Series: Audiences
Almost every object, which can work with input, implements/extends the Audience
interface. That includes, but is not limited to:
There are a lot of methods declared in the Audience
interface. Too many to list them all. It is recommended to just check out the JavaDocs, but the
most important ones are:
-
sendMessage(ComponentLike)
-
sendActionBar(ComponentLike)
-
sendPlayerListHeader(ComponentLike)
-
sendPlayerListFooter(ComponentLike)
-
playSound(Sound)
-
showTitle(Title)
-
showBossBar(BossBar)
-
openBook(Book)
Paper’s Server/World/Team Objects
Section titled “Paper’s Server/World/Team Objects”These objects have a special implementation of the Audience
interface: The ForwardingAudience
.
That means, instead of executing a method for themselves, it executes it for all audiences backed by the individual object.
More specifically, sending a message to a…
…Server
sends the message to every player and the console.
…World
sends the message to every player in that world.
…Team
sends the message to every player in that team.
This makes sending messages to multiple players very convenient.
Creating Forwarding Audiences
Section titled “Creating Forwarding Audiences”You can create your own forwarding audiences! For this, Audience
provides a static method:
Audience.audience(Audience...)
.
This allows for grouping multiple audiences together in order to have to only send a message (or similar) once and it reaching multiple targets.
This is particularly useful for stuff like a party system or certain mini games.
Constructing a Sound
, Title
, BossBar
, and Book
Section titled “Constructing a , , , and ”Each of these provide their own way of creating them. You can check the JavaDocs on the specifics, but I have added some basic examples to showcase their functionality.
// net.kyori.adventure.sound.Soundfinal Sound sound = Sound.sound() .pitch(1.5f) .volume(100.0f) .type(org.bukkit.Sound.ENTITY_PLAYER_LEVELUP) .build();Bukkit.getServer().playSound(sound);
Preview
// net.kyori.adventure.title.Titlefinal Title title = Title.title( Component.text("Big Top Text"), Component.text("small bottom text"), // Fade-in duration Stay duration Fade out duration Title.Times.times(Duration.ofSeconds(5), Duration.ofSeconds(5), Duration.ofSeconds(5)));Bukkit.getServer().showTitle(title);
Preview
// net.kyori.adventure.bossbar.BossBarfinal BossBar bossBar = BossBar.bossBar( miniMessage().deserialize("<gradient:aqua:light_purple:aqua><b>A very nice looking bossbar!"), 0.75f, BossBar.Color.PURPLE, BossBar.Overlay.PROGRESS, Set.of(BossBar.Flag.CREATE_WORLD_FOG));Bukkit.getServer().showBossBar(bossBar);
Preview
// net.kyori.adventure.inventory.Bookfinal Book book = Book.builder() .title(miniMessage().deserialize("<gradient:red:blue><b>Police Report")) .author(Component.text("The Police").color(NamedTextColor.GRAY)) .addPage(miniMessage().deserialize(""" <dark_gray><u><b>Report Day 1</u>
Events: <red>none</red> Found victims: <red>2</red> Cases solved: <red>none</red>
""".trim())) .addPage(miniMessage().deserialize(""" <dark_gray><u><b>Report Day 2</u>
Events: <red>1</red> Found victims: <red>none</red> Cases solved: <red>1</red>
""".trim())) .build();Bukkit.getServer().openBook(book);
Preview
Learn Paper Dev is licensed under CC BY-NC-SA 4.0