Skip to content

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:

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.

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.

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.Sound
final Sound sound = Sound.sound()
.pitch(1.5f)
.volume(100.0f)
.type(org.bukkit.Sound.ENTITY_PLAYER_LEVELUP)
.build();
Bukkit.getServer().playSound(sound);
Preview

Learn Paper Dev is licensed under CC BY-NC-SA 4.0