Skip to content

Commit 89a0732

Browse files
Feature - Rich Presence Module (#141)
* Implement Rich Status module * Implement rich status resetting * Make most rich status fields nullable * Rename to rich presence * Add overview desc to rich presence module --------- Co-authored-by: TrentinTheKid <[email protected]>
1 parent b9ec74c commit 89a0732

File tree

10 files changed

+487
-0
lines changed

10 files changed

+487
-0
lines changed
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
/*
2+
* This file is part of Apollo, licensed under the MIT License.
3+
*
4+
* Copyright (c) 2023 Moonsworth
5+
*
6+
* Permission is hereby granted, free of charge, to any person obtaining a copy
7+
* of this software and associated documentation files (the "Software"), to deal
8+
* in the Software without restriction, including without limitation the rights
9+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10+
* copies of the Software, and to permit persons to whom the Software is
11+
* furnished to do so, subject to the following conditions:
12+
*
13+
* The above copyright notice and this permission notice shall be included in all
14+
* copies or substantial portions of the Software.
15+
*
16+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22+
* SOFTWARE.
23+
*/
24+
package com.lunarclient.apollo.module.richpresence;
25+
26+
import com.lunarclient.apollo.module.ApolloModule;
27+
import com.lunarclient.apollo.module.ModuleDefinition;
28+
import com.lunarclient.apollo.recipients.Recipients;
29+
import org.jetbrains.annotations.ApiStatus;
30+
31+
/**
32+
* Represents the rich presence module.
33+
*
34+
* @since 1.1.2
35+
*/
36+
@ApiStatus.NonExtendable
37+
@ModuleDefinition(id = "rich_presence", name = "RichPresence")
38+
public abstract class RichPresenceModule extends ApolloModule {
39+
40+
/**
41+
* Overrides the {@link ServerRichPresence} for the {@link Recipients}.
42+
*
43+
* @param recipients the recipients that are receiving the packet
44+
* @param richPresence the rich presence
45+
* @since 1.1.2
46+
*/
47+
public abstract void overrideServerRichPresence(Recipients recipients, ServerRichPresence richPresence);
48+
49+
/**
50+
* Resets the {@link ServerRichPresence} for the given {@link Recipients}.
51+
*
52+
* @param recipients the recipients that are receiving the packet
53+
* @since 1.1.2
54+
*/
55+
public abstract void resetServerRichPresence(Recipients recipients);
56+
57+
}
Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
/*
2+
* This file is part of Apollo, licensed under the MIT License.
3+
*
4+
* Copyright (c) 2023 Moonsworth
5+
*
6+
* Permission is hereby granted, free of charge, to any person obtaining a copy
7+
* of this software and associated documentation files (the "Software"), to deal
8+
* in the Software without restriction, including without limitation the rights
9+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10+
* copies of the Software, and to permit persons to whom the Software is
11+
* furnished to do so, subject to the following conditions:
12+
*
13+
* The above copyright notice and this permission notice shall be included in all
14+
* copies or substantial portions of the Software.
15+
*
16+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22+
* SOFTWARE.
23+
*/
24+
package com.lunarclient.apollo.module.richpresence;
25+
26+
import lombok.Builder;
27+
import lombok.Getter;
28+
import org.jetbrains.annotations.Nullable;
29+
30+
/**
31+
* Represents a server rich presence for the rich presence module.
32+
*
33+
* @since 1.1.2
34+
*/
35+
@Getter
36+
@Builder
37+
public class ServerRichPresence {
38+
39+
/**
40+
* Returns the {@link String} name of the game the player is playing on (e.g. 'BedWars').
41+
*
42+
* @return the game name
43+
* @since 1.1.2
44+
*/
45+
@Nullable String gameName;
46+
47+
/**
48+
* Returns the {@link String} variant of the game the player is playing on (e.g. 'Solo').
49+
*
50+
* @return the game variant name
51+
* @since 1.1.2
52+
*/
53+
@Nullable String gameVariantName;
54+
55+
/**
56+
* Returns the {@link String} state of the current game (e.g. 'In Game').
57+
*
58+
* @return the game state
59+
* @since 1.1.2
60+
*/
61+
@Nullable String gameState;
62+
63+
/**
64+
* Returns {@link String} what the player is currently doing in the game (e.g. 'Spectating', 'Playing', 'Crafting').
65+
*
66+
* @return the player state
67+
* @since 1.1.2
68+
*/
69+
@Nullable String playerState;
70+
71+
/**
72+
* Returns the {@link String} name of the map the player is playing on (e.g. 'Winter').
73+
*
74+
* @return the map name
75+
* @since 1.1.2
76+
*/
77+
@Nullable String mapName;
78+
79+
/**
80+
* Returns the {@link String} sub server name of the server the player is playing on (e.g. 'BW02').
81+
*
82+
* @return the sub server
83+
* @since 1.1.2
84+
*/
85+
@Nullable String subServerName;
86+
87+
/**
88+
* Returns the {@link Integer} current size of the player's team.
89+
*
90+
* @return the current team size
91+
* @since 1.1.2
92+
*/
93+
int teamCurrentSize;
94+
95+
/**
96+
* Returns the {@link Integer} max size of the player's team.
97+
*
98+
* @return the max team size
99+
* @since 1.1.2
100+
*/
101+
int teamMaxSize;
102+
103+
}

bukkit-example/src/main/java/com/lunarclient/apollo/example/ApolloExamplePlugin.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838
import com.lunarclient.apollo.example.commands.NametagCommand;
3939
import com.lunarclient.apollo.example.commands.NickHiderCommand;
4040
import com.lunarclient.apollo.example.commands.NotificationCommand;
41+
import com.lunarclient.apollo.example.commands.RichPresenceCommand;
4142
import com.lunarclient.apollo.example.commands.ServerRuleCommand;
4243
import com.lunarclient.apollo.example.commands.StaffModCommand;
4344
import com.lunarclient.apollo.example.commands.StopwatchCommand;
@@ -62,6 +63,7 @@
6263
import com.lunarclient.apollo.example.modules.NametagExample;
6364
import com.lunarclient.apollo.example.modules.NickHiderExample;
6465
import com.lunarclient.apollo.example.modules.NotificationExample;
66+
import com.lunarclient.apollo.example.modules.RichPresenceExample;
6567
import com.lunarclient.apollo.example.modules.ServerRuleExample;
6668
import com.lunarclient.apollo.example.modules.StaffModExample;
6769
import com.lunarclient.apollo.example.modules.StopwatchExample;
@@ -94,6 +96,7 @@ public class ApolloExamplePlugin extends JavaPlugin {
9496
private NametagExample nametagExample;
9597
private NickHiderExample nickHiderExample;
9698
private NotificationExample notificationExample;
99+
private RichPresenceExample richPresenceExample;
97100
private ServerRuleExample serverRuleExample;
98101
private StaffModExample staffModExample;
99102
private StopwatchExample stopwatchExample;
@@ -133,6 +136,7 @@ private void registerModuleExamples() {
133136
this.nametagExample = new NametagExample();
134137
this.nickHiderExample = new NickHiderExample();
135138
this.notificationExample = new NotificationExample();
139+
this.richPresenceExample = new RichPresenceExample();
136140
this.serverRuleExample = new ServerRuleExample();
137141
this.staffModExample = new StaffModExample();
138142
this.stopwatchExample = new StopwatchExample();
@@ -159,6 +163,7 @@ private void registerCommands() {
159163
this.getCommand("nametag").setExecutor(new NametagCommand());
160164
this.getCommand("nickhider").setExecutor(new NickHiderCommand());
161165
this.getCommand("notification").setExecutor(new NotificationCommand());
166+
this.getCommand("richpresence").setExecutor(new RichPresenceCommand());
162167
this.getCommand("serverrule").setExecutor(new ServerRuleCommand());
163168
this.getCommand("staffmod").setExecutor(new StaffModCommand());
164169
this.getCommand("stopwatch").setExecutor(new StopwatchCommand());
Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
/*
2+
* This file is part of Apollo, licensed under the MIT License.
3+
*
4+
* Copyright (c) 2023 Moonsworth
5+
*
6+
* Permission is hereby granted, free of charge, to any person obtaining a copy
7+
* of this software and associated documentation files (the "Software"), to deal
8+
* in the Software without restriction, including without limitation the rights
9+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10+
* copies of the Software, and to permit persons to whom the Software is
11+
* furnished to do so, subject to the following conditions:
12+
*
13+
* The above copyright notice and this permission notice shall be included in all
14+
* copies or substantial portions of the Software.
15+
*
16+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22+
* SOFTWARE.
23+
*/
24+
package com.lunarclient.apollo.example.commands;
25+
26+
import com.lunarclient.apollo.example.ApolloExamplePlugin;
27+
import com.lunarclient.apollo.example.modules.RichPresenceExample;
28+
import org.bukkit.command.Command;
29+
import org.bukkit.command.CommandExecutor;
30+
import org.bukkit.command.CommandSender;
31+
import org.bukkit.entity.Player;
32+
import org.jetbrains.annotations.NotNull;
33+
34+
public class RichPresenceCommand implements CommandExecutor {
35+
36+
private final RichPresenceExample richPresenceExample = ApolloExamplePlugin.getPlugin().getRichPresenceExample();
37+
38+
@Override
39+
public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label, @NotNull String[] args) {
40+
if (!(sender instanceof Player)) {
41+
sender.sendMessage("Player only!");
42+
return true;
43+
}
44+
45+
Player player = (Player) sender;
46+
47+
if (args.length != 1) {
48+
player.sendMessage("Usage: /richpresence <override|reset>");
49+
return true;
50+
}
51+
52+
switch (args[0].toLowerCase()) {
53+
case "override": {
54+
this.richPresenceExample.overrideServerRichPresenceExample(player);
55+
player.sendMessage("Overriding rich presence....");
56+
break;
57+
}
58+
59+
case "reset": {
60+
this.richPresenceExample.resetServerRichPresenceExample(player);
61+
player.sendMessage("Resetting rich presence...");
62+
break;
63+
}
64+
65+
default: {
66+
player.sendMessage("Usage: /richpresence <override|reset>");
67+
break;
68+
}
69+
}
70+
71+
return true;
72+
}
73+
}
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
/*
2+
* This file is part of Apollo, licensed under the MIT License.
3+
*
4+
* Copyright (c) 2023 Moonsworth
5+
*
6+
* Permission is hereby granted, free of charge, to any person obtaining a copy
7+
* of this software and associated documentation files (the "Software"), to deal
8+
* in the Software without restriction, including without limitation the rights
9+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10+
* copies of the Software, and to permit persons to whom the Software is
11+
* furnished to do so, subject to the following conditions:
12+
*
13+
* The above copyright notice and this permission notice shall be included in all
14+
* copies or substantial portions of the Software.
15+
*
16+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22+
* SOFTWARE.
23+
*/
24+
package com.lunarclient.apollo.example.modules;
25+
26+
import com.lunarclient.apollo.Apollo;
27+
import com.lunarclient.apollo.module.richpresence.RichPresenceModule;
28+
import com.lunarclient.apollo.module.richpresence.ServerRichPresence;
29+
import com.lunarclient.apollo.player.ApolloPlayer;
30+
import java.util.Optional;
31+
import org.bukkit.entity.Player;
32+
33+
public class RichPresenceExample {
34+
35+
private final RichPresenceModule richPresenceModule = Apollo.getModuleManager().getModule(RichPresenceModule.class);
36+
37+
public void overrideServerRichPresenceExample(Player viewer) {
38+
Optional<ApolloPlayer> apolloPlayerOpt = Apollo.getPlayerManager().getPlayer(viewer.getUniqueId());
39+
40+
apolloPlayerOpt.ifPresent(apolloPlayer -> {
41+
this.richPresenceModule.overrideServerRichPresence(apolloPlayer, ServerRichPresence.builder()
42+
.gameName("BedWars")
43+
.gameVariantName("Solo")
44+
.gameState("In Game")
45+
.playerState("Playing")
46+
.mapName("Winter")
47+
.subServerName("BW02")
48+
.teamCurrentSize(3)
49+
.teamMaxSize(4)
50+
.build()
51+
);
52+
});
53+
}
54+
55+
public void resetServerRichPresenceExample(Player viewer) {
56+
Optional<ApolloPlayer> apolloPlayerOpt = Apollo.getPlayerManager().getPlayer(viewer.getUniqueId());
57+
apolloPlayerOpt.ifPresent(this.richPresenceModule::resetServerRichPresence);
58+
}
59+
60+
}

bukkit-example/src/main/resources/plugin.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,8 @@ commands:
3434
description: "Nick Hider!"
3535
notification:
3636
description: "Notifications!"
37+
richpresence:
38+
description: "Rich Presence!"
3739
serverrule:
3840
description: "Server Rule!"
3941
staffmod:

bukkit/src/main/java/com/lunarclient/apollo/ApolloBukkitPlatform.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,8 @@
5757
import com.lunarclient.apollo.module.notification.NotificationModuleImpl;
5858
import com.lunarclient.apollo.module.packetenrichment.PacketEnrichmentImpl;
5959
import com.lunarclient.apollo.module.packetenrichment.PacketEnrichmentModule;
60+
import com.lunarclient.apollo.module.richpresence.RichPresenceModule;
61+
import com.lunarclient.apollo.module.richpresence.RichPresenceModuleImpl;
6062
import com.lunarclient.apollo.module.serverrule.ServerRuleModule;
6163
import com.lunarclient.apollo.module.staffmod.StaffModModule;
6264
import com.lunarclient.apollo.module.staffmod.StaffModModuleImpl;
@@ -125,6 +127,7 @@ public void onEnable() {
125127
.addModule(NickHiderModule.class, new NickHiderModuleImpl())
126128
.addModule(NotificationModule.class, new NotificationModuleImpl())
127129
.addModule(PacketEnrichmentModule.class, new PacketEnrichmentImpl())
130+
.addModule(RichPresenceModule.class, new RichPresenceModuleImpl())
128131
.addModule(ServerRuleModule.class)
129132
.addModule(StaffModModule.class, new StaffModModuleImpl())
130133
.addModule(StopwatchModule.class, new StopwatchModuleImpl())

0 commit comments

Comments
 (0)