Interface Audience
- All Superinterfaces:
Pointered
- All Known Subinterfaces:
ForwardingAudience,ForwardingAudience.Single
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
Audiences 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:
-
Method Summary
Modifier and TypeMethodDescriptionstatic @NotNull ForwardingAudienceCreates an audience that forwards to many other audiences.static @NotNull AudienceCreates an audience that forwards to many other audiences.default voidClear all server-provided resource packs that have been sent to this user.default voidClears the title, if one is being displayed.default voiddeleteMessage(@NotNull SignedMessage signedMessage) Requests deletion of a message with the providedSignedMessage's signature.default voiddeleteMessage(@NotNull SignedMessage.Signature signature) Requests deletion of a message with the providedSignedMessage.Signature.static @NotNull Audienceempty()Gets an audience that does nothing.default @NotNull AudiencefilterAudience(@NotNull Predicate<? super Audience> filter) Filters this audience.default voidforEachAudience(@NotNull Consumer<? super Audience> action) Executes an action against all audiences.default voidhideBossBar(@NotNull BossBar bar) Hides a boss bar.default voidOpens a book.default voidopenBook(@NotNull Book.Builder book) Opens a book.default voidPlays a sound at the location of the recipient of the sound.default voidPlays a sound at a location.default voidplaySound(@NotNull Sound sound, @NotNull Sound.Emitter emitter) Plays a sound from an emitter, usually an entity.default voidremoveResourcePacks(@NotNull Iterable<UUID> ids) Clear resource packs with the provided ids if they are present.default voidremoveResourcePacks(@NotNull UUID id, @NotNull UUID @NotNull ... others) Clear resource packs with the provided ids if they are present.default voidremoveResourcePacks(@NotNull ResourcePackInfoLike request, @NotNull ResourcePackInfoLike @NotNull ... others) Clear resource packs with the IDs used in the provided requests if they are present.default voidremoveResourcePacks(@NotNull ResourcePackRequest request) Clear resource packs with the IDs used in the provided requests if they are present.default voidremoveResourcePacks(@NotNull ResourcePackRequestLike request) Clear resource packs with the IDs used in the provided requests if they are present.default voidResets the title and timings back to their default.default voidsendActionBar(@NotNull Component message) Sends a message on the action bar.default voidsendActionBar(@NotNull ComponentLike message) Sends a message on the action bar.default voidsendMessage(@NotNull SignedMessage signedMessage, @NotNull ChatType.Bound boundChatType) Sends a signed player message to thisAudiencewith the providedbound chat type.default voidsendMessage(@NotNull Identified source, @NotNull Component message) Deprecated.default voidsendMessage(@NotNull Identified source, @NotNull ComponentLike message) Deprecated.since 4.12.0, the client errors on and can reject identified messages withoutSignedMessagedata, this may be unsupported in the future, usesendMessage(SignedMessage, ChatType.Bound)insteaddefault voidsendMessage(@NotNull Identified source, @NotNull ComponentLike message, @NotNull MessageType type) Deprecated.for removal since 4.12.0,MessageTypeis deprecated for removal and the client errors on receiving and can reject identified messages withoutSignedMessagedata, usesendMessage(SignedMessage, ChatType.Bound)insteaddefault voidsendMessage(@NotNull Identified source, @NotNull Component message, @NotNull MessageType type) Deprecated.for removal since 4.12.0,MessageTypeis deprecated for removal and the client errors on receiving and can reject identified messages withoutSignedMessagedata, usesendMessage(SignedMessage, ChatType.Bound)insteaddefault voidsendMessage(@NotNull Identity source, @NotNull Component message) Deprecated.since 4.12.0, the client errors on receiving and can reject identified messages withoutSignedMessagedata, this may be unsupported in the future, usesendMessage(SignedMessage, ChatType.Bound)insteaddefault voidsendMessage(@NotNull Identity source, @NotNull ComponentLike message) Deprecated.since 4.12.0, the client errors on and can reject identified messages withoutSignedMessagedata, this may be unsupported in the future, usesendMessage(SignedMessage, ChatType.Bound)insteaddefault voidsendMessage(@NotNull Identity source, @NotNull ComponentLike message, @NotNull MessageType type) Deprecated.for removal since 4.12.0,MessageTypeis deprecated for removal and the client errors on receiving and can reject identified messages withoutSignedMessagedata, usesendMessage(SignedMessage, ChatType.Bound)insteaddefault voidsendMessage(@NotNull Identity source, @NotNull Component message, @NotNull MessageType type) Deprecated.for removal since 4.12.0,MessageTypeis deprecated for removal and the client errors on receiving and can reject identified messages withoutSignedMessagedata, usesendMessage(SignedMessage, ChatType.Bound)insteaddefault voidsendMessage(@NotNull Component message) Sends a system chat message to thisAudience.default voidsendMessage(@NotNull ComponentLike message) Sends a system chat message to thisAudience.default voidsendMessage(@NotNull ComponentLike message, @NotNull MessageType type) Deprecated.for removal since 4.12.0,MessageTypeis deprecated for removal, usesendMessage(ComponentLike)default voidsendMessage(@NotNull ComponentLike message, @NotNull ChatType.Bound boundChatType) Sends a message to thisAudiencewith the providedbound chat type.default voidsendMessage(@NotNull Component message, @NotNull MessageType type) Deprecated.for removal since 4.12.0,MessageTypeis deprecated for removal, usesendMessage(Component)insteaddefault voidsendMessage(@NotNull Component message, @NotNull ChatType.Bound boundChatType) Sends a message to thisAudiencewith the providedbound chat type.default voidsendPlayerListFooter(@NotNull Component footer) Sends the player list footer.default voidsendPlayerListFooter(@NotNull ComponentLike footer) Sends the player list footer.default voidsendPlayerListHeader(@NotNull Component header) Sends the player list header.default voidsendPlayerListHeader(@NotNull ComponentLike header) Sends the player list header.default voidsendPlayerListHeaderAndFooter(@NotNull ComponentLike header, @NotNull ComponentLike footer) Sends the player list header and footer.default voidsendPlayerListHeaderAndFooter(@NotNull Component header, @NotNull Component footer) Sends the player list header and footer.default voidsendResourcePacks(@NotNull ResourcePackInfoLike first, @NotNull ResourcePackInfoLike... others) Sends a request to apply resource packs to this audience.default voidsendResourcePacks(@NotNull ResourcePackRequest request) Sends a request to apply resource packs to this audience.default voidsendResourcePacks(@NotNull ResourcePackRequestLike request) Sends a request to apply resource packs to this audience.default <T> voidsendTitlePart(@NotNull TitlePart<T> part, T value) Shows a part of a title.default voidshowBossBar(@NotNull BossBar bar) Shows a boss bar.default voidshowDialog(@NotNull DialogLike dialog) Shows a dialog to this audience.default voidShows a title.default voidStops a sound.default voidStops a sound, or many sounds.static @NotNull Collector<? super Audience,?, ForwardingAudience> 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:
-
audience
@NotNull static @NotNull ForwardingAudience audience(@NotNull @NotNull Iterable<? extends Audience> audiences) Creates an audience that forwards to many other audiences.The underlying
Iterableis 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:
-
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
-
filterAudience
@NotNull default @NotNull Audience filterAudience(@NotNull @NotNull Predicate<? super Audience> filter) Filters this audience.The returned
Audiencemay be the same, or a completely different one.Container audiences such as
ForwardingAudiencemay or may not have their own identity. If they do, they may test themselves against the providedfilterfirst, and if the test fails return an empty audience skipping any contained children. If they do not, they must not test themselves against the filter, only testing their children.- Parameters:
filter- a filter that determines if an audience should be included- Returns:
- an audience providing a snapshot of all audiences that match the predicate when this method is invoked
- Since:
- 4.9.0
-
forEachAudience
Executes an action against all audiences.If you implement
Audienceand notForwardingAudiencein your own code, and your audience forwards to other audiences, then you must override this method and provide each audience toaction.If an implementation of
Audiencehas its own identity distinct from its contained children, it may test itself against the providedfilterfirst, and if the test fails return an empty audience skipping any contained children. If it does not, it must not test itself against the filter, only testing its children.- Parameters:
action- the action- Since:
- 4.9.0
-
sendMessage
Sends a system chat message to thisAudience.- Parameters:
message- a message- Since:
- 4.1.0
- See Also:
-
sendMessage
Sends a system chat message to thisAudience.- Parameters:
message- a message- Since:
- 4.1.0
- See Also:
-
sendMessage
@ScheduledForRemoval(inVersion="5.0.0") @Deprecated default void sendMessage(@NotNull @NotNull ComponentLike message, @NotNull @NotNull MessageType type) Deprecated.for removal since 4.12.0,MessageTypeis deprecated for removal, usesendMessage(ComponentLike)Sends a system chat message to thisAudienceignoring the providedMessageType.- Parameters:
message- a messagetype- the type- Since:
- 4.1.0
- See Also:
-
sendMessage
@ScheduledForRemoval(inVersion="5.0.0") @Deprecated default void sendMessage(@NotNull @NotNull Component message, @NotNull @NotNull MessageType type) Deprecated.for removal since 4.12.0,MessageTypeis deprecated for removal, usesendMessage(Component)insteadSends a system chat message to thisAudienceignoring the providedMessageType.- Parameters:
message- a messagetype- the type- Since:
- 4.1.0
- See Also:
-
sendMessage
@Deprecated default void sendMessage(@NotNull @NotNull Identified source, @NotNull @NotNull ComponentLike message) Deprecated.since 4.12.0, the client errors on and can reject identified messages withoutSignedMessagedata, this may be unsupported in the future, usesendMessage(SignedMessage, ChatType.Bound)insteadSends an unsigned player chat message from the givenIdentifiedto thisAudiencewith thesystemchat type.- Parameters:
source- the source of the messagemessage- a message- Since:
- 4.0.0
- See Also:
-
sendMessage
@Deprecated default void sendMessage(@NotNull @NotNull Identity source, @NotNull @NotNull ComponentLike message) Deprecated.since 4.12.0, the client errors on and can reject identified messages withoutSignedMessagedata, this may be unsupported in the future, usesendMessage(SignedMessage, ChatType.Bound)insteadSends an unsigned player chat message from the entity represented by the givenIdentityto thisAudiencewith thesystemchat type.- Parameters:
source- the identity of the source of the messagemessage- a message- Since:
- 4.0.0
- See Also:
-
sendMessage
@Deprecated default void sendMessage(@NotNull @NotNull Identified source, @NotNull @NotNull Component message) Deprecated.since 4.12.0, the client errors on receiving and can reject identified messages withoutSignedMessagedata, this may be unsupported in the future, usesendMessage(SignedMessage, ChatType.Bound)insteadSends an unsigned player chat message from the givenIdentifiedto thisAudiencewith thesystemchat type.- Parameters:
source- the source of the messagemessage- a message- Since:
- 4.0.0
- See Also:
-
sendMessage
@Deprecated default void sendMessage(@NotNull @NotNull Identity source, @NotNull @NotNull Component message) Deprecated.since 4.12.0, the client errors on receiving and can reject identified messages withoutSignedMessagedata, this may be unsupported in the future, usesendMessage(SignedMessage, ChatType.Bound)insteadSends an unsigned player chat message from the entity represented by the givenIdentityto thisAudiencewith thesystemchat type.- Parameters:
source- the identity of the source of the messagemessage- a message- Since:
- 4.0.0
- See Also:
-
sendMessage
@ScheduledForRemoval(inVersion="5.0.0") @Deprecated default void sendMessage(@NotNull @NotNull Identified source, @NotNull @NotNull ComponentLike message, @NotNull @NotNull MessageType type) Deprecated.for removal since 4.12.0,MessageTypeis deprecated for removal and the client errors on receiving and can reject identified messages withoutSignedMessagedata, usesendMessage(SignedMessage, ChatType.Bound)insteadSends an unsigned player chat message from the givenIdentifiedto thisAudiencewith theChatTypecorresponding to the providedMessageType.- Parameters:
source- the source of the messagemessage- a messagetype- the type- Since:
- 4.0.0
- See Also:
-
sendMessage
@ScheduledForRemoval(inVersion="5.0.0") @Deprecated default void sendMessage(@NotNull @NotNull Identity source, @NotNull @NotNull ComponentLike message, @NotNull @NotNull MessageType type) Deprecated.for removal since 4.12.0,MessageTypeis deprecated for removal and the client errors on receiving and can reject identified messages withoutSignedMessagedata, usesendMessage(SignedMessage, ChatType.Bound)insteadSends an unsigned player chat message from the entity represented by the givenIdentityto thisAudience.- Parameters:
source- the identity of the source of the messagemessage- a messagetype- the type- Since:
- 4.0.0
- See Also:
-
sendMessage
@ScheduledForRemoval(inVersion="5.0.0") @Deprecated default void sendMessage(@NotNull @NotNull Identified source, @NotNull @NotNull Component message, @NotNull @NotNull MessageType type) Deprecated.for removal since 4.12.0,MessageTypeis deprecated for removal and the client errors on receiving and can reject identified messages withoutSignedMessagedata, usesendMessage(SignedMessage, ChatType.Bound)insteadSends an unsigned player chat message from the givenIdentifiedto thisAudiencewith theChatTypecorresponding to the providedMessageType.- Parameters:
source- the source of the messagemessage- a messagetype- the type- Since:
- 4.0.0
- See Also:
-
sendMessage
@ScheduledForRemoval(inVersion="5.0.0") @Deprecated default void sendMessage(@NotNull @NotNull Identity source, @NotNull @NotNull Component message, @NotNull @NotNull MessageType type) Deprecated.for removal since 4.12.0,MessageTypeis deprecated for removal and the client errors on receiving and can reject identified messages withoutSignedMessagedata, usesendMessage(SignedMessage, ChatType.Bound)insteadSends a player chat message from the entity represented by the givenIdentityto thisAudiencewith theChatTypecorresponding to the providedMessageType.- Parameters:
source- the identity of the source of the messagemessage- a messagetype- the type- Since:
- 4.0.0
- See Also:
-
sendMessage
default void sendMessage(@NotNull @NotNull Component message, @NotNull ChatType.Bound boundChatType) Sends a message to thisAudiencewith the providedbound chat type.- Parameters:
message- the component contentboundChatType- the bound chat type- Since:
- 4.12.0
- Since Minecraft:
- 1.19
-
sendMessage
default void sendMessage(@NotNull @NotNull ComponentLike message, @NotNull ChatType.Bound boundChatType) Sends a message to thisAudiencewith the providedbound chat type.- Parameters:
message- the component contentboundChatType- the bound chat type- Since:
- 4.12.0
- Since Minecraft:
- 1.19
-
sendMessage
default void sendMessage(@NotNull @NotNull SignedMessage signedMessage, @NotNull ChatType.Bound boundChatType) Sends a signed player message to thisAudiencewith the providedbound chat type.- Parameters:
signedMessage- the signed message databoundChatType- the bound chat type- Since:
- 4.12.0
- Since Minecraft:
- 1.19
-
deleteMessage
Requests deletion of a message with the providedSignedMessage's signature.- Parameters:
signedMessage- the message to delete- Since:
- 4.12.0
- See Also:
- Since Minecraft:
- 1.19
-
deleteMessage
Requests deletion of a message with the providedSignedMessage.Signature.- Parameters:
signature- the signature- Since:
- 4.12.0
- Since Minecraft:
- 1.19
-
sendActionBar
Sends a message on the action bar.- Parameters:
message- a message- Since:
- 4.0.0
- See Also:
-
sendActionBar
Sends a message on the action bar.- Parameters:
message- a message- Since:
- 4.0.0
- See Also:
-
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:
-
sendTitlePart
Shows a part of a title.- Type Parameters:
T- the type of the value of the part- Parameters:
part- the partvalue- the value- Throws:
IllegalArgumentException- if a title part that is not inTitlePartis used- Since:
- 4.9.0
-
clearTitle
default void clearTitle()Clears the title, if one is being displayed.- Since:
- 4.0.0
- See Also:
-
resetTitle
default void resetTitle()Resets the title and timings back to their default.- Since:
- 4.0.0
- See Also:
-
showBossBar
Shows a boss bar.- Parameters:
bar- a boss bar- Since:
- 4.0.0
- See Also:
-
hideBossBar
Hides a boss bar.- Parameters:
bar- a boss bar- Since:
- 4.0.0
- See Also:
-
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:
-
playSound
Plays a sound at a location.- Parameters:
sound- a soundx- x coordinatey- y coordinatez- z coordinate- Since:
- 4.0.0
- See Also:
-
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().- Parameters:
sound- a soundemitter- an emitter- Since:
- 4.8.0
-
stopSound
Stops a sound.- Parameters:
sound- the sound- Since:
- 4.8.0
-
stopSound
Stops a sound, or many sounds.- Parameters:
stop- a sound stop- Since:
- 4.0.0
- See Also:
-
openBook
Opens a book.When possible, no item should persist after closing the book.
- Parameters:
book- a book- Since:
- 4.0.0
- See Also:
-
openBook
Opens a book.When possible, no item should persist after closing the book.
- Parameters:
book- a book- Since:
- 4.0.0
- See Also:
-
sendResourcePacks
default void sendResourcePacks(@NotNull @NotNull ResourcePackInfoLike first, @NotNull @NotNull ResourcePackInfoLike... others) Sends a request to apply resource packs to this audience.Multiple resource packs are only supported since 1.20.3. On older versions, all requests behave as if
ResourcePackRequest.replace()is set totrue.- Parameters:
first- the resource pack infoothers- the other pack infos- Since:
- 4.15.0
- See Also:
-
sendResourcePacks
Sends a request to apply resource packs to this audience.Multiple resource packs are only supported since 1.20.3. On older versions, all requests behave as if
ResourcePackRequest.replace()is set totrue.- Parameters:
request- the resource pack request- Since:
- 4.15.0
- See Also:
-
sendResourcePacks
Sends a request to apply resource packs to this audience.Multiple resource packs are only supported since 1.20.3. On older versions, all requests behave as if
ResourcePackRequest.replace()is set totrue.- Parameters:
request- the resource pack request- Since:
- 4.15.0
- See Also:
-
removeResourcePacks
Clear resource packs with the IDs used in the provided requests if they are present.- Parameters:
request- the request used to originally apply the packs- Since:
- 4.15.0
- Since Minecraft:
- 1.20.3
-
removeResourcePacks
Clear resource packs with the IDs used in the provided requests if they are present.- Parameters:
request- the request used to originally apply the packs- Since:
- 4.15.0
- Since Minecraft:
- 1.20.3
-
removeResourcePacks
default void removeResourcePacks(@NotNull @NotNull ResourcePackInfoLike request, @NotNull @NotNull ResourcePackInfoLike @NotNull ... others) Clear resource packs with the IDs used in the provided requests if they are present.- Parameters:
request- the first request used to originally apply the packothers- requests for other packs that should be removed- Since:
- 4.15.0
- Since Minecraft:
- 1.20.3
-
removeResourcePacks
Clear resource packs with the provided ids if they are present.- Parameters:
ids- the ids of resource packs to remove- Since:
- 4.16.0
- Since Minecraft:
- 1.20.3
-
removeResourcePacks
default void removeResourcePacks(@NotNull @NotNull UUID id, @NotNull @NotNull UUID @NotNull ... others) Clear resource packs with the provided ids if they are present.- Parameters:
id- the idothers- the ids of any additional resource packs- Since:
- 4.15.0
- Since Minecraft:
- 1.20.3
-
clearResourcePacks
default void clearResourcePacks()Clear all server-provided resource packs that have been sent to this user.- Since:
- 4.15.0
-
showDialog
Shows a dialog to this audience.This method exists to allow initial native support for dialogs until Adventure has full API to support building and sending dialogs.
- Parameters:
dialog- the dialog- Since:
- 4.22.0
- Since Minecraft:
- 1.21.6
-
SignedMessagedata, this may be unsupported in the future, usesendMessage(SignedMessage, ChatType.Bound)instead