Apollo
Stopwatch

Stopwatch Module

Overview

The stopwatch module allows you to add custom Stopwatch and Timers directly to player's screens in any HUD position you want.

  • Ability to create unique Stopwatch counters for a player.
    • Control when it starts, stops, and when it resets.
    • Customize the name, display color, and display format.
    • Display the stopwatch anywhere on the player's screen.
  • Ability to create and control unique Timers for a player.
    • Control when the timer starts, stops, and when it resets.
    • Customize the duration, name, looping, display format, and display color of the timer.
    • Display the timer HUD in the position you'd like on the player's screen.

Stopwatch Module Example

Start, Stop, and Reset the Lunar Client stopwatch mod!

Integration

Sample Code

Explore each integration by cycling through each tab, to find the best fit for your requirements and needs.

Apollo API examples. See General for common patterns and helpers.

Adding a Stopwatch

public void addStopwatchExample(Player viewer) {
    Optional<ApolloPlayer> apolloPlayerOpt = Apollo.getPlayerManager().getPlayer(viewer.getUniqueId());
 
    apolloPlayerOpt.ifPresent(apolloPlayer -> {
        this.stopwatchModule.addStopwatch(apolloPlayer, Stopwatch.builder()
            .id("parkour-stopwatch")
            .name("Parkour")
            .resetOnStart(true)
            .preventModification(true)
            .hideWhenStopped(false)
            .displayFormat("mm:ss")
            .textColor(ApolloColors.DARK_AQUA)
            .hudPosition(HudPosition.builder()
                .x(-30)
                .y(30)
                .build()
            )
            .build());
    });
}

Removing a Stopwatch

public void removeStopwatchExample(Player viewer) {
    Optional<ApolloPlayer> apolloPlayerOpt = Apollo.getPlayerManager().getPlayer(viewer.getUniqueId());
    apolloPlayerOpt.ifPresent(apolloPlayer -> this.stopwatchModule.removeStopwatch(apolloPlayer, "parkour-stopwatch"));
}

Starting a Stopwatch

public void startStopwatchExample(Player viewer) {
    Optional<ApolloPlayer> apolloPlayerOpt = Apollo.getPlayerManager().getPlayer(viewer.getUniqueId());
    apolloPlayerOpt.ifPresent(apolloPlayer -> this.stopwatchModule.startStopwatch(apolloPlayer, "parkour-stopwatch"));
}

Stopping a Stopwatch

public void stopStopwatchExample(Player viewer) {
    Optional<ApolloPlayer> apolloPlayerOpt = Apollo.getPlayerManager().getPlayer(viewer.getUniqueId());
    apolloPlayerOpt.ifPresent(apolloPlayer -> this.stopwatchModule.stopStopwatch(apolloPlayer, "parkour-stopwatch"));
}

Resetting a Stopwatch

public void resetStopwatchExample(Player viewer) {
    Optional<ApolloPlayer> apolloPlayerOpt = Apollo.getPlayerManager().getPlayer(viewer.getUniqueId());
    apolloPlayerOpt.ifPresent(apolloPlayer -> this.stopwatchModule.resetStopwatch(apolloPlayer, "parkour-stopwatch"));
}

Resetting all Stopwatches

public void resetStopwatchesExample(Player viewer) {
    Optional<ApolloPlayer> apolloPlayerOpt = Apollo.getPlayerManager().getPlayer(viewer.getUniqueId());
    apolloPlayerOpt.ifPresent(this.stopwatchModule::resetStopwatches);
}

Adding a Timer

public void addTimerExample(Player viewer) {
    Optional<ApolloPlayer> apolloPlayerOpt = Apollo.getPlayerManager().getPlayer(viewer.getUniqueId());
 
    apolloPlayerOpt.ifPresent(apolloPlayer -> {
        this.stopwatchModule.addTimer(apolloPlayer, Timer.builder()
            .id("game-timer")
            .name("Countdown")
            .duration(Duration.ofSeconds(45))
            .loop(false)
            .preventModification(true)
            .hideWhenStopped(false)
            .displayFormat("mm:ss")
            .titleText(Component.text("Time's up!", NamedTextColor.RED))
            .inGameNotification(true)
            .textColor(ApolloColors.LIGHT_PURPLE)
            .hudPosition(HudPosition.builder()
                .x(-10)
                .y(30)
                .build()
            )
            .build());
    });
}

Removing a Timer

public void removeTimerExample(Player viewer) {
    Optional<ApolloPlayer> apolloPlayerOpt = Apollo.getPlayerManager().getPlayer(viewer.getUniqueId());
    apolloPlayerOpt.ifPresent(apolloPlayer -> this.stopwatchModule.removeTimer(apolloPlayer, "game-timer"));
}

Starting a Timer

public void startTimerExample(Player viewer) {
    Optional<ApolloPlayer> apolloPlayerOpt = Apollo.getPlayerManager().getPlayer(viewer.getUniqueId());
    apolloPlayerOpt.ifPresent(apolloPlayer -> this.stopwatchModule.startTimer(apolloPlayer, "game-timer"));
}

Stopping a Timer

public void stopTimerExample(Player viewer) {
    Optional<ApolloPlayer> apolloPlayerOpt = Apollo.getPlayerManager().getPlayer(viewer.getUniqueId());
    apolloPlayerOpt.ifPresent(apolloPlayer -> this.stopwatchModule.stopTimer(apolloPlayer, "game-timer"));
}

Resetting a Timer

public void resetTimerExample(Player viewer) {
    Optional<ApolloPlayer> apolloPlayerOpt = Apollo.getPlayerManager().getPlayer(viewer.getUniqueId());
    apolloPlayerOpt.ifPresent(apolloPlayer -> this.stopwatchModule.resetTimer(apolloPlayer, "game-timer"));
}

Resetting all Timers

public void resetTimersExample(Player viewer) {
    Optional<ApolloPlayer> apolloPlayerOpt = Apollo.getPlayerManager().getPlayer(viewer.getUniqueId());
    apolloPlayerOpt.ifPresent(this.stopwatchModule::resetTimers);
}

Stopwatch Options

.id(String) is the unique server-assigned id for the stopwatch.

.id("parkour-stopwatch")

.name(String) is the HUD display name.

.name("Parkour")

.resetOnStart(boolean) determines whether to reset elapsed time on each start.

.resetOnStart(true)

.preventModification(boolean) prevents the user from modifying the options for this stopwatch on the client side.

.preventModification(true)

.hideWhenStopped(boolean) determines whether the stopwatch is hidden from the HUD when stopped.

.hideWhenStopped(false)

.displayFormat(String) is a format string (e.g. "mm:ss"). Uses the default display format if not provided.

.displayFormat("mm:ss")

.textColor(java.awt.Color) is the text color. Defaults to white if not provided. See the colors page for more.

.textColor(ApolloColors.DARK_AQUA)

.hudPosition(HudPosition) is the HUD position on the client screen. If not provided, the stopwatch is auto-stacked.

.hudPosition(HudPosition.builder().x(-30).y(30).build())

Timer Options

.id(String) is the unique server-assigned id for the timer.

.id("game-timer")

.name(String) is the HUD display name.

.name("Countdown")

.duration(java.time.Duration) is the countdown duration.

.duration(Duration.ofSeconds(45))

.loop(boolean) determines whether the timer restarts automatically when finished.

.loop(false)

.preventModification(boolean) prevents the user from modifying the options for this timer on the client side.

.preventModification(true)

.hideWhenStopped(boolean) determines whether the timer is hidden from the HUD when stopped.

.hideWhenStopped(false)

.displayFormat(String) is a format string. Uses the default display format if not provided.

.displayFormat("mm:ss")

.titleText(Component) is the on-screen title shown when the timer finishes. Set to null or omit to skip. See the chat components (opens in a new tab) page for more.

.titleText(Component.text("Time's up!", NamedTextColor.RED))

.inGameNotification(boolean) determines whether to show an in-game popup when the timer finishes.

.inGameNotification(true)

.textColor(java.awt.Color) is the text color. Defaults to white if not provided. See the colors page for more.

.textColor(ApolloColors.LIGHT_PURPLE)

.hudPosition(HudPosition) is the HUD position on the client screen. If not provided, the timer is auto-stacked.

.hudPosition(HudPosition.builder().x(-10).y(30).build())