Skip to content

Commit 7fbc2e0

Browse files
committed
Add the pay now module
1 parent fb97136 commit 7fbc2e0

File tree

31 files changed

+527
-13
lines changed

31 files changed

+527
-13
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/paynow-module' }}"
4545
run: ./gradlew publish
4646

4747
- name: Gradle Release

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
@@ -32,6 +32,7 @@
3232
import com.lunarclient.apollo.event.player.ApolloPlayerHandshakeEvent;
3333
import com.lunarclient.apollo.event.player.ApolloRegisterPlayerEvent;
3434
import com.lunarclient.apollo.event.player.ApolloUnregisterPlayerEvent;
35+
import com.lunarclient.apollo.module.paynow.PayNowEmbeddedCheckoutSupport;
3536
import com.lunarclient.apollo.module.tebex.TebexEmbeddedCheckoutSupport;
3637
import com.lunarclient.apollo.network.NetworkOptions;
3738
import com.lunarclient.apollo.player.v1.PlayerHandshakeMessage;
@@ -137,15 +138,27 @@ public void handlePlayerHandshake(@NotNull ApolloPlayer player, @NotNull PlayerH
137138
.build()
138139
).collect(Collectors.toList());
139140

140-
TebexEmbeddedCheckoutSupport checkoutSupportType;
141+
int embeddedCheckoutSupport = message.getEmbeddedCheckoutSupportValue();
142+
TebexEmbeddedCheckoutSupport tebexEmbeddedCheckoutSupport;
141143
try {
142-
checkoutSupportType = TebexEmbeddedCheckoutSupport.values()[message.getEmbeddedCheckoutSupportValue() - 1];
144+
tebexEmbeddedCheckoutSupport = TebexEmbeddedCheckoutSupport.values()[embeddedCheckoutSupport - 1];
143145
} catch (ArrayIndexOutOfBoundsException e) {
144-
checkoutSupportType = TebexEmbeddedCheckoutSupport.UNSUPPORTED;
146+
tebexEmbeddedCheckoutSupport = TebexEmbeddedCheckoutSupport.UNSUPPORTED;
145147
}
146148

147-
EventBus.EventResult<ApolloPlayerHandshakeEvent> result = EventBus.getBus()
148-
.post(new ApolloPlayerHandshakeEvent(player, minecraftVersion, lunarClientVersion, mods, checkoutSupportType));
149+
PayNowEmbeddedCheckoutSupport payNowEmbeddedCheckoutSupport;
150+
try {
151+
payNowEmbeddedCheckoutSupport = PayNowEmbeddedCheckoutSupport.values()[embeddedCheckoutSupport - 1];
152+
} catch (ArrayIndexOutOfBoundsException e) {
153+
payNowEmbeddedCheckoutSupport = PayNowEmbeddedCheckoutSupport.UNSUPPORTED;
154+
}
155+
156+
ApolloPlayerHandshakeEvent event = new ApolloPlayerHandshakeEvent(
157+
player, minecraftVersion, lunarClientVersion, mods,
158+
tebexEmbeddedCheckoutSupport, payNowEmbeddedCheckoutSupport
159+
);
160+
161+
EventBus.EventResult<ApolloPlayerHandshakeEvent> result = EventBus.getBus().post(event);
149162

150163
for (Throwable throwable : result.getThrowing()) {
151164
throwable.printStackTrace();
@@ -155,7 +168,8 @@ public void handlePlayerHandshake(@NotNull ApolloPlayer player, @NotNull PlayerH
155168
apolloPlayer.setMinecraftVersion(minecraftVersion);
156169
apolloPlayer.setLunarClientVersion(lunarClientVersion);
157170
apolloPlayer.setInstalledMods(mods);
158-
apolloPlayer.setTebexEmbeddedCheckoutSupport(checkoutSupportType);
171+
apolloPlayer.setTebexEmbeddedCheckoutSupport(tebexEmbeddedCheckoutSupport);
172+
apolloPlayer.setPayNowEmbeddedCheckoutSupport(payNowEmbeddedCheckoutSupport);
159173
}
160174

161175
}

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

0 commit comments

Comments
 (0)