Interface Audience
- All Superinterfaces:
Pointered
- All Known Subinterfaces:
ForwardingAudience
,ForwardingAudience.Single
public interface Audience extends Pointered
Audience
is designed to be a universal interface for any player,
command sender, console, or otherwise who can receive text, titles,
boss bars, and other Minecraft media. It is also designed for a group of
receivers such as a team, server, world, or permission.
In the past, Minecraft platforms have typically reserved methods such as
showTitle
for a Player
interface. While this is good
textbook object-oriented design, it presents two key drawbacks: 1) there
is no abstraction for groups of players, such as a Server
or a
Team
and 2) it add boilerplate for handling special cases like
console or command senders.
Consider the use-case of sending a message and title to every player on a
server, and also sending a message to console. Without an Audience
,
the code might look like this:
Server server; for (Player player : server.getPlayers()) { player.sendMessage(...); player.showTitle(...); } server.getConsole().sendMessage(...);
Now, if Server
implemented Audience
, its unified interface
would allow users to easily send media without if-guarding console or
iterating through the list of players:
Server server; server.sendMessage(...); // Sends a message to players and console server.showTitle(...); // Shows a title to players, silently ignored by console
When an Audience
is unable to perform an operation, such as sending
a boss bar to console, it will silently fail, without logging. This
requirement allows users to easily send media to a group of
Audience
s without checking each for compatibility.
While the scope of Audience
may be expanded in the future to support
new Minecraft media such as the player list, its interface will remain stateless
and any new methods will be stubbed by default.
- Since:
- 4.0.0
- See Also:
ForwardingAudience
-
Method Summary
Modifier and Type Method Description static @NotNull ForwardingAudience
audience(@NotNull Iterable<? extends Audience> audiences)
Creates an audience that forwards to many other audiences.static @NotNull Audience
audience(@NotNull Audience @NotNull ... audiences)
Creates an audience that forwards to many other audiences.default void
clearTitle()
Clears the title, if one is being displayed.static @NotNull Audience
empty()
Gets an audience that does nothing.default void
hideBossBar(@NotNull BossBar bar)
Hides a boss bar.default void
openBook(@NotNull Book book)
Opens a book.default void
openBook(@NotNull Book.Builder book)
Opens a book.default void
playSound(@NotNull Sound sound)
Plays a sound at the location of the recipient of the sound.default void
playSound(@NotNull Sound sound, double x, double y, double z)
Plays a sound at a location.default void
playSound(@NotNull Sound sound, @NotNull Sound.Emitter emitter)
Plays a sound from an emitter, usually an entity.default void
resetTitle()
Resets the title and timings back to their default.default void
sendActionBar(@NotNull Component message)
Sends a message on the action bar.default void
sendActionBar(@NotNull ComponentLike message)
Sends a message on the action bar.default void
sendMessage(@NotNull Identified source, @NotNull Component message)
Sends a chat message from the givenIdentified
to thisAudience
.default void
sendMessage(@NotNull Identified source, @NotNull ComponentLike message)
Sends a chat message from the givenIdentified
to thisAudience
.default void
sendMessage(@NotNull Identified source, @NotNull ComponentLike message, @NotNull MessageType type)
Sends a chat message from the givenIdentified
to thisAudience
.default void
sendMessage(@NotNull Identified source, @NotNull Component message, @NotNull MessageType type)
Sends a chat message.default void
sendMessage(@NotNull Identity source, @NotNull Component message)
Sends a chat message from the entity represented by the givenIdentity
(or the game usingIdentity.nil()
) to thisAudience
.default void
sendMessage(@NotNull Identity source, @NotNull ComponentLike message)
Sends a chat message from the entity represented by the givenIdentity
(or the game usingIdentity.nil()
) to thisAudience
.default void
sendMessage(@NotNull Identity source, @NotNull ComponentLike message, @NotNull MessageType type)
Sends a chat message from the entity represented by the givenIdentity
(or the game usingIdentity.nil()
) to thisAudience
.default void
sendMessage(@NotNull Identity source, @NotNull Component message, @NotNull MessageType type)
Sends a chat message.default void
sendMessage(@NotNull Component message)
default void
sendMessage(@NotNull ComponentLike message)
default void
sendMessage(@NotNull ComponentLike message, @NotNull MessageType type)
default void
sendMessage(@NotNull Component message, @NotNull MessageType type)
default void
sendPlayerListFooter(@NotNull Component footer)
Sends the player list footer.default void
sendPlayerListFooter(@NotNull ComponentLike footer)
Sends the player list footer.default void
sendPlayerListHeader(@NotNull Component header)
Sends the player list header.default void
sendPlayerListHeader(@NotNull ComponentLike header)
Sends the player list header.default void
sendPlayerListHeaderAndFooter(@NotNull ComponentLike header, @NotNull ComponentLike footer)
Sends the player list header and footer.default void
sendPlayerListHeaderAndFooter(@NotNull Component header, @NotNull Component footer)
Sends the player list header and footer.default void
showBossBar(@NotNull BossBar bar)
Shows a boss bar.default void
showTitle(@NotNull Title title)
Shows a title.default void
stopSound(@NotNull Sound sound)
Stops a sound.default void
stopSound(@NotNull SoundStop stop)
Stops a sound, or many sounds.static @NotNull Collector<? super Audience,?,ForwardingAudience>
toAudience()
Provides a collector to create a forwarding audience from a stream of audiences.Methods inherited from interface net.kyori.adventure.pointer.Pointered
get, getOrDefault, getOrDefaultFrom, pointers
-
Method Details
-
empty
Gets an audience that does nothing.- Returns:
- a do-nothing audience
- Since:
- 4.0.0
-
audience
Creates an audience that forwards to many other audiences.- Parameters:
audiences
- an array of audiences, can be empty- Returns:
- an audience
- Since:
- 4.0.0
- See Also:
ForwardingAudience
-
audience
@NotNull static @NotNull ForwardingAudience audience(@NotNull @NotNull Iterable<? extends Audience> audiences)Creates an audience that forwards to many other audiences.The underlying
Iterable
is not copied, therefore any changes made will be reflected inAudience
.- Parameters:
audiences
- an iterable of audiences, can be empty- Returns:
- an audience
- Since:
- 4.0.0
- See Also:
ForwardingAudience
-
toAudience
Provides a collector to create a forwarding audience from a stream of audiences.The audience produced is immutable and can be reused as desired.
- Returns:
- a collector to create a forwarding audience
- Since:
- 4.0.0
-
sendMessage
- Parameters:
message
- a message- Since:
- 4.1.0
- See Also:
Component
,sendMessage(Identified, ComponentLike)
,sendMessage(Identity, ComponentLike)
-
sendMessage
default void sendMessage(@NotNull @NotNull Identified source, @NotNull @NotNull ComponentLike message)Sends a chat message from the givenIdentified
to thisAudience
.- Parameters:
source
- the source of the messagemessage
- a message- Since:
- 4.0.0
- See Also:
Component
-
sendMessage
default void sendMessage(@NotNull @NotNull Identity source, @NotNull @NotNull ComponentLike message)Sends a chat message from the entity represented by the givenIdentity
(or the game usingIdentity.nil()
) to thisAudience
.- Parameters:
source
- the identity of the source of the messagemessage
- a message- Since:
- 4.0.0
- See Also:
Component
-
sendMessage
- Parameters:
message
- a message- Since:
- 4.1.0
- See Also:
Component
,sendMessage(Identified, Component)
,sendMessage(Identity, Component)
-
sendMessage
Sends a chat message from the givenIdentified
to thisAudience
.- Parameters:
source
- the source of the messagemessage
- a message- Since:
- 4.0.0
- See Also:
Component
-
sendMessage
Sends a chat message from the entity represented by the givenIdentity
(or the game usingIdentity.nil()
) to thisAudience
.- Parameters:
source
- the identity of the source of the messagemessage
- a message- Since:
- 4.0.0
- See Also:
Component
-
sendMessage
default void sendMessage(@NotNull @NotNull ComponentLike message, @NotNull @NotNull MessageType type)- Parameters:
message
- a messagetype
- the type- Since:
- 4.1.0
- See Also:
Component
,sendMessage(Identified, ComponentLike, MessageType)
,sendMessage(Identity, ComponentLike, MessageType)
-
sendMessage
default void sendMessage(@NotNull @NotNull Identified source, @NotNull @NotNull ComponentLike message, @NotNull @NotNull MessageType type)Sends a chat message from the givenIdentified
to thisAudience
.- Parameters:
source
- the source of the messagemessage
- a messagetype
- the type- Since:
- 4.0.0
- See Also:
Component
-
sendMessage
default void sendMessage(@NotNull @NotNull Identity source, @NotNull @NotNull ComponentLike message, @NotNull @NotNull MessageType type)Sends a chat message from the entity represented by the givenIdentity
(or the game usingIdentity.nil()
) to thisAudience
.- Parameters:
source
- the identity of the source of the messagemessage
- a messagetype
- the type- Since:
- 4.0.0
- See Also:
Component
-
sendMessage
- Parameters:
message
- a messagetype
- the type- Since:
- 4.1.0
- See Also:
Component
,sendMessage(Identified, Component, MessageType)
,sendMessage(Identity, Component, MessageType)
-
sendMessage
default void sendMessage(@NotNull @NotNull Identified source, @NotNull @NotNull Component message, @NotNull @NotNull MessageType type)Sends a chat message.- Parameters:
source
- the source of the messagemessage
- a messagetype
- the type- Since:
- 4.0.0
- See Also:
Component
-
sendMessage
default void sendMessage(@NotNull @NotNull Identity source, @NotNull @NotNull Component message, @NotNull @NotNull MessageType type)Sends a chat message.- Parameters:
source
- the identity of the source of the messagemessage
- a messagetype
- the type- Since:
- 4.0.0
- See Also:
Component
-
sendActionBar
Sends a message on the action bar.- Parameters:
message
- a message- Since:
- 4.0.0
- See Also:
Component
-
sendActionBar
Sends a message on the action bar.- Parameters:
message
- a message- Since:
- 4.0.0
- See Also:
Component
-
sendPlayerListHeader
Sends the player list header.Depending on the implementation of this
Audience
, an existing footer may be displayed. If you wish to set both the header and the footer, please usesendPlayerListHeaderAndFooter(ComponentLike, ComponentLike)
.- Parameters:
header
- the header- Since:
- 4.3.0
-
sendPlayerListHeader
Sends the player list header.Depending on the implementation of this
Audience
, an existing footer may be displayed. If you wish to set both the header and the footer, please usesendPlayerListHeaderAndFooter(Component, Component)
.- Parameters:
header
- the header- Since:
- 4.3.0
-
showTitle
Shows a title.- Parameters:
title
- a title- Since:
- 4.0.0
- See Also:
Title
-
clearTitle
default void clearTitle()Clears the title, if one is being displayed.- Since:
- 4.0.0
- See Also:
Title
-
resetTitle
default void resetTitle()Resets the title and timings back to their default.- Since:
- 4.0.0
- See Also:
Title
-
showBossBar
Shows a boss bar.- Parameters:
bar
- a boss bar- Since:
- 4.0.0
- See Also:
BossBar
-
hideBossBar
Hides a boss bar.- Parameters:
bar
- a boss bar- Since:
- 4.0.0
- See Also:
BossBar
-
playSound
Plays a sound at the location of the recipient of the sound.To play a sound that follows the recipient, use
playSound(Sound, Sound.Emitter)
withSound.Emitter.self()
.- Parameters:
sound
- a sound- Since:
- 4.0.0
- See Also:
Sound
-
playSound
Plays a sound at a location.- Parameters:
sound
- a soundx
- x coordinatey
- y coordinatez
- z coordinate- Since:
- 4.0.0
- See Also:
Sound
-
stopSound
Stops a sound.- Parameters:
sound
- the sound- Since:
- 4.8.0
-
playSound
Plays a sound from an emitter, usually an entity.Sounds played using this method will follow the emitter unless the sound is a custom sound. In this case the sound will be played at the location of the emitter and will not follow them.
To play a sound that follows the recipient, use
Sound.Emitter.self()
.Note: Due to MC-138832, the volume and pitch may be ignored when using this method.
- Parameters:
sound
- a soundemitter
- an emitter- Since:
- 4.8.0
-
stopSound
Stops a sound, or many sounds.- Parameters:
stop
- a sound stop- Since:
- 4.0.0
- See Also:
SoundStop
-
openBook
Opens a book.When possible, no item should persist after closing the book.
- Parameters:
book
- a book- Since:
- 4.0.0
- See Also:
Book
-
openBook
Opens a book.When possible, no item should persist after closing the book.
- Parameters:
book
- a book- Since:
- 4.0.0
- See Also:
Book
-