Skip to content

Commit bec99b8

Browse files
committed
Receive mod status from the handshake packet
1 parent fa4f866 commit bec99b8

File tree

6 files changed

+40
-22
lines changed

6 files changed

+40
-22
lines changed

api/src/main/java/com/lunarclient/apollo/event/mods/ApolloUpdateModOptionEvent.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@
3535
* @since 1.2.1
3636
*/
3737
@Value
38-
public final class ApolloUpdateModOptionEvent implements Event {
38+
public class ApolloUpdateModOptionEvent implements Event {
3939

4040
/**
4141
* The {@link ApolloPlayer} that the option was updated for.

common/src/main/java/com/lunarclient/apollo/mods/ApolloModsManager.java

Lines changed: 25 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -168,16 +168,34 @@ private void handleConfiguration(ApolloPlayer player, Any any) {
168168
continue;
169169
}
170170

171-
for (Map.Entry<String, Value> entry : setting.getPropertiesMap().entrySet()) {
172-
Option<?, ?, ?> option = this.playerOptions.getOptionsByKey().get(entry.getKey());
171+
this.updateOptions(player, setting.getPropertiesMap(), false);
172+
}
173+
}
174+
175+
/**
176+
* Updates the {@link Option}s for a specific {@link ApolloPlayer} using the properties
177+
* received from the client.
178+
*
179+
* @param player the apollo player
180+
* @param properties a map of option keys and values
181+
* @param callEvent whether to call the update mod option event
182+
* @since 1.2.1
183+
*/
184+
public void updateOptions(ApolloPlayer player, Map<String, Value> properties, boolean callEvent) {
185+
System.out.println("Update options: " + properties.size());
186+
187+
for (Map.Entry<String, Value> entry : properties.entrySet()) {
188+
Option<?, ?, ?> option = this.playerOptions.getOptionsByKey().get(entry.getKey());
173189

174-
Object unwrappedValue = NetworkOptions.unwrapValue(
175-
entry.getValue(),
176-
option.getTypeToken().getType()
177-
);
190+
Object unwrappedValue = NetworkOptions.unwrapValue(
191+
entry.getValue(),
192+
option.getTypeToken().getType()
193+
);
178194

179-
this.playerOptions.set(player, option, unwrappedValue);
195+
this.playerOptions.set(player, option, unwrappedValue);
196+
System.out.println("Set: " + option.getKey() + "=" + unwrappedValue);
180197

198+
if (callEvent) {
181199
EventBus.EventResult<ApolloUpdateModOptionEvent> eventResult = EventBus.getBus()
182200
.post(new ApolloUpdateModOptionEvent(player, option, unwrappedValue));
183201

common/src/main/java/com/lunarclient/apollo/network/NetworkOptions.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -142,8 +142,11 @@ public static Value wrapValue(Value.Builder valueBuilder, Type type, @Nullable O
142142
String string = (String) current;
143143
return valueBuilder.setStringValue(string).build();
144144
} else if (current instanceof Color) {
145-
Color currentColor = (Color) current;
146-
return valueBuilder.setStringValue(Integer.toHexString(currentColor.getRGB())).build();
145+
Color color = (Color) current;
146+
return valueBuilder.setStringValue(Integer.toHexString(color.getRGB())).build();
147+
} else if (current instanceof Integer) {
148+
int color = (int) current;
149+
return valueBuilder.setStringValue(Integer.toHexString(color)).build();
147150
} else {
148151
throw new RuntimeException("Unable to wrap Color value of type '" + clazz.getSimpleName() + "'!");
149152

common/src/main/java/com/lunarclient/apollo/player/ApolloPlayerManagerImpl.java

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
*/
2424
package com.lunarclient.apollo.player;
2525

26+
import com.google.protobuf.Value;
2627
import com.lunarclient.apollo.Apollo;
2728
import com.lunarclient.apollo.ApolloManager;
2829
import com.lunarclient.apollo.client.mod.LunarClientMod;
@@ -34,11 +35,8 @@
3435
import com.lunarclient.apollo.event.player.ApolloRegisterPlayerEvent;
3536
import com.lunarclient.apollo.event.player.ApolloUnregisterPlayerEvent;
3637
import com.lunarclient.apollo.mods.ModStatusImpl;
37-
import com.lunarclient.apollo.mods.impl.ModFreelook;
38-
import com.lunarclient.apollo.mods.impl.ModWaypoints;
3938
import com.lunarclient.apollo.module.tebex.TebexEmbeddedCheckoutSupport;
4039
import com.lunarclient.apollo.network.NetworkOptions;
41-
import com.lunarclient.apollo.option.Options;
4240
import com.lunarclient.apollo.player.v1.PlayerHandshakeMessage;
4341
import java.util.Collection;
4442
import java.util.Collections;
@@ -162,11 +160,10 @@ public void handlePlayerHandshake(@NotNull ApolloPlayer player, @NotNull PlayerH
162160
apolloPlayer.setInstalledMods(mods);
163161
apolloPlayer.setTebexEmbeddedCheckoutSupport(checkoutSupportType);
164162

165-
// TODO: receive data from client
166-
// mock
167-
Options options = ApolloManager.getModsManager().getPlayerOptions();
168-
options.set(apolloPlayer, ModWaypoints.ENABLED, false);
169-
options.set(apolloPlayer, ModFreelook.INVERT_YAW, true);
163+
Map<String, Value> modStatus = message.getModStatusMap();
164+
if (!modStatus.isEmpty()) {
165+
ApolloManager.getModsManager().updateOptions(apolloPlayer, modStatus, false);
166+
}
170167

171168
apolloPlayer.setModStatus(new ModStatusImpl(player.getUniqueId()));
172169
}

docs/developers/lightweight/protobuf/getting-started.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.0.2</version>
29+
<version>0.0.4</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.0.2'
44+
api 'com.lunarclient:apollo-protos:0.0.4'
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.0.2")
58+
api("com.lunarclient:apollo-protos:0.0.4")
5959
}
6060
```
6161
</Tab>

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.0.2"
14+
protobuf = "0.0.4"
1515
gson = "2.10.1"
1616
shadow = "8.1.1"
1717
spotless = "6.13.0"

0 commit comments

Comments
 (0)