Skip to content

Commit 9325ec6

Browse files
committed
Apollo Mod Status API
1 parent a7537e9 commit 9325ec6

File tree

20 files changed

+739
-229
lines changed

20 files changed

+739
-229
lines changed

.github/workflows/deploy.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ jobs:
4141
fi
4242
4343
- name: Gradle Publish
44-
if: "${{ github.ref == 'refs/heads/master' || startsWith(github.ref, 'refs/heads/version/') }}"
44+
if: "${{ github.ref == 'refs/heads/master' || startsWith(github.ref, 'refs/heads/version/') || github.ref == 'refs/heads/feature/mod-status' }}"
4545
run: ./gradlew publish
4646

4747
- name: Gradle Release
Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
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.event.mods;
25+
26+
import com.lunarclient.apollo.event.Event;
27+
import com.lunarclient.apollo.option.Option;
28+
import com.lunarclient.apollo.option.Options;
29+
import com.lunarclient.apollo.player.ApolloPlayer;
30+
import lombok.Value;
31+
import org.jetbrains.annotations.Nullable;
32+
33+
/**
34+
* Represents an event that is fired when an option is updated.
35+
*
36+
* @since 1.2.1
37+
*/
38+
@Value
39+
public final class ApolloUpdateModOptionEvent implements Event {
40+
41+
// TODO: not needed?
42+
/**
43+
* The {@link Options} container that the option is in.
44+
*
45+
* @return the options container
46+
* @since 1.2.1
47+
*/
48+
Options container;
49+
50+
/**
51+
* The {@link ApolloPlayer} that the option was updated for.
52+
*
53+
* @return the player
54+
* @since 1.2.1
55+
*/
56+
ApolloPlayer player;
57+
58+
/**
59+
* The {@link Option} that was updated.
60+
*
61+
* @return the option
62+
* @since 1.2.1
63+
*/
64+
Option<?, ?, ?> option;
65+
66+
/**
67+
* The new value of the option.
68+
*
69+
* @return the new value
70+
* @since 1.2.1
71+
*/
72+
@Nullable Object value;
73+
74+
}
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
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.mods;
25+
26+
import com.lunarclient.apollo.option.Option;
27+
import lombok.NonNull;
28+
import org.jetbrains.annotations.ApiStatus;
29+
30+
/**
31+
* Represents the current values for Lunar Client mod options.
32+
*
33+
* @since 1.2.1
34+
*/
35+
@ApiStatus.NonExtendable
36+
public interface ModStatus {
37+
38+
/**
39+
* Gets the value of the specified {@link Option}.
40+
*
41+
* @param option the option
42+
* @param <T> the value type
43+
* @param <C> the option type
44+
* @return the value of the option
45+
* @since 1.2.1
46+
*/
47+
public <T, C extends Option<T, ?, ?>> T get(@NonNull C option);
48+
49+
}

api/src/main/java/com/lunarclient/apollo/mods/Mods.java

Lines changed: 124 additions & 88 deletions
Original file line numberDiff line numberDiff line change
@@ -110,8 +110,12 @@
110110
import com.lunarclient.apollo.mods.impl.ModWeatherChanger;
111111
import com.lunarclient.apollo.mods.impl.ModWorldeditCui;
112112
import com.lunarclient.apollo.mods.impl.ModZoom;
113+
import com.lunarclient.apollo.option.Option;
114+
import java.lang.reflect.Field;
113115
import java.util.Arrays;
116+
import java.util.LinkedHashMap;
114117
import java.util.List;
118+
import java.util.Map;
115119

