Skip to content

Commit f53ffa5

Browse files
authored
StaffMod Module Improvements - Add enabledByDefault (#296)
* Add `StaffModModule#enableStaffMods(recipients, mods, enabledByDefault)` & `StaffModModule#enableAllStaffMods(recipients, enabledByDefault)` * Apply changes from optimizations PR
1 parent f525c0c commit f53ffa5

8 files changed

Lines changed: 47 additions & 6 deletions

File tree

api/src/main/java/com/lunarclient/apollo/module/staffmod/StaffModModule.java

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,16 @@ public abstract class StaffModModule extends ApolloModule {
4747
*/
4848
public abstract void enableStaffMods(Recipients recipients, List<StaffMod> mods);
4949

50+
/**
51+
* Enables the {@link StaffMod}s for the {@link Recipients}.
52+
*
53+
* @param recipients the recipients that are receiving the packet
54+
* @param mods the staff mods
55+
* @param enabledByDefault whether the staff mods should be enabled by default on the client
56+
* @since 1.2.8
57+
*/
58+
public abstract void enableStaffMods(Recipients recipients, List<StaffMod> mods, boolean enabledByDefault);
59+
5060
/**
5161
* Disables the {@link StaffMod}s from the {@link Recipients}.
5262
*
@@ -64,6 +74,15 @@ public abstract class StaffModModule extends ApolloModule {
6474
*/
6575
public abstract void enableAllStaffMods(Recipients recipients);
6676

77+
/**
78+
* Enables all {@link StaffMod}s for the {@link Recipients}.
79+
*
80+
* @param recipients the recipients that are receiving the packet
81+
* @param enabledByDefault whether the staff mods should be enabled by default on the client
82+
* @since 1.2.8
83+
*/
84+
public abstract void enableAllStaffMods(Recipients recipients, boolean enabledByDefault);
85+
6786
/**
6887
* Disables all {@link StaffMod}s from the {@link Recipients}.
6988
*

common/src/main/java/com/lunarclient/apollo/module/staffmod/StaffModModuleImpl.java

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,12 +54,18 @@ public final class StaffModModuleImpl extends StaffModModule {
5454

5555
@Override
5656
public void enableStaffMods(@NonNull Recipients recipients, @NonNull List<StaffMod> mods) {
57+
this.enableStaffMods(recipients, mods, false);
58+
}
59+
60+
@Override
61+
public void enableStaffMods(@NonNull Recipients recipients, @NonNull List<StaffMod> mods, boolean enabledByDefault) {
5762
Set<com.lunarclient.apollo.staffmod.v1.StaffMod> staffModsProto = mods.stream()
5863
.map(this::toProtobuf)
5964
.collect(Collectors.toSet());
6065

6166
EnableStaffModsMessage message = EnableStaffModsMessage.newBuilder()
6267
.addAllStaffMods(staffModsProto)
68+
.setEnabledByDefault(enabledByDefault)
6369
.build();
6470

6571
ApolloManager.getNetworkManager().sendPacket(recipients, message);
@@ -83,6 +89,16 @@ public void enableAllStaffMods(@NonNull Recipients recipients) {
8389
ApolloManager.getNetworkManager().sendPacket(recipients, this.enableAllStaffModsMessage);
8490
}
8591

92+
@Override
93+
public void enableAllStaffMods(@NonNull Recipients recipients, boolean enabledByDefault) {
94+
EnableStaffModsMessage message = EnableStaffModsMessage.newBuilder()
95+
.addAllStaffMods(this.staffMods)
96+
.setEnabledByDefault(enabledByDefault)
97+
.build();
98+
99+
ApolloManager.getNetworkManager().sendPacket(recipients, message);
100+
}
101+
86102
@Override
87103
public void disableAllStaffMods(@NonNull Recipients recipients) {
88104
ApolloManager.getNetworkManager().sendPacket(recipients, this.disableAllStaffModsMessage);

docs/developers/lightweight/protobuf.mdx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ Available fields for each message, including their types, are available on the B
2626
<dependency>
2727
<groupId>com.lunarclient</groupId>
2828
<artifactId>apollo-protos</artifactId>
29-
<version>0.1.8</version>
29+
<version>0.2.0</version>
3030
</dependency>
3131
</dependencies>
3232
```
@@ -41,7 +41,7 @@ Available fields for each message, including their types, are available on the B
4141
}
4242
4343
dependencies {
44-
api 'com.lunarclient:apollo-protos:0.1.8'
44+
api 'com.lunarclient:apollo-protos:0.2.0'
4545
}
4646
```
4747
</Tab>
@@ -55,7 +55,7 @@ Available fields for each message, including their types, are available on the B
5555
}
5656

5757
dependencies {
58-
api("com.lunarclient:apollo-protos:0.1.8")
58+
api("com.lunarclient:apollo-protos:0.2.0")
5959
}
6060
```
6161
</Tab>

docs/developers/modules/staffmod.mdx

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ public void enableStaffModsExample(Player viewer) {
3737
}
3838

3939
Optional<ApolloPlayer> apolloPlayerOpt = Apollo.getPlayerManager().getPlayer(viewer.getUniqueId());
40-
apolloPlayerOpt.ifPresent(apolloPlayer -> this.staffModModule.enableStaffMods(apolloPlayer, Collections.singletonList(StaffMod.XRAY)));
40+
apolloPlayerOpt.ifPresent(apolloPlayer -> this.staffModModule.enableStaffMods(apolloPlayer, Collections.singletonList(StaffMod.XRAY), true));
4141
}
4242
```
4343

@@ -56,6 +56,8 @@ public void disableStaffModsExample(Player viewer) {
5656
- A list of all the player(s) you want to enable or disable the staff mod.
5757
2. `StaffMod.TYPE`
5858
- The type of staff mod(s) you want to enable for the `Recipients` player. See the [staff mod types](#staffmod-types) section for more.
59+
3. `boolean enabledByDefault`
60+
- Only available on `enableStaffMods`. When `true`, the staff mod is automatically enabled on the player's client; when `false`, it is unlocked but left disabled for the player to toggle on themselves.
5961

6062
## `StaffMod` Types
6163

@@ -79,6 +81,7 @@ public void enableStaffModsExample(Player viewer) {
7981

8082
EnableStaffModsMessage message = EnableStaffModsMessage.newBuilder()
8183
.addAllStaffMods(Collections.singletonList(StaffMod.STAFF_MOD_XRAY))
84+
.setEnabledByDefault(true)
8285
.build();
8386

8487
ProtobufPacketUtil.sendPacket(viewer, message);
@@ -121,6 +124,7 @@ public void enableStaffModsExample(Player viewer) {
121124
JsonObject message = new JsonObject();
122125
message.addProperty("@type", "type.googleapis.com/lunarclient.apollo.staffmod.v1.EnableStaffModsMessage");
123126
message.add("staff_mods", staffMods);
127+
message.addProperty("enabled_by_default", true);
124128

125129
JsonPacketUtil.sendPacket(viewer, message);
126130
}

example/bukkit/api/src/main/java/com/lunarclient/apollo/example/api/module/StaffModApiExample.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ public void enableStaffModsExample(Player viewer) {
4343
}
4444

4545
Optional<ApolloPlayer> apolloPlayerOpt = Apollo.getPlayerManager().getPlayer(viewer.getUniqueId());
46-
apolloPlayerOpt.ifPresent(apolloPlayer -> this.staffModModule.enableStaffMods(apolloPlayer, Collections.singletonList(StaffMod.XRAY)));
46+
apolloPlayerOpt.ifPresent(apolloPlayer -> this.staffModModule.enableStaffMods(apolloPlayer, Collections.singletonList(StaffMod.XRAY), true));
4747
}
4848

4949
@Override

example/bukkit/json/src/main/java/com/lunarclient/apollo/example/json/module/StaffModJsonExample.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ public void enableStaffModsExample(Player viewer) {
4747
JsonObject message = new JsonObject();
4848
message.addProperty("@type", "type.googleapis.com/lunarclient.apollo.staffmod.v1.EnableStaffModsMessage");
4949
message.add("staff_mods", staffMods);
50+
message.addProperty("enabled_by_default", true);
5051

5152
JsonPacketUtil.sendPacket(viewer, message);
5253
}

example/bukkit/proto/src/main/java/com/lunarclient/apollo/example/proto/module/StaffModProtoExample.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ public void enableStaffModsExample(Player viewer) {
4141

4242
EnableStaffModsMessage message = EnableStaffModsMessage.newBuilder()
4343
.addAllStaffMods(Collections.singletonList(StaffMod.STAFF_MOD_XRAY))
44+
.setEnabledByDefault(true)
4445
.build();
4546

4647
ProtobufPacketUtil.sendPacket(viewer, message);

gradle/libs.versions.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ geantyref = "1.3.11"
1111
idea = "1.1.7"
1212
jetbrains = "24.0.1"
1313
lombok = "1.18.38"
14-
protobuf = "0.1.8"
14+
protobuf = "0.2.0"
1515
gson = "2.10.1"
1616
shadow = "9.4.1"
1717
spotless = "8.4.0"

0 commit comments

Comments
 (0)