Skip to content

Commit b2bed08

Browse files
committed
Move mod status API into ModSettingsModule
1 parent 48bc7ed commit b2bed08

File tree

13 files changed

+238
-238
lines changed

13 files changed

+238
-238
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
2222
* SOFTWARE.
2323
*/
24-
package com.lunarclient.apollo.event.mods;
24+
package com.lunarclient.apollo.event.modsetting;
2525

2626
import com.lunarclient.apollo.event.Event;
2727
import com.lunarclient.apollo.option.Option;

api/src/main/java/com/lunarclient/apollo/module/modsetting/ModSettingModule.java

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,14 @@
2626
import com.lunarclient.apollo.ApolloPlatform;
2727
import com.lunarclient.apollo.module.ApolloModule;
2828
import com.lunarclient.apollo.module.ModuleDefinition;
29+
import com.lunarclient.apollo.option.Option;
30+
import com.lunarclient.apollo.player.ApolloPlayer;
2931
import com.lunarclient.apollo.util.ConfigTarget;
3032
import java.util.Arrays;
3133
import java.util.Collection;
34+
import lombok.NonNull;
3235
import org.jetbrains.annotations.ApiStatus;
36+
import org.jetbrains.annotations.NotNull;
3337

3438
/**
3539
* Represents the mod settings module.
@@ -50,4 +54,16 @@ public boolean isClientNotify() {
5054
return true;
5155
}
5256

57+
/**
58+
* Gets the value of the specified {@link Option} for the {@link ApolloPlayer}.
59+
*
60+
* @param player the apollo player
61+
* @param option the option
62+
* @param <T> the value type
63+
* @param <C> the option type
64+
* @return the value of the option
65+
* @since 1.2.1
66+
*/
67+
public abstract <T, C extends Option<T, ?, ?>> T getStatus(@NotNull ApolloPlayer player, @NonNull C option);
68+
5369
}

api/src/main/java/com/lunarclient/apollo/player/ApolloPlayer.java

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@
2727
import com.lunarclient.apollo.client.version.LunarClientVersion;
2828
import com.lunarclient.apollo.client.version.MinecraftVersion;
2929
import com.lunarclient.apollo.common.location.ApolloLocation;
30-
import com.lunarclient.apollo.mods.ModStatus;
3130
import com.lunarclient.apollo.module.tebex.TebexEmbeddedCheckoutSupport;
3231
import com.lunarclient.apollo.option.Option;
3332
import com.lunarclient.apollo.option.Options;
@@ -145,13 +144,4 @@ default boolean hasPermission(Options options, Option<String, ?, ?> option) {
145144
*/
146145
@Nullable TebexEmbeddedCheckoutSupport getTebexEmbeddedCheckoutSupport();
147146

148-
/**
149-
* Returns the {@link ModStatus} interface used for retrieving
150-
* the current value of mod options.
151-
*
152-
* @return the mod status interface
153-
* @since 1.2.1
154-
*/
155-
@Nullable ModStatus getModStatus();
156-
157147
}

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

Lines changed: 1 addition & 86 deletions
Original file line numberDiff line numberDiff line change
@@ -23,23 +23,10 @@
2323
*/
2424
package com.lunarclient.apollo.mods;
2525