116120
/**
117121
* Mod container.
@@ -120,100 +124,132 @@
120124
*/
121125
public final class Mods {
122126

127+
private static final Map<String, Option<?, ?, ?>> OPTIONS = Mods.collectModOptions();
128+
123129
/**
124130
* List of all current mod classes.
125131
*
126132
* @since 1.0.0
127133
*/
128134
public static final List<Class<?>> ALL_MODS = Arrays.asList(
129-
ModReplaymod.class,
130-
ModOneSevenVisuals.class,
131-
ModFps.class,
132-
ModCps.class,
133-
ModSba.class,
134-
ModToggleSneak.class,
135-
ModZoom.class,
136-
ModHypixelMod.class,
137-
ModHypixelBedwars.class,
138-
ModQuickplay.class,
139-
ModArmorstatus.class,
140-
ModKeystrokes.class,
141-
ModCoordinates.class,
142-
ModDayCounter.class,
143-
ModCrosshair.class,
144-
ModPotionEffects.class,
145-
ModDirectionHud.class,
146-
ModWaypoints.class,
147-
ModHitColor.class,
148-
ModScoreboard.class,
149-
ModTitles.class,
150-
ModItemCounter.class,
151-
ModPing.class,
152-
ModMotionBlur.class,
153-
ModPackOrganizer.class,
154-
ModChat.class,
155-
ModTab.class,
156-
ModNametag.class,
157-
ModShulkerPreview.class,
158-
ModScrollableTooltips.class,
159-
ModUhcOverlay.class,
160-
ModParticleChanger.class,
161-
ModNickHider.class,
162-
ModCooldowns.class,
163-
ModWorldeditCui.class,
164-
ModClock.class,
165-
ModStopwatch.class,
166-
ModPlaytime.class,
167-
ModMemory.class,
168-
ModCombo.class,
169-
ModReachDisplay.class,
170-
ModTimeChanger.class,
171-
ModServerAddress.class,
172-
ModSaturation.class,
173-
ModColorSaturation.class,
174-
ModItemPhysics.class,
175-
ModTntCountdown.class,
176-
ModItemTracker.class,
177-
ModShinyPots.class,
178-
Mod3dSkins.class,
179-
ModGlintColorizer.class,
180-
ModMomentum.class,
181-
ModBlockOutline.class,
182-
ModScreenshot.class,
183-
ModFov.class,
184-
ModFog.class,
185-
ModAutoTextHotkey.class,
186-
ModAutoTextActions.class,
187-
ModMumbleLink.class,
188-
ModTotemCounter.class,
189-
Mod2dItems.class,
190-
ModBossbar.class,
191-
ModFreelook.class,
192-
ModPvpInfo.class,
193-
ModSnaplook.class,
194-
ModTeamView.class,
195-
ModPackDisplay.class,
196-
ModMenuBlur.class,
197-
ModMinimap.class,
198-
ModHitbox.class,
199-
ModLighting.class,
200-
ModWeatherChanger.class,
201-
ModChunkBorders.class,
202-
ModSoundChanger.class,
203-
ModWaila.class,
204-
ModNeu.class,
205-
ModHurtCam.class,
206-
ModTierTagger.class,
207-
ModDamageTint.class,
208-
ModMobSize.class,
209-
ModSkyblock.class,
210-
ModHorseStats.class,
211-
ModRewind.class,
212-
ModAudioSubtitles.class,
213-
ModKillSounds.class,
214-
ModInventoryMod.class,
215-
ModRadio.class
216-
);
135+
ModReplaymod.class,
136+
ModOneSevenVisuals.class,
137+
ModFps.class,
138+
ModCps.class,
139+
ModSba.class,
140+
ModToggleSneak.class,
141+
ModZoom.class,
142+
ModHypixelMod.class,
143+
ModHypixelBedwars.class,
144+
ModQuickplay.class,
145+
ModArmorstatus.class,
146+
ModKeystrokes.class,
147+
ModCoordinates.class,
148+
ModDayCounter.class,
149+
ModCrosshair.class,
150+
ModPotionEffects.class,
151+
ModDirectionHud.class,
152+
ModWaypoints.class,
153+
ModHitColor.class,
154+
ModScoreboard.class,
155+
ModTitles.class,
156+
ModItemCounter.class,
157+
ModPing.class,
158+
ModMotionBlur.class,
159+
ModPackOrganizer.class,
160+
ModChat.class,
161+
ModTab.class,
162+
ModNametag.class,
163+
ModShulkerPreview.class,
164+
ModScrollableTooltips.class,
165+
ModUhcOverlay.class,
166+
ModParticleChanger.class,
167+
ModNickHider.class,
168+
ModCooldowns.class,
169+
ModWorldeditCui.class,
170+
ModClock.class,
171+
ModStopwatch.class,
172+
ModPlaytime.class,
173+
ModMemory.class,
174+
ModCombo.class,
175+
ModReachDisplay.class,
176+
ModTimeChanger.class,
177+
ModServerAddress.class,
178+
ModSaturation.class,
179+
ModColorSaturation.class,
180+
ModItemPhysics.class,
181+
ModTntCountdown.class,
182+
ModItemTracker.class,
183+
ModShinyPots.class,
184+
Mod3dSkins.class,
185+
ModGlintColorizer.class,
186+
ModMomentum.class,
187+
ModBlockOutline.class,
188+
ModScreenshot.class,
189+
ModFov.class,
190+
ModFog.class,
191+
ModAutoTextHotkey.class,
192+
ModAutoTextActions.class,
193+
ModMumbleLink.class,
194+
ModTotemCounter.class,
195+
Mod2dItems.class,
196+
ModBossbar.class,
197+
ModFreelook.class,
198+
ModPvpInfo.class,
199+
ModSnaplook.class,
200+
ModTeamView.class,
201+
ModPackDisplay.class,
202+
ModMenuBlur.class,
203+
ModMinimap.class,
204+
ModHitbox.class,
205+
ModLighting.class,
206+
ModWeatherChanger.class,
207+
ModChunkBorders.class,
208+
ModSoundChanger.class,
209+
ModWaila.class,
210+
ModNeu.class,
211+
ModHurtCam.class,
212+
ModTierTagger.class,
213+
ModDamageTint.class,
214+
ModMobSize.class,
215+
ModSkyblock.class,
216+
ModHorseStats.class,
217+
ModRewind.class,
218+
ModAudioSubtitles.class,
219+
ModKillSounds.class,
220+
ModInventoryMod.class,
221+
ModRadio.class
222+
);
223+
224+
/**
225+
* Returns a new map containing all mod options.
226+
*
227+
* @return a linked hash map of mod option keys to options
228+
* @since 1.2.1
229+
*/
230+
public static Map<String, Option<?, ?, ?>> getOptions() {
231+
return new LinkedHashMap<>(OPTIONS);
232+
}
233+
234+
private static Map<String, Option<?, ?, ?>> collectModOptions() {
235+
Map<String, Option<?, ?, ?>> options = new LinkedHashMap<>();
236+
237+
for (Class<?> mod : Mods.ALL_MODS) {
238+
Field[] fields = mod.getDeclaredFields();
239+
240+
for (Field field : fields) {
241+
try {
242+
field.setAccessible(true);
243+
Option<?, ?, ?> option = (Option<?, ?, ?>) field.get(Option.class);
244+
options.put(option.getKey(), option);
245+
} catch (IllegalAccessException e) {
246+
e.printStackTrace();
247+
}
248+
}
249+
}
250+
251+
return options;
252+
}
217253

218254
private Mods() {
219255
}

api/src/main/java/com/lunarclient/apollo/module/ApolloModule.java

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,17 @@ protected ApolloModule() {
120120
* @since 1.0.0
121121
*/
122122
protected void registerOptions(Option<?, ?, ?>... options) {
123-
this.optionKeys.addAll(Arrays.asList(options));
123+
this.registerOptions(Arrays.asList(options));
124+
}
125+
126+
/**
127+
* Registers {@link Option}s for this module.
128+
*
129+
* @param options the option keys
130+
* @since 1.2.1
131+
*/
132+
protected void registerOptions(Collection<Option<?, ?, ?>> options) {
133+
this.optionKeys.addAll(options);
124134
}
125135

126136
/**

0 commit comments

Comments
 (0)