Skip to content

Commit 63a3bf1

Browse files
authored
Feature - PayNow Module (#244)
* Add the pay now module # Conflicts: # common/src/main/java/com/lunarclient/apollo/player/ApolloPlayerManagerImpl.java # docs/developers/lightweight/protobuf/getting-started.mdx # gradle/libs.versions.toml * Fix import order * Update example message * Paynow docs * Dont deploy this branch
1 parent 1322563 commit 63a3bf1

File tree

30 files changed

+612
-12
lines changed

30 files changed

+612
-12
lines changed

api/src/main/java/com/lunarclient/apollo/event/player/ApolloPlayerHandshakeEvent.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
import com.lunarclient.apollo.client.version.LunarClientVersion;
2828
import com.lunarclient.apollo.client.version.MinecraftVersion;
2929
import com.lunarclient.apollo.event.Event;
30+
import com.lunarclient.apollo.module.paynow.PayNowEmbeddedCheckoutSupport;
3031
import com.lunarclient.apollo.module.tebex.TebexEmbeddedCheckoutSupport;
3132
import com.lunarclient.apollo.player.ApolloPlayer;
3233
import java.util.List;
@@ -80,4 +81,12 @@ public class ApolloPlayerHandshakeEvent implements Event {
8081
*/
8182
TebexEmbeddedCheckoutSupport tebexEmbeddedCheckoutSupport;
8283

84+
/**
85+
* The {@link PayNowEmbeddedCheckoutSupport} type.
86+
*
87+
* @return the Pay Now checkout support type
88+
* @since 1.2.1
89+
*/
90+
PayNowEmbeddedCheckoutSupport payNowEmbeddedCheckoutSupport;
91+
8392
}
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
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.paynow;
25+
26+
/**
27+
* Represents the paynow embedded checkout support type.
28+
*
29+
* @since 1.2.1
30+
*/
31+
public enum PayNowEmbeddedCheckoutSupport {
32+
33+
/**
34+
* External checkout is supported as a game overlay.
35+
*
36+
* @since 1.2.1
37+
*/
38+
OVERLAY,
39+
40+
/**
41+
* Embedded checkout is supported in an external window.
42+
*
43+
* @since 1.2.1
44+
*/
45+
WINDOW,
46+
47+
/**
48+
* The checkout is not supported.
49+
*
50+
* @since 1.2.1
51+
*/
52+
UNSUPPORTED
53+
54+
}
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.module.paynow;
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 pay now module.
33+
*
34+
* @since 1.2.1
35+
*/
36+
@ApiStatus.NonExtendable
37+
@ModuleDefinition(id = "pay_now", name = "PayNow")
38+
public abstract class PayNowModule extends ApolloModule {
39+
40+
/**
41+
* Displays the checkout with the provided {@link String} checkout token to the {@link Recipients}.
42+
*
43+
* @param recipients the recipients that are receiving the packet
44+
* @param checkoutToken the paynow checkout token
45+
* @since 1.2.1
46+
*/
47+
public abstract void displayPayNowEmbeddedCheckout(Recipients recipients, String checkoutToken);
48+
49+
}

api/src/main/java/com/lunarclient/apollo/module/tebex/TebexEmbeddedCheckoutSupport.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
package com.lunarclient.apollo.module.tebex;
2525

2626
/**
27-
* Represents an embedded checkout support type.
27+
* Represents the tebex embedded checkout support type.
2828
*
2929
* @since 1.1.6
3030
*/

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

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
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.module.paynow.PayNowEmbeddedCheckoutSupport;
3031
import com.lunarclient.apollo.module.tebex.TebexEmbeddedCheckoutSupport;
3132
import com.lunarclient.apollo.option.Option;
3233
import com.lunarclient.apollo.option.Options;
@@ -144,4 +145,12 @@ default boolean hasPermission(Options options, Option<String, ?, ?> option) {
144145
*/
145146
@Nullable TebexEmbeddedCheckoutSupport getTebexEmbeddedCheckoutSupport();
146147

148+
/**
149+
* Returns the {@link PayNowEmbeddedCheckoutSupport} type.
150+
*
151+
* @return the Pay Now checkout support type
152+
* @since 1.2.1
153+
*/
154+
@Nullable PayNowEmbeddedCheckoutSupport getPayNowEmbeddedCheckoutSupport();
155+
147156
}
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
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.paynow;
25+
26+
import com.lunarclient.apollo.paynow.v1.OpenPayNowEmbeddedCheckoutMessage;
27+
import com.lunarclient.apollo.player.AbstractApolloPlayer;
28+
import com.lunarclient.apollo.recipients.Recipients;
29+
import lombok.NonNull;
30+
31+
/**
32+
* Provides the paynow module.
33+
*
34+
* @since 1.2.1
35+
*/
36+
public final class PayNowModuleImpl extends PayNowModule {
37+
38+
@Override
39+
public void displayPayNowEmbeddedCheckout(@NonNull Recipients recipients, @NonNull String checkoutToken) {
40+
OpenPayNowEmbeddedCheckoutMessage message = OpenPayNowEmbeddedCheckoutMessage.newBuilder()
41+
.setCheckoutToken(checkoutToken)
42+
.build();
43+
44+
recipients.forEach(player -> ((AbstractApolloPlayer) player).sendPacket(message));
45+
}
46+
47+
}

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
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.module.paynow.PayNowEmbeddedCheckoutSupport;
3536
import com.lunarclient.apollo.module.tebex.TebexEmbeddedCheckoutSupport;
3637
import com.lunarclient.apollo.roundtrip.ApolloRequest;
3738
import com.lunarclient.apollo.roundtrip.ApolloResponse;
@@ -53,6 +54,7 @@ public abstract class AbstractApolloPlayer implements ApolloPlayer {
5354
private LunarClientVersion lunarClientVersion;
5455
private List<LunarClientMod> installedMods;
5556
private TebexEmbeddedCheckoutSupport tebexEmbeddedCheckoutSupport;
57+
private PayNowEmbeddedCheckoutSupport payNowEmbeddedCheckoutSupport;
5658

5759
@Override
5860
public Optional<ApolloWorld> getWorld() {

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

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
import com.lunarclient.apollo.event.player.ApolloUnregisterPlayerEvent;
3636
import com.lunarclient.apollo.module.modsetting.ModSettingModule;
3737
import com.lunarclient.apollo.module.modsettings.ModSettingModuleImpl;
38+
import com.lunarclient.apollo.module.paynow.PayNowEmbeddedCheckoutSupport;
3839
import com.lunarclient.apollo.module.tebex.TebexEmbeddedCheckoutSupport;
3940
import com.lunarclient.apollo.network.NetworkOptions;
4041
import com.lunarclient.apollo.player.v1.PlayerHandshakeMessage;
@@ -140,18 +141,27 @@ public void handlePlayerHandshake(@NotNull ApolloPlayer player, @NotNull PlayerH
140141
.build()
141142
).collect(Collectors.toList());
142143

143-
TebexEmbeddedCheckoutSupport checkoutSupportType;
144+
int embeddedCheckoutSupport = message.getEmbeddedCheckoutSupportValue();
145+
TebexEmbeddedCheckoutSupport tebexEmbeddedCheckoutSupport;
144146
try {
145-
checkoutSupportType = TebexEmbeddedCheckoutSupport.values()[message.getEmbeddedCheckoutSupportValue() - 1];
147+
tebexEmbeddedCheckoutSupport = TebexEmbeddedCheckoutSupport.values()[embeddedCheckoutSupport - 1];
146148
} catch (ArrayIndexOutOfBoundsException e) {
147-
checkoutSupportType = TebexEmbeddedCheckoutSupport.UNSUPPORTED;
149+
tebexEmbeddedCheckoutSupport = TebexEmbeddedCheckoutSupport.UNSUPPORTED;
150+
}
151+
152+
PayNowEmbeddedCheckoutSupport payNowEmbeddedCheckoutSupport;
153+
try {
154+
payNowEmbeddedCheckoutSupport = PayNowEmbeddedCheckoutSupport.values()[embeddedCheckoutSupport - 1];
155+
} catch (ArrayIndexOutOfBoundsException e) {
156+
payNowEmbeddedCheckoutSupport = PayNowEmbeddedCheckoutSupport.UNSUPPORTED;
148157
}
149158

150159
AbstractApolloPlayer apolloPlayer = ((AbstractApolloPlayer) player);
151160
apolloPlayer.setMinecraftVersion(minecraftVersion);
152161
apolloPlayer.setLunarClientVersion(lunarClientVersion);
153162
apolloPlayer.setInstalledMods(mods);
154-
apolloPlayer.setTebexEmbeddedCheckoutSupport(checkoutSupportType);
163+
apolloPlayer.setTebexEmbeddedCheckoutSupport(tebexEmbeddedCheckoutSupport);
164+
apolloPlayer.setPayNowEmbeddedCheckoutSupport(payNowEmbeddedCheckoutSupport);
155165

156166
Map<String, Value> modStatus = message.getModStatusMap();
157167
if (!modStatus.isEmpty()) {
@@ -162,8 +172,12 @@ public void handlePlayerHandshake(@NotNull ApolloPlayer player, @NotNull PlayerH
162172
}
163173
}
164174

165-
EventBus.EventResult<ApolloPlayerHandshakeEvent> result = EventBus.getBus()
166-
.post(new ApolloPlayerHandshakeEvent(player, minecraftVersion, lunarClientVersion, mods, checkoutSupportType));
175+
ApolloPlayerHandshakeEvent event = new ApolloPlayerHandshakeEvent(
176+
player, minecraftVersion, lunarClientVersion, mods,
177+
tebexEmbeddedCheckoutSupport, payNowEmbeddedCheckoutSupport
178+
);
179+
180+
EventBus.EventResult<ApolloPlayerHandshakeEvent> result = EventBus.getBus().post(event);
167181

168182
for (Throwable throwable : result.getThrowing()) {
169183
throwable.printStackTrace();

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.4</version>
29+
<version>0.0.5</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.4'
44+
api 'com.lunarclient:apollo-protos:0.0.5'
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.4")
58+
api("com.lunarclient:apollo-protos:0.0.5")
5959
}
6060
```
6161
</Tab>

docs/developers/modules/_meta.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
"nametag": "Nametag",
1717
"nickhider": "Nick Hider",
1818
"notification": "Notification",
19+
"paynow": "Pay Now",
1920
"packetenrichment": "Packet Enrichment",
2021
"richpresence": "Rich Presence",
2122
"saturation": "Saturation",

0 commit comments

Comments
 (0)