Apollo
Developers
Modules
Notification

Notification Module

Overview

The notification module allows you to send Lunar Client notifications to players actively on your server. Lunar Client notifications appear in the upper right of the user's screen.

  • Send custom notifications to Lunar Client players.
    • Custom notification color can be provided.
    • Custom icons can be provided.

Notification Module Example

Send notifications using Lunar Client, with any icon, title, and description!

Integration

Notification Builder

private final Notification uhcAnnouncement = Notification.builder()
    .titleComponent(Component.text("UHC Announcement", NamedTextColor.GREEN))
    .descriptionComponent(Component.text("UHC starts in 5 minutes...", NamedTextColor.RED)
        .appendNewline()
        .append(Component.text("Get ready!", NamedTextColor.WHITE))
        .appendNewline()
        .append(Component.text("Good luck!", NamedTextColor.GOLD))
    )
    .resourceLocation("icons/golden_apple.png") // This field is optional
    .displayTime(Duration.ofSeconds(5))
    .build();

Notification Options

⚠️

There are character limits for the titleComponent option.

.titleComponent(Component) is the title of the notification box. Char limit: 15. See the chat components (opens in a new tab) page for more.

.titleComponent(Component.text("UHC Announcement", NamedTextColor.GREEN))

.descriptionComponent(Component) is the description displayed inside the notification box. See the chat components (opens in a new tab) page for more.

.descriptionComponent(Component.text("UHC starts in 5 minutes...", NamedTextColor.RED))

.resourceLocation(String) is the resource location of the shown icon.

.resourceLocation("icons/golden_apple.png")

.displayTime(java.time.Duration) is the duration you want to keep the notification on screen. See the java.time.Duration Javadocs (opens in a new tab) for more.

.displayTime(Duration.ofSeconds(5))

If this field is left empty (null) it'll display a generic info icon, as displayed here.

⚠️

The fields title and description are deprecated since 1.0.6, use 'titleComponent' and 'descriptionComponent' instead.

.title(String) is the title of the notification box. Char limit: 15

.title("UHC Announcement")

.description(String) is the description displayed inside the notification box.

.description("UHC starts in 5 minutes...")

Displaying a Notification for a specific player

public void displayNotificationExample(Player viewer) {
    Optional<ApolloPlayer> apolloPlayerOpt = Apollo.getPlayerManager().getPlayer(viewer.getUniqueId());
    apolloPlayerOpt.ifPresent(apolloPlayer -> this.notificationModule.displayNotification(apolloPlayer, this.uhcAnnouncement));
}

Resetting all notifications for a player

public void resetNotificationsExample(Player viewer) {
    Optional<ApolloPlayer> apolloPlayerOpt = Apollo.getPlayerManager().getPlayer(viewer.getUniqueId());
    apolloPlayerOpt.ifPresent(this.notificationModule::resetNotifications);
}