Interface Audience

All Known Subinterfaces:
ForwardingAudience, ForwardingAudience.Single

public interface Audience
A receiver of Minecraft media.

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:
ForwardingAudience