Skip to content

Commit 4419710

Browse files
committed
feat: initial works for economy api
1 parent 21f5bee commit 4419710

File tree

14 files changed

+566
-64
lines changed

14 files changed

+566
-64
lines changed

.github/workflows/gradle.yml

Lines changed: 27 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -5,35 +5,50 @@ on:
55
branches: [ "master" ]
66
paths:
77
- .github/workflows/gradle.yml
8+
- gradle.properties
9+
- build.gradle.kts
810
- src/**
911
pull_request:
1012
paths:
1113
- .github/workflows/gradle.yml
14+
- gradle.properties
15+
- build.gradle.kts
1216
- src/**
1317

1418
jobs:
15-
build:
19+
publish:
1620
runs-on: ubuntu-latest
21+
timeout-minutes: 10
1722
steps:
18-
- uses: actions/checkout@v4
19-
- run: chmod +x gradlew
20-
- uses: actions/setup-java@v4
23+
- name: Checkout
24+
uses: actions/checkout@v5
25+
26+
- name: Setup Java
27+
uses: actions/setup-java@v5
2128
with:
2229
java-version: '21'
2330
distribution: 'zulu'
24-
- name: Setup gradle
25-
uses: gradle/actions/setup-gradle@v4
31+
32+
- name: Setup Gradle
33+
uses: gradle/actions/setup-gradle@v5
2634
with:
2735
gradle-version: wrapper
2836
cache-overwrite-existing: true
2937
cache-read-only: false
3038
build-scan-publish: true
3139
build-scan-terms-of-use-url: "https://gradle.com/terms-of-service"
3240
build-scan-terms-of-use-agree: "yes"
41+
3342
- name: Build
34-
run: ./gradlew shadowJar
35-
- name: Upload Artifact
36-
uses: actions/upload-artifact@v4
37-
if: success() && contains(github.ref_name, 'master')
38-
with:
39-
path: build/libs/*.jar
43+
run: |
44+
chmod +x gradlew
45+
./gradlew build
46+
47+
- name: Publish to Maven Central
48+
if: success() && github.event_name == 'push' && github.repository == 'AllayMC/EconomyAPI' && contains(github.ref_name, 'master')
49+
run: ./gradlew publishToMavenCentral
50+
env:
51+
ORG_GRADLE_PROJECT_mavenCentralUsername: ${{ secrets.SONATYPE_USERNAME }}
52+
ORG_GRADLE_PROJECT_mavenCentralPassword: ${{ secrets.SONATYPE_PASSWORD }}
53+
ORG_GRADLE_PROJECT_signingInMemoryKey: ${{ secrets.SONATYPE_SECRET_KEY }}
54+
ORG_GRADLE_PROJECT_signingInMemoryKeyPassword: ${{ secrets.SONATYPE_SECRET_KEY_PASSWORD }}

README.md

Lines changed: 64 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,56 +1,112 @@
1-
# Allay Java Plugin Template
1+
# EconomyAPI
22

3-
Welcome to the java plugin template for allay.
3+
![Maven Central Version](https://img.shields.io/maven-central/v/org.allaymc/economyapi?label=economyapi)
44

5-
## Prerequisites
5+
EconomyAPI is a plugin that unifies all economy plugins under one single API. The API can be used by both economy plugins
6+
providing the API, and other plugins using the API (i.e. shop plugins). This allows for all plugins that require an economy
7+
to work with any economy plugin.
8+
9+
## Usages
10+
11+
```kts
12+
repositories {
13+
mavenCentral()
14+
}
15+
16+
dependencies {
17+
compileOnly(group = "org.allaymc", name = "economyapi", version = "0.1.0")
18+
}
19+
```
20+
21+
WIP
22+
23+
## Install
24+
25+
26+
- Download .jar file from [release](https://github.com/AllayMC/PlaceholderAPI/releases) or [action](https://github.com/AllayMC/PlaceholderAPI/actions/workflows/gradle.yml)
27+
28+
- Put it into `plugins` folder
29+
30+
- Restart the server, enjoy!
631

7-
- Java21 or higher.
8-
- Allay installed.
932

1033
## Getting Started
1134

35+
1236
1. **Clone this Repository**
1337

38+
1439
```bash
40+
1541
git clone https://github.com/AllayMC/JavaPluginTemplate.git
42+
1643
```
44+
1745

1846
2. **Navigate to the Cloned Directory**
1947

48+
2049
```bash
50+
2151
cd JavaPluginTemplate
52+
2253
```
54+
2355

2456
3. **Change Plugin Information**
2557

58+
2659
- Rename package name from `org.allaymc.javaplugintemplate` to `your.group.name.and.pluginname`
60+
2761
- Update [build.gradle.kts](build.gradle.kts) and [settings.gradle.kts](settings.gradle.kts)
62+
2863
- Reload gradle
64+
2965

3066
4. **Build and Run Your Plugin**
3167

68+
3269
```bash
70+
3371
gradlew shadowJar
72+
3473
```
74+
3575

3676
This command will produce a `.jar` file in the `build/libs` directory.
77+
3778
Copy the `.jar` file to the `plugins` directory of your allay server.
79+
3880
Start the allay server and check the logs to ensure your plugin loads and operates
81+
3982
as expected.
4083

84+
4185
5. **Test Your Plugin in Gradle**
4286

87+
4388
```bash
89+
4490
gradlew runServer
91+
4592
```
4693

94+
4795
This command will start an allay server with your plugin loaded.
96+
4897
Then close allay server by clicking `X` in the dashboard window.
4998

50-
## Documentation
99+
## Requirement
100+
101+
Java: 21+
102+
103+
Allay: 0.17.0+
104+
105+
## Contributing
51106

52-
For a deeper dive into the Allay API and its functionalities, please refer to our [documentation](https://docs.allaymc.org) (WIP).
107+
Contributions are welcome! Feel free to fork the repository, improve the code, and submit pull requests with your
108+
changes.
53109

54110
## License
55111

56-
This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.
112+
This project is licensed under the LGPL v3 License - see the [LICENSE](LICENSE) file for details.

build.gradle.kts

Lines changed: 72 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,89 @@
1+
import com.vanniktech.maven.publish.MavenPublishBaseExtension
2+
13
plugins {
24
id("java-library")
5+
id("com.vanniktech.maven.publish") version "0.34.0"
36
id("org.allaymc.gradle.plugin") version "0.1.2"
47
}
58

6-
// TODO: Update the group to yours (should be same to the package of the plugin main class)
7-
group = "org.allaymc.javaplugintemplate"
8-
// TODO: Update the description to yours
9-
description = "Java plugin template for allay server"
10-
version = "0.1.0"
11-
12-
java {
13-
toolchain {
14-
languageVersion = JavaLanguageVersion.of(21)
15-
}
16-
}
9+
group = "org.allaymc"
10+
version = "0.1.0-SNAPSHOT"
11+
description = "EconomyAPI is a plugin that unifies all economy plugins under one single API"
1712

18-
// See also https://github.com/AllayMC/AllayGradle
1913
allay {
20-
// TODO: Update the api version to the latest
21-
// You can find the latest version here: https://central.sonatype.com/artifact/org.allaymc.allay/api
2214
api = "0.17.0"
2315

2416
plugin {
25-
// TODO: Update the entrance when you change your plugin main class
26-
// Same to `org.allaymc.javaplugintemplate.JavaPluginTemplate`
27-
entrance = ".JavaPluginTemplate"
28-
// TODO: Use your handsome name here
29-
authors += "YourNameHere"
30-
// TODO: Update the website to yours
31-
website = "https://github.com/AllayMC/JavaPluginTemplate"
17+
entrance = "org.allaymc.economyapi.Entrance"
18+
authors += "daoge_cmd"
19+
website = "https://github.com/AllayMC/EconomyAPI"
3220
}
3321
}
3422

3523
dependencies {
3624
compileOnly(group = "org.projectlombok", name = "lombok", version = "1.18.34")
3725
annotationProcessor(group = "org.projectlombok", name = "lombok", version = "1.18.34")
3826
}
27+
28+
tasks {
29+
withType<JavaCompile> {
30+
options.encoding = "UTF-8"
31+
configureEach {
32+
options.isFork = true
33+
}
34+
}
35+
36+
// We already have sources jar, so no need to build Javadoc, which would cause a lot of warnings
37+
withType<Javadoc> {
38+
enabled = false
39+
}
40+
41+
withType<Copy> {
42+
duplicatesStrategy = DuplicatesStrategy.EXCLUDE
43+
}
44+
}
45+
46+
java {
47+
toolchain {
48+
languageVersion = JavaLanguageVersion.of(21)
49+
}
50+
}
51+
52+
repositories {
53+
mavenCentral()
54+
}
55+
56+
configure<MavenPublishBaseExtension> {
57+
publishToMavenCentral()
58+
signAllPublications()
59+
60+
coordinates(project.group.toString(), project.name, project.version.toString())
61+
62+
pom {
63+
name.set(project.name)
64+
description.set("EconomyAPI is a plugin that unifies all economy plugins under one single API")
65+
inceptionYear.set("2025")
66+
url.set("https://github.com/AllayMC/EconomyAPI")
67+
68+
scm {
69+
connection.set("scm:git:git://github.com/AllayMC/EconomyAPI.git")
70+
developerConnection.set("scm:git:ssh://github.com/AllayMC/EconomyAPI.git")
71+
url.set("https://github.com/AllayMC/EconomyAPI")
72+
}
73+
74+
licenses {
75+
license {
76+
name.set("LGPL 3.0")
77+
url.set("https://www.gnu.org/licenses/lgpl-3.0.en.html")
78+
}
79+
}
80+
81+
developers {
82+
developer {
83+
name.set("AllayMC Team")
84+
organization.set("AllayMC")
85+
organizationUrl.set("https://github.com/AllayMC")
86+
}
87+
}
88+
}
89+
}

settings.gradle.kts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
rootProject.name = "JavaPluginTemplate"
1+
rootProject.name = "EconomyAPI"
22

Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
package org.allaymc.economyapi;
2+
3+
import org.allaymc.economyapi.event.BalanceChangeEvent;
4+
import org.allaymc.economyapi.event.BalanceTransferEvent;
5+
import org.jetbrains.annotations.Unmodifiable;
6+
7+
import java.math.BigDecimal;
8+
import java.util.Map;
9+
import java.util.UUID;
10+
11+
/**
12+
* Represents an account, which stores amounts of various {@link Currency currencies}.
13+
* <p>
14+
* Every account is bound to a {@link UUID}, it usually should be same to the player's
15+
* uuid if the account belongs to a player, or a random uuid in other cases.
16+
*
17+
* @author daoge_cmd
18+
*/
19+
public interface Account {
20+
21+
/**
22+
* Gets the unique id of this account.
23+
*
24+
* @return the unique id of this account
25+
*/
26+
UUID getUniqueId();
27+
28+
/**
29+
* Gets the name of this account.
30+
*
31+
* @return the name of this account
32+
*/
33+
String getName();
34+
35+
/**
36+
* Gets a {@link BigDecimal} representative of the balance for the given {@link Currency}.
37+
*
38+
* @param currency the currency to get the balance for
39+
* @return the balance of the currency
40+
*/
41+
BigDecimal getBalance(Currency currency);
42+
43+
/**
44+
* Retrieves an unmodifiable map of all balances associated with this account. Each entry
45+
* in the map represents a {@link Currency} and its corresponding balance as a {@link BigDecimal}.
46+
*
47+
* @return an unmodifiable map containing currencies as keys and their respective balances as values
48+
*/
49+
@Unmodifiable
50+
Map<Currency, BigDecimal> getBalances();
51+
52+
/**
53+
* Sets the balance for the given currency to the specified amount. Event {@link BalanceChangeEvent}
54+
* will be called when this method is called.
55+
*
56+
* @param currency the {@link Currency} for which the balance is being set
57+
* @param amount the {@link BigDecimal} value representing the new balance
58+
* @return {@code true} if the balance was successfully set, otherwise {@code false}
59+
*/
60+
boolean setBalance(Currency currency, BigDecimal amount);
61+
62+
/**
63+
* Deposits a specified amount of the given currency into the account.
64+
* The new balance is calculated by adding the deposit amount to the current balance.
65+
*
66+
* @param currency the {@link Currency} being deposited
67+
* @param amount the {@link BigDecimal} value of the amount to deposit
68+
* @return {@code true} if the new balance was successfully updated, otherwise {@code false}
69+
*/
70+
default boolean deposit(Currency currency, BigDecimal amount) {
71+
return setBalance(currency, getBalance(currency).add(amount));
72+
}
73+
74+
/**
75+
* Withdraws a specified amount of the given currency from the account.
76+
* The new balance is calculated by subtracting the withdrawal amount
77+
* from the current balance.
78+
*
79+
* @param currency the {@link Currency} from which the amount is being withdrawn
80+
* @param amount the {@link BigDecimal} value of the amount to withdraw
81+
* @return {@code true} if the new balance was successfully updated, otherwise {@code false}
82+
*/
83+
default boolean withdraw(Currency currency, BigDecimal amount) {
84+
return setBalance(currency, getBalance(currency).subtract(amount));
85+
}
86+
87+
/**
88+
* Transfers a specified amount of a given currency from this account to another account.
89+
* Event {@link BalanceTransferEvent} will be called when this method is called.
90+
*
91+
* @param to the recipient {@link Account} to which the amount will be transferred
92+
* @param currency the {@link Currency} of the amount being transferred
93+
* @param amount the {@link BigDecimal} value representing the amount to be transferred
94+
* @return {@code true} if the transfer was successful, otherwise {@code false}
95+
*/
96+
boolean transfer(Account to, Currency currency, BigDecimal amount);
97+
}

0 commit comments

Comments
 (0)