LunarClient / Apollo

Next-generation Lunar Client server API
https://lunarclient.dev
MIT License
92 stars 18 forks source link

Feature - Rich Presence Module #141

Closed ItsNature closed 7 months ago

ItsNature commented 8 months ago

Overview

Description: The Rich Presence Module allows you to interact with Discord and Lunar Client's launcher rich presence.

Further documentation can temporarily be found here.

Changes: Added ServerRichPresence class builder

Added RichPresenceModule#overrideServerRichPresence(Recipients, ServerRichPresence) API method Added RichPresenceModule#resetServerRichPresence(Recipients) API method

Added OverrideServerRichPresenceMessage protobuf message Added ResetServerRichPresenceMessage protobuf message

Code Example:

Override the server rich presence for a player

public void overrideServerRichPresenceExample(Player viewer) {
    Optional<ApolloPlayer> apolloPlayerOpt = Apollo.getPlayerManager().getPlayer(viewer.getUniqueId());

    apolloPlayerOpt.ifPresent(apolloPlayer -> {
        this.richPresenceModule.overrideServerRichPresence(apolloPlayer, ServerRichPresence.builder()
            .gameName("BedWars")
            .gameVariantName("Solo")
            .gameState("In Game")
            .playerState("Playing")
            .mapName("Winter")
            .subServerName("BW02")
            .teamCurrentSize(3)
            .teamMaxSize(4)
            .build()
        );
    });
}

Resetting the server rich presence for a player

public void resetServerRichPresenceExample(Player viewer) {
    Optional<ApolloPlayer> apolloPlayerOpt = Apollo.getPlayerManager().getPlayer(viewer.getUniqueId());
    apolloPlayerOpt.ifPresent(this.richPresenceModule::resetServerRichPresence);
}

Review Request Checklist