Skip to content

Commit b823410

Browse files
authored
Merge pull request #5 from DragosGhinea/main
Added RoyaleEconomy support
2 parents 05f7fa4 + 90deadc commit b823410

File tree

5 files changed

+58
-15
lines changed

5 files changed

+58
-15
lines changed

build.gradle

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ dependencies {
4040
compileOnly files('libs/zEssentialsAPI-1.0.1.4.jar')
4141
compileOnly files('libs/CoinsEngine-2.4.2.jar')
4242
compileOnly files('libs/nightcore-2.7.1.jar')
43+
compileOnly files('libs/RoyaleEconomyAPI.jar')
4344
}
4445
def targetJavaVersion = 8
4546
java {
@@ -74,6 +75,7 @@ build.dependsOn generateVersionProperties
7475
java {
7576
withSourcesJar()
7677
withJavadocJar()
78+
7779
}
7880

7981
publishing {

libs/RoyaleEconomyAPI.jar

139 KB
Binary file not shown.

readme.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ The `Currencies` enum allows easy management of various in-game currencies like
2222
- [CoinsEngine](https://www.spigotmc.org/resources/84121/) - `COINSENGINE`
2323
- [VotingPlugin](https://www.spigotmc.org/resources/15358/) - `VOTINGPLUGIN`
2424
- [RedisEconomy](https://www.spigotmc.org/resources/105965/) - `REDISECONOMY`
25+
- [RoyaleEconomy](https://polymart.org/product/113/royaleeconomy-1-8-1-21) - `ROYALEECONOMY`
2526

2627
Each of these providers is implemented through a specific class extending `CurrencyProvider`.
2728

src/main/java/fr/traqueur/currencies/Currencies.java

Lines changed: 6 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,6 @@
11
package fr.traqueur.currencies;
22

3-
import fr.traqueur.currencies.providers.BeastTokenProvider;
4-
import fr.traqueur.currencies.providers.CoinsEngineProvider;
5-
import fr.traqueur.currencies.providers.EcoBitProvider;
6-
import fr.traqueur.currencies.providers.ElementalGemsProvider;
7-
import fr.traqueur.currencies.providers.ElementalTokensProvider;
8-
import fr.traqueur.currencies.providers.ExperienceProvider;
9-
import fr.traqueur.currencies.providers.ItemProvider;
10-
import fr.traqueur.currencies.providers.LevelProvider;
11-
import fr.traqueur.currencies.providers.PlayerPointsProvider;
12-
import fr.traqueur.currencies.providers.RedisEconomyProvider;
13-
import fr.traqueur.currencies.providers.VaultProvider;
14-
import fr.traqueur.currencies.providers.VotingProvider;
15-
import fr.traqueur.currencies.providers.ZEssentialsProvider;
16-
import fr.traqueur.currencies.providers.ZMenuItemProvider;
3+
import fr.traqueur.currencies.providers.*;
174
import org.bukkit.Bukkit;
185
import org.bukkit.OfflinePlayer;
196

@@ -84,7 +71,11 @@ public enum Currencies {
8471
/**
8572
* The currency RedisEconomy from the plugin RedisEconomy.
8673
*/
87-
REDISECONOMY("RedisEconomy", RedisEconomyProvider.class, true, true);
74+
REDISECONOMY("RedisEconomy", RedisEconomyProvider.class, true, true),
75+
/**
76+
* The currency RoyaleEconomy from the plugin RoyaleEconomy.
77+
*/
78+
ROYALEECONOMY("RoyaleEconomy", RoyaleEconomyProvider.class, true, true);
8879

8980
static {
9081
Updater.checkUpdates();
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
package fr.traqueur.currencies.providers;
2+
3+
import fr.traqueur.currencies.CurrencyProvider;
4+
import me.qKing12.RoyaleEconomy.API.Currency;
5+
import me.qKing12.RoyaleEconomy.API.MultiCurrencyHandler;
6+
import org.bukkit.OfflinePlayer;
7+
8+
import java.math.BigDecimal;
9+
10+
public class RoyaleEconomyProvider implements CurrencyProvider {
11+
12+
private Currency currency;
13+
private final String currencyId;
14+
15+
public RoyaleEconomyProvider(String currencyId) {
16+
this.currencyId = currencyId;
17+
}
18+
19+
@SuppressWarnings("ConstantConditions") // findCurrencyById always returns null in the API only
20+
private void initialize() {
21+
if (currency != null)
22+
return;
23+
24+
if (MultiCurrencyHandler.getCurrencies() == null)
25+
throw new NullPointerException("RoyaleEconomy multi-currency not enabled.");
26+
27+
currency = MultiCurrencyHandler.findCurrencyById(currencyId);
28+
if (currency == null)
29+
throw new NullPointerException("RoyaleEconomy currency " + currencyId + " not found");
30+
}
31+
32+
@Override
33+
public void deposit(OfflinePlayer offlinePlayer, BigDecimal amount, String reason) {
34+
initialize();
35+
currency.addAmount(offlinePlayer.getUniqueId().toString(), amount.doubleValue());
36+
}
37+
38+
@Override
39+
public void withdraw(OfflinePlayer offlinePlayer, BigDecimal amount, String reason) {
40+
initialize();
41+
currency.removeAmount(offlinePlayer.getUniqueId().toString(), amount.doubleValue());
42+
}
43+
44+
@Override
45+
public BigDecimal getBalance(OfflinePlayer offlinePlayer) {
46+
initialize();
47+
return BigDecimal.valueOf(currency.getAmount(offlinePlayer.getUniqueId().toString()));
48+
}
49+
}

0 commit comments

Comments
 (0)