26-
import com.google.protobuf.Any;
27-
import com.google.protobuf.InvalidProtocolBufferException;
28-
import com.google.protobuf.Value;
29-
import com.lunarclient.apollo.configurable.v1.ConfigurableSettings;
30-
import com.lunarclient.apollo.configurable.v1.OverrideConfigurableSettingsMessage;
31-
import com.lunarclient.apollo.event.ApolloListener;
32-
import com.lunarclient.apollo.event.ApolloReceivePacketEvent;
33-
import com.lunarclient.apollo.event.EventBus;
34-
import com.lunarclient.apollo.event.Listen;
35-
import com.lunarclient.apollo.event.mods.ApolloUpdateModOptionEvent;
36-
import com.lunarclient.apollo.network.NetworkOptions;
3726
import com.lunarclient.apollo.option.Option;
3827
import com.lunarclient.apollo.option.StatusOptionsImpl;
39-
import com.lunarclient.apollo.player.ApolloPlayer;
4028
import java.lang.reflect.Field;
4129
import java.util.ArrayList;
42-
import java.util.Collections;
4330
import java.util.LinkedHashMap;
4431
import java.util.List;
4532
import java.util.Map;
@@ -52,7 +39,7 @@
5239
* @since 1.2.1
5340
*/
5441
@Getter
55-
public final class ApolloModsManager implements ApolloListener {
42+
public final class ApolloModsManager {
5643

5744
private final Container container;
5845
private final StatusOptionsImpl playerOptions;
@@ -63,8 +50,6 @@ public final class ApolloModsManager implements ApolloListener {
6350
* @since 1.2.1
6451
*/
6552
public ApolloModsManager() {
66-
EventBus.getBus().register(this);
67-
6853
this.container = ApolloModsManager.loadModOptions();
6954
this.playerOptions = new StatusOptionsImpl(this.container.getModStatusOptions());
7055
}
@@ -135,74 +120,4 @@ public static class Container {
135120

136121
}
137122

138-
@Listen
139-
private void onApolloReceivePacket(ApolloReceivePacketEvent event) {
140-
ApolloPlayer player = event.getPlayer();
141-
Any packet = event.getPacket();
142-
143-
if(packet.is(OverrideConfigurableSettingsMessage.class) || packet.is(ConfigurableSettings.class)) {
144-
this.handleConfiguration(player, packet);
145-
}
146-
}
147-
148-
private void handleConfiguration(ApolloPlayer player, Any any) {
149-
// Unpack the settings first.
150-
List<ConfigurableSettings> settings;
151-
try {
152-
if (any.is(OverrideConfigurableSettingsMessage.class)) {
153-
OverrideConfigurableSettingsMessage message = any.unpack(OverrideConfigurableSettingsMessage.class);
154-
settings = message.getConfigurableSettingsList();
155-
} else {
156-
settings = Collections.singletonList(any.unpack(ConfigurableSettings.class));
157-
}
158-
} catch (InvalidProtocolBufferException exception) {
159-
throw new RuntimeException(exception);
160-
}
161-
162-
for (ConfigurableSettings setting : settings) {
163-
if (!setting.hasApolloModule()) {
164-
continue;
165-
}
166-
167-
if (!setting.getApolloModule().equals("mod_status")) {
168-
continue;
169-
}
170-
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());
189-
190-
Object unwrappedValue = NetworkOptions.unwrapValue(
191-
entry.getValue(),
192-
option.getTypeToken().getType()
193-
);
194-
195-
this.playerOptions.set(player, option, unwrappedValue);
196-
System.out.println("Set: " + option.getKey() + "=" + unwrappedValue);
197-
198-
if (callEvent) {
199-
EventBus.EventResult<ApolloUpdateModOptionEvent> eventResult = EventBus.getBus()
200-
.post(new ApolloUpdateModOptionEvent(player, option, unwrappedValue));
201-
202-
for (Throwable throwable : eventResult.getThrowing()) {
203-
throwable.printStackTrace();
204-
}
205-
}
206-
}
207-
}
208123
}

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

Lines changed: 0 additions & 47 deletions
This file was deleted.

common/src/main/java/com/lunarclient/apollo/module/modsettings/ModSettingsModuleImpl.java

Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,25 @@
2323
*/
2424
package com.lunarclient.apollo.module.modsettings;
2525

26+
import com.google.protobuf.Any;
27+
import com.google.protobuf.InvalidProtocolBufferException;
28+
import com.google.protobuf.Value;
2629
import com.lunarclient.apollo.ApolloManager;
30+
import com.lunarclient.apollo.configurable.v1.ConfigurableSettings;
31+
import com.lunarclient.apollo.configurable.v1.OverrideConfigurableSettingsMessage;
32+
import com.lunarclient.apollo.event.ApolloReceivePacketEvent;
33+
import com.lunarclient.apollo.event.EventBus;
34+
import com.lunarclient.apollo.event.modsetting.ApolloUpdateModOptionEvent;
2735
import com.lunarclient.apollo.module.modsetting.ModSettingModule;
36+
import com.lunarclient.apollo.network.NetworkOptions;
37+
import com.lunarclient.apollo.option.Option;
38+
import com.lunarclient.apollo.option.StatusOptionsImpl;
39+
import com.lunarclient.apollo.player.ApolloPlayer;
40+
import java.util.Collections;
41+
import java.util.List;
42+
import java.util.Map;
43+
import lombok.NonNull;
44+
import org.jetbrains.annotations.NotNull;
2845

2946
/**
3047
* Provides the mod settings module.
@@ -41,6 +58,83 @@ public final class ModSettingsModuleImpl extends ModSettingModule {
4158
public ModSettingsModuleImpl() {
4259
super();
4360
this.registerOptions(ApolloManager.getModsManager().getContainer().getModSettingsOptions());
61+
this.handle(ApolloReceivePacketEvent.class, this::onReceivePacket);
62+
}
63+
64+
@Override
65+
public <T, C extends Option<T, ?, ?>> T getStatus(@NotNull ApolloPlayer player, @NonNull C option) {
66+
return ApolloManager.getModsManager().getPlayerOptions().get(player.getUniqueId(), option);
67+
}
68+
69+
private void onReceivePacket(ApolloReceivePacketEvent event) {
70+
ApolloPlayer player = event.getPlayer();
71+
Any packet = event.getPacket();
72+
73+
if(packet.is(OverrideConfigurableSettingsMessage.class) || packet.is(ConfigurableSettings.class)) {
74+
this.handleConfiguration(player, packet);
75+
}
76+
}
77+
78+
private void handleConfiguration(ApolloPlayer player, Any any) {
79+
// Unpack the settings first.
80+
List<ConfigurableSettings> settings;
81+
try {
82+
if (any.is(OverrideConfigurableSettingsMessage.class)) {
83+
OverrideConfigurableSettingsMessage message = any.unpack(OverrideConfigurableSettingsMessage.class);
84+
settings = message.getConfigurableSettingsList();
85+
} else {
86+
settings = Collections.singletonList(any.unpack(ConfigurableSettings.class));
87+
}
88+
} catch (InvalidProtocolBufferException exception) {
89+
throw new RuntimeException(exception);
90+
}
91+
92+
for (ConfigurableSettings setting : settings) {
93+
if (!setting.hasApolloModule()) {
94+
continue;
95+
}
96+
97+
if (!setting.getApolloModule().equals(this.getId())) {
98+
continue;
99+
}
100+
101+
this.updateOptions(player, setting.getPropertiesMap(), false);
102+
}
103+
}
104+
105+
/**
106+
* Updates the {@link Option}s for a specific {@link ApolloPlayer} using the properties
107+
* received from the client.
108+
*
109+
* @param player the apollo player
110+
* @param properties a map of option keys and values
111+
* @param callEvent whether to call the update mod option event
112+
* @since 1.2.1
113+
*/
114+
public void updateOptions(ApolloPlayer player, Map<String, Value> properties, boolean callEvent) {
115+
StatusOptionsImpl statusOptions = ApolloManager.getModsManager().getPlayerOptions();
116+
System.out.println("Update options: " + properties.size());
117+
118+
for (Map.Entry<String, Value> entry : properties.entrySet()) {
119+
Option<?, ?, ?> option = statusOptions.getOptionsByKey().get(entry.getKey());
120+
121+
Object unwrappedValue = NetworkOptions.unwrapValue(
122+
entry.getValue(),
123+
option.getTypeToken().getType()
124+
);
125+
126+
statusOptions.set(player, option, unwrappedValue);
127+
System.out.println("Set: " + option.getKey() + "=" + unwrappedValue);
128+
129+
if (callEvent) {
130+
EventBus.EventResult<ApolloUpdateModOptionEvent> eventResult = EventBus.getBus()
131+
.post(new ApolloUpdateModOptionEvent(player, option, unwrappedValue));
132+
133+
for (Throwable throwable : eventResult.getThrowing()) {
134+
throwable.printStackTrace();
135+
}
136+
}
137+
}
44138
}
45139

46140
}

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

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@
3232
import com.lunarclient.apollo.client.version.LunarClientVersion;
3333
import com.lunarclient.apollo.client.version.MinecraftVersion;
3434
import com.lunarclient.apollo.common.location.ApolloLocation;
35-
import com.lunarclient.apollo.mods.ModStatus;
3635
import com.lunarclient.apollo.module.tebex.TebexEmbeddedCheckoutSupport;
3736
import com.lunarclient.apollo.roundtrip.ApolloRequest;
3837
import com.lunarclient.apollo.roundtrip.ApolloResponse;
@@ -54,7 +53,6 @@ public abstract class AbstractApolloPlayer implements ApolloPlayer {
5453
private LunarClientVersion lunarClientVersion;
5554
private List<LunarClientMod> installedMods;
5655
private TebexEmbeddedCheckoutSupport tebexEmbeddedCheckoutSupport;
57-
private ModStatus modStatus;
5856

5957
@Override
6058
public Optional<ApolloWorld> getWorld() {

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

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@
2525

2626
import com.google.protobuf.Value;
2727
import com.lunarclient.apollo.Apollo;
28-
import com.lunarclient.apollo.ApolloManager;
2928
import com.lunarclient.apollo.client.mod.LunarClientMod;
3029
import com.lunarclient.apollo.client.mod.LunarClientModType;
3130
import com.lunarclient.apollo.client.version.LunarClientVersion;
@@ -34,7 +33,8 @@
3433
import com.lunarclient.apollo.event.player.ApolloPlayerHandshakeEvent;
3534
import com.lunarclient.apollo.event.player.ApolloRegisterPlayerEvent;
3635
import com.lunarclient.apollo.event.player.ApolloUnregisterPlayerEvent;
37-
import com.lunarclient.apollo.mods.ModStatusImpl;
36+
import com.lunarclient.apollo.module.modsetting.ModSettingModule;
37+
import com.lunarclient.apollo.module.modsettings.ModSettingsModuleImpl;
3838
import com.lunarclient.apollo.module.tebex.TebexEmbeddedCheckoutSupport;
3939
import com.lunarclient.apollo.network.NetworkOptions;
4040
import com.lunarclient.apollo.player.v1.PlayerHandshakeMessage;
@@ -162,10 +162,12 @@ public void handlePlayerHandshake(@NotNull ApolloPlayer player, @NotNull PlayerH
162162

163163
Map<String, Value> modStatus = message.getModStatusMap();
164164
if (!modStatus.isEmpty()) {
165-
ApolloManager.getModsManager().updateOptions(apolloPlayer, modStatus, false);
166-
}
165+
ModSettingsModuleImpl modSettingModule = (ModSettingsModuleImpl) Apollo.getModuleManager().getModule(ModSettingModule.class);
167166

168-
apolloPlayer.setModStatus(new ModStatusImpl(player.getUniqueId()));
167+
if (modSettingModule.isEnabled()) {
168+
modSettingModule.updateOptions(apolloPlayer, modStatus, false);
169+
}
170+
}
169171
}
170172

171173
}

docs/developers/_meta.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
"options": "Options",
66
"modules": "Modules",
77
"mods": "Mods",
8-
"mod-status": "Mod Status",
98
"utilities": "Utilities",
109
"platform-utilities": "Platform Utilities",
1110
"adventure": "Adventure",

0 commit comments

Comments
 (0)