Skip to content

Commit fd12f83

Browse files
emmachaseLemmmy
andcommitted
chore: open source squash
Co-authored-by: Drew Edwards <github@drew.contact>
0 parents  commit fd12f83

File tree

160 files changed

+9633
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

160 files changed

+9633
-0
lines changed

.editorconfig

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
root = true
2+
3+
[*]
4+
end_of_line = lf
5+
insert_final_newline = true
6+
7+
[*.{java,kt,kts,lua}]
8+
indent_style = space
9+
indent_size = 4

.github/workflows/build.yml

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
# Copyright (c) 2024 tmpim All rights reserved.
2+
# Use of this source code is governed by a BSD-style
3+
# license that can be found in the LICENSE file.
4+
5+
name: build
6+
on:
7+
push:
8+
tags:
9+
- 'v*'
10+
jobs:
11+
build:
12+
runs-on: ubuntu-latest
13+
steps:
14+
- name: Checkout repository
15+
uses: actions/checkout@v2
16+
17+
- name: Setup JDK 17
18+
uses: actions/setup-java@v2
19+
with:
20+
distribution: 'temurin'
21+
java-version: 17
22+
23+
- name: Make Gradle wrapper executable
24+
if: ${{ runner.os != 'Windows' }}
25+
run: chmod +x ./gradlew
26+
27+
- name: Validate Gradle wrapper
28+
uses: gradle/wrapper-validation-action@v1
29+
30+
- name: Build and publish
31+
uses: nick-fields/retry@v2
32+
with:
33+
command: ./gradlew --no-parallel publishKristpay
34+
timeout_minutes: 69
35+
max_attempts: 5
36+
retry_on: error
37+
env:
38+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

.gitignore

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
# gradle
2+
3+
.gradle/
4+
build/
5+
out/
6+
classes/
7+
8+
# eclipse
9+
10+
*.launch
11+
12+
# idea
13+
14+
.idea/
15+
*.iml
16+
*.ipr
17+
*.iws
18+
19+
# vscode
20+
21+
.settings/
22+
.vscode/
23+
bin/
24+
.classpath
25+
.project
26+
27+
# macos
28+
29+
*.DS_Store
30+
31+
# fabric
32+
33+
run/
34+
logs/

LICENSE

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
BSD 3-Clause License
2+
3+
Copyright (c) 2022-2024, tmpim
4+
5+
Redistribution and use in source and binary forms, with or without
6+
modification, are permitted provided that the following conditions are met:
7+
8+
1. Redistributions of source code must retain the above copyright notice, this
9+
list of conditions and the following disclaimer.
10+
11+
2. Redistributions in binary form must reproduce the above copyright notice,
12+
this list of conditions and the following disclaimer in the documentation
13+
and/or other materials provided with the distribution.
14+
15+
3. Neither the name of the copyright holder nor the names of its
16+
contributors may be used to endorse or promote products derived from
17+
this software without specific prior written permission.
18+
19+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
20+
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21+
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
22+
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
23+
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
24+
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
25+
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
26+
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
27+
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28+
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

README.md

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
# KristPay3
2+
3+
## Commands
4+
5+
### For Players
6+
- `/bal[ance]` (kristpay.balance.get.base)<br />View your own Krist balance
7+
- `/txs` `/transactions` (kristpay.list.base)<br />View your own transaction history
8+
- `/pay <address> <amount>` (kristpay.pay.address)<br />Pay another player or Krist address
9+
- `/deposit` (no permission node)<br />View your own deposit address
10+
- `/welfare` (kristpay.welfare.check.base)<br />Check whether you are opted into welfare
11+
- `/welfare opt in` (kristpay.welfare.opt.in.base)<br />Opt into welfare
12+
- `/welfare opt out` (kristpay.welfare.opt.out.base)<br />Opt out of welfare
13+
- `/welfare return` (kristpay.welfare.return.base)<br />Return your welfare rewards to the master wallet
14+
15+
### For Staff
16+
- `/bal[ance] <player>` (kristpay.balance.get.others)<br />View another player's Krist balance
17+
- `/setbal [player] <amount>` (kristpay.balance.set)<br />Set a player's Krist balance
18+
- `/grant <player> <amount>` (kristpay.balance.grant)<br />Grant a player Krist (semantically equivalent to `/setbal oldBal+delta`)
19+
- `/txs <player>` `/transactions <player>` (kristpay.list.others)<br />View another player's transaction history
20+
- `/masterbal` (kristpay.masterbal.check)<br />View the master wallet and the allocated / unallocated amounts
21+
- `/welfare <player>` (kristpay.welfare.check.others)<br />Check whether a player is opted into welfare
22+
- `/welfare return <player>` (kristpay.welfare.return.others)<br />Return a player's welfare rewards to the master wallet
23+
24+
## Permissions
25+
Permission | Role | Description
26+
-|-|-
27+
kristpay.balance.get.base | USER | Allows the user to view their own Krist balance
28+
kristpay.balance.get.others | MOD | Allows the user to view another user's Krist balance
29+
kristpay.balance.set.base | ADMIN | Set your Krist balance
30+
kristpay.balance.set.others | ADMIN | Set another user's Krist balance
31+
kristpay.grant.base | ADMIN | Grant yourself Krist
32+
kristpay.grant.others | ADMIN | Grant another user Krist
33+
kristpay.list.base | USER | List your own transactions
34+
kristpay.list.others | MOD | List another user's transactions
35+
kristpay.masterbal.check | MOD | Allow the user to check the master wallet balance
36+
kristpay.pay.address | USER | Allow the user to pay another user or address
37+
kristpay.welfare.check.base | USER | Allow the user to check whether they are opted into welfare
38+
kristpay.welfare.check.others | MOD | Check whether another user is opted into welfare
39+
kristpay.welfare.claim | NONE | Allow the user to claim all types of welfare
40+
kristpay.welfare.claim.faucet | USER | Allow the user to run /faucet
41+
kristpay.welfare.claim.login | USER | Allow the user to claim the daily login bonus
42+
kristpay.welfare.opt.in | USER | Allow the user to opt in to welfare
43+
kristpay.welfare.opt.out | USER | Allow the user to opt out of welfare
44+
kristpay.welfare.return.base | USER | Allows the user to return the welfare rewards they have received back to the server
45+
kristpay.welfare.return.others | ADMIN | Force another user to return the welfare rewards they have received
46+
47+
## API Usage
48+
49+
![](https://maven.pkg.github.com/SwitchCraftCC/KristPay3-OSS/api/badge/latest/releases/io/sc3/kristpay-api?name=Latest%20version)
50+
```properties
51+
# gradle.properties
52+
kristpayVersion = <version>
53+
```
54+
55+
```kotlin
56+
// build.gradle.kts
57+
val kristpayVersion: String by project
58+
59+
repositories {
60+
maven {
61+
url = uri("https://maven.pkg.github.com/SwitchCraftCC/KristPay3-OSS/releases")
62+
content {
63+
includeGroup("io.sc3")
64+
}
65+
}
66+
}
67+
68+
dependencies {
69+
compileOnly("io.sc3", "kristpay-api", kristpayVersion)
70+
}
71+
```

api/build.gradle.kts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
/*
2+
* Copyright (c) 2024 tmpim All rights reserved.
3+
* Use of this source code is governed by a BSD-style
4+
* license that can be found in the LICENSE file.
5+
*/
6+
7+
base {
8+
archivesName.set("kristpay-api")
9+
}
Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
/*
2+
* Copyright (c) 2024 tmpim All rights reserved.
3+
* Use of this source code is governed by a BSD-style
4+
* license that can be found in the LICENSE file.
5+
*/
6+
7+
package io.sc3.kristpay.api
8+
9+
import io.sc3.kristpay.api.model.*
10+
import io.sc3.kristpay.api.model.frontend.TransactionSymbol
11+
import kotlinx.serialization.json.JsonObject
12+
import org.jetbrains.annotations.ApiStatus.Internal
13+
import java.util.*
14+
15+
typealias UserID = UUID
16+
typealias WalletID = UUID
17+
typealias UserGroupID = UUID
18+
19+
interface KristPayAPI {
20+
21+
fun acquireServiceWallet(id: String): WalletID
22+
23+
suspend fun planServicePayment(request: ServicePaymentRequest): ServicePaymentPlan?
24+
fun subscribeToPaymentGroup(pluginID: PluginID, groupID: GroupID, callback: (ServicePayment) -> Unit)
25+
26+
/** Callback should return a TransactionSymbol object, or null if it doesn't want to handle the transaction. */
27+
fun registerTransactionSymbol(callback: (KristPayWallet, TransactionSnapshot) -> TransactionSymbol?)
28+
/** Callback should return a list of Minecraft Text objects, serialised to JSON, or null if it doesn't want to
29+
* handle the transaction. */
30+
fun registerTransactionDescriptor(callback: (KristPayWallet, TransactionSnapshot) -> List<String>?)
31+
32+
fun getMasterWallet(): MasterWallet
33+
34+
fun getWalletSnapshot(wallet: WalletID): WalletSnapshot?
35+
fun getWalletName(wallet: WalletID): String?
36+
37+
fun findWalletByName(name: String): WalletSnapshot?
38+
39+
fun getDefaultWallet(userID: UserID): WalletID?
40+
fun getDefaultWalletSnapshot(userID: UserID): WalletSnapshot? = getDefaultWallet(userID)?.let { getWalletSnapshot(it) }
41+
42+
fun getNotifications(userID: UserID): List<NotificationSnapshot>
43+
fun clearNotifications(userID: UserID)
44+
45+
// True if user was created, False if user already existed
46+
fun initializeUser(userID: UserID, userReferenceName: String, giveStartingBalance: Boolean = true): Boolean
47+
48+
fun initializeTransaction(
49+
from: PaymentActor,
50+
to: PaymentActor,
51+
amount: MonetaryAmount,
52+
metadata: String? = null,
53+
initiator: Initiator,
54+
systemMetadata: JsonObject? = null,
55+
sendNotification: Boolean = true,
56+
externalReference: Int? = null,
57+
allowDebt: Boolean = false
58+
): PaymentResult
59+
60+
// The list returned is lazy, and will only fetch more pages as needed
61+
// Because of this, never fully iterate over the list unless you're sure you want to
62+
// Use lazyMap to transform the list when necessary
63+
fun listTransactions(
64+
wallet: WalletID,
65+
pageSize: Int = 100,
66+
): List<TransactionSnapshot>
67+
68+
fun getTransaction(id: UUID): TransactionSnapshot?
69+
70+
fun getFrontend(): KristPayFrontend
71+
72+
@Internal
73+
fun cleanup()
74+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
/*
2+
* Copyright (c) 2024 tmpim All rights reserved.
3+
* Use of this source code is governed by a BSD-style
4+
* license that can be found in the LICENSE file.
5+
*/
6+
7+
package io.sc3.kristpay.api
8+
9+
abstract class KristPayConsumer {
10+
protected val API: KristPayAPI by lazy { KristPayProvider.get() }
11+
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
/*
2+
* Copyright (c) 2024 tmpim All rights reserved.
3+
* Use of this source code is governed by a BSD-style
4+
* license that can be found in the LICENSE file.
5+
*/
6+
7+
package io.sc3.kristpay.api
8+
9+
import io.sc3.kristpay.api.model.MonetaryAmount
10+
import io.sc3.kristpay.api.model.NotificationSnapshot
11+
import io.sc3.kristpay.api.model.PaymentResult
12+
import io.sc3.kristpay.api.model.ServicePaymentRequest
13+
import io.sc3.kristpay.api.model.frontend.PaymentRequestResponse
14+
15+
interface KristPayFrontend {
16+
17+
suspend fun presentPaymentRequest(request: ServicePaymentRequest): PaymentRequestResponse
18+
19+
fun presentNotification(notification: NotificationSnapshot): Boolean
20+
21+
fun sendBalance(user: UserID, amount: MonetaryAmount)
22+
23+
fun notifyServicePaymentSuccess(request: ServicePaymentRequest, response: PaymentRequestResponse)
24+
fun notifyServicePaymentFailure(result: PaymentResult, request: ServicePaymentRequest, response: PaymentRequestResponse)
25+
}
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
/*
2+
* Copyright (c) 2024 tmpim All rights reserved.
3+
* Use of this source code is governed by a BSD-style
4+
* license that can be found in the LICENSE file.
5+
*/
6+
7+
package io.sc3.kristpay.api
8+
9+
import org.jetbrains.annotations.ApiStatus.Internal
10+
11+
object KristPayProvider {
12+
private var instance: KristPayAPI? = null
13+
14+
fun get() = instance ?: throw NotLoadedException
15+
16+
@Internal
17+
fun register(kristPay: KristPayAPI) {
18+
instance = kristPay
19+
}
20+
21+
@Internal
22+
fun unregister() {
23+
instance = null
24+
}
25+
26+
private object NotLoadedException : IllegalStateException() {
27+
private const val MESSAGE = "The KristPay API isn't loaded yet!\n" +
28+
"This could be because:\n" +
29+
" a) the KristPay plugin is not installed or it failed to enable\n" +
30+
" b) the plugin in the stacktrace does not declare a dependency on KristPay\n" +
31+
" c) the plugin in the stacktrace is retrieving the API before the plugin 'enable' phase\n" +
32+
" (call the #get method in onEnable, not the constructor!)\n"
33+
}
34+
}
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
/*
2+
* Copyright (c) 2024 tmpim All rights reserved.
3+
* Use of this source code is governed by a BSD-style
4+
* license that can be found in the LICENSE file.
5+
*/
6+
7+
package io.sc3.kristpay.api.model
8+
9+
import java.util.UUID
10+
11+
sealed class Initiator {
12+
data class User(val id: UUID): Initiator()
13+
data class KristAddress(val address: String): Initiator()
14+
data class ServerPlugin(val pluginID: String): Initiator()
15+
object Server: Initiator()
16+
17+
fun serialize(): String {
18+
return when (this) {
19+
is User -> "$UserKey:$id"
20+
is KristAddress -> "$AddressKey:$address"
21+
is ServerPlugin -> "$PluginKey:$pluginID"
22+
is Server -> ServerKey
23+
}
24+
}
25+
26+
companion object {
27+
private const val UserKey = "User"
28+
private const val AddressKey = "Krist"
29+
private const val PluginKey = "Plugin"
30+
private const val ServerKey = "Server"
31+
32+
fun deserialize(record: String): Initiator {
33+
val prefix = record.substringBefore(":")
34+
val value = record.substringAfter(":")
35+
return when (prefix) {
36+
UserKey -> User(UUID.fromString(value))
37+
AddressKey -> KristAddress(value)
38+
PluginKey -> ServerPlugin(value)
39+
ServerKey -> Server
40+
else -> throw IllegalArgumentException("Invalid initiator record: $record")
41+
}
42+
}
43+
}
44+
}

0 commit comments

Comments
 (0)