diff --git a/build.gradle.kts b/build.gradle.kts index 9014b4d..beb9c72 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -30,6 +30,14 @@ repositories { url = uri("https://nexus.bencodez.com/repository/maven-public/") name = "BenCodez Repo" } + maven { + url = uri("https://repo.auxilor.io/repository/maven-public/") + name = "Auxilor Repo" + } + maven { + url = uri("https://repo.nightexpressdev.com/releases") + name = "night-releases" + } } dependencies { @@ -40,6 +48,7 @@ dependencies { compileOnly("com.willfp:EcoBits:1.8.4") compileOnly("com.bencodez:votingplugin:6.17.2") compileOnly("com.github.Emibergo02:RedisEconomy:4.3.19") + compileOnly("su.nightexpress.coinsengine:CoinsEngine:2.7.0") compileOnly("fr.maxlego08.menu:zmenu-api:1.1.0.6") diff --git a/gradle.properties b/gradle.properties index 16d78b6..3e862dc 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1 +1 @@ -version=1.0.11 \ No newline at end of file +version=1.0.12 \ No newline at end of file diff --git a/readme.md b/readme.md index dfadfd5..b0c91bf 100644 --- a/readme.md +++ b/readme.md @@ -20,6 +20,7 @@ The `Currencies` enum allows easy management of various in-game currencies like - [zMenu](https://www.spigotmc.org/resources/110402/) - `ZMENUITEMS` - [EcoBits](https://www.spigotmc.org/resources/109967/) - `ECOBITS` - [CoinsEngine](https://www.spigotmc.org/resources/84121/) - `COINSENGINE` +- [ExcellentEconomy](https://modrinth.com/plugin/excellenteconomy) - `EXCELLENTEECONOMY` - [VotingPlugin](https://www.spigotmc.org/resources/15358/) - `VOTINGPLUGIN` - [RedisEconomy](https://www.spigotmc.org/resources/105965/) - `REDISECONOMY` - [RoyaleEconomy](https://polymart.org/product/113/royaleeconomy-1-8-1-21) - `ROYALEECONOMY` @@ -46,7 +47,7 @@ To add the Currencies API to your project using Maven, add the following to your fr.traqueur.currencies currenciesapi - 1.0.11 + 1.0.12 ``` @@ -63,7 +64,7 @@ repositories { } dependencies { - implementation("fr.traqueur.currencies:currenciesapi:1.0.11") + implementation("fr.traqueur.currencies:currenciesapi:1.0.12") } ``` diff --git a/src/main/java/fr/traqueur/currencies/Currencies.java b/src/main/java/fr/traqueur/currencies/Currencies.java index 6d0691d..a848970 100644 --- a/src/main/java/fr/traqueur/currencies/Currencies.java +++ b/src/main/java/fr/traqueur/currencies/Currencies.java @@ -1,20 +1,6 @@ package fr.traqueur.currencies; -import fr.traqueur.currencies.providers.BeastTokenProvider; -import fr.traqueur.currencies.providers.CoinsEngineProvider; -import fr.traqueur.currencies.providers.EcoBitProvider; -import fr.traqueur.currencies.providers.ElementalGemsProvider; -import fr.traqueur.currencies.providers.ElementalTokensProvider; -import fr.traqueur.currencies.providers.ExperienceProvider; -import fr.traqueur.currencies.providers.ItemProvider; -import fr.traqueur.currencies.providers.LevelProvider; -import fr.traqueur.currencies.providers.PlayerPointsProvider; -import fr.traqueur.currencies.providers.RedisEconomyProvider; -import fr.traqueur.currencies.providers.RoyaleEconomyProvider; -import fr.traqueur.currencies.providers.VaultProvider; -import fr.traqueur.currencies.providers.VotingProvider; -import fr.traqueur.currencies.providers.ZEssentialsProvider; -import fr.traqueur.currencies.providers.ZMenuItemProvider; +import fr.traqueur.currencies.providers.*; import org.bukkit.Bukkit; import org.bukkit.OfflinePlayer; @@ -90,7 +76,12 @@ public enum Currencies { /** * The currency RoyaleEconomy from the plugin RoyaleEconomy. */ - ROYALEECONOMY("RoyaleEconomy", RoyaleEconomyProvider.class, true, true); + ROYALEECONOMY("RoyaleEconomy", RoyaleEconomyProvider.class, true, true), + /** + * The currency ExcellentEconomy from the plugin ExcellentEconomy (new name for CraftEngine) + */ + EXCELLENTEECONOMY("ExcellentEconomy", ExcellentEconomyProvider.class, true, true) + ; static { Updater.checkUpdates(); diff --git a/src/main/java/fr/traqueur/currencies/providers/ExcellentEconomyProvider.java b/src/main/java/fr/traqueur/currencies/providers/ExcellentEconomyProvider.java new file mode 100644 index 0000000..a40e9a0 --- /dev/null +++ b/src/main/java/fr/traqueur/currencies/providers/ExcellentEconomyProvider.java @@ -0,0 +1,61 @@ +package fr.traqueur.currencies.providers; + +import fr.traqueur.currencies.CurrencyProvider; +import org.bukkit.Bukkit; +import org.bukkit.OfflinePlayer; +import org.bukkit.entity.Player; +import org.bukkit.plugin.RegisteredServiceProvider; +import su.nightexpress.excellenteconomy.api.ExcellentEconomyAPI; +import su.nightexpress.excellenteconomy.api.currency.operation.OperationContext; + +import java.math.BigDecimal; + +public class ExcellentEconomyProvider implements CurrencyProvider { + private final ExcellentEconomyAPI api; + private final String currencyName; + + public ExcellentEconomyProvider(String currencyName) { + this.currencyName = currencyName; + RegisteredServiceProvider provider = Bukkit.getServer().getServicesManager().getRegistration(ExcellentEconomyAPI.class); + if (provider == null) { + throw new IllegalStateException("ExcellentEconomy service not registered"); + } + this.api = provider.getProvider(); + } + + @Override + public void deposit(OfflinePlayer player, BigDecimal amount, String reason) { + OperationContext ctx = OperationContext.custom(reason); + if (isOnline(player)) { + this.api.deposit(asOnline(player), this.currencyName, amount.doubleValue(), ctx); + } else { + this.api.depositAsync(player.getUniqueId(), this.currencyName, amount.doubleValue(), ctx); + } + } + + @Override + public void withdraw(OfflinePlayer player, BigDecimal amount, String reason) { + OperationContext ctx = OperationContext.custom(reason); + if (isOnline(player)) { + this.api.withdraw(asOnline(player), this.currencyName, amount.doubleValue(), ctx); + } else { + this.api.withdrawAsync(player.getUniqueId(), this.currencyName, amount.doubleValue(), ctx); + } + } + + @Override + public BigDecimal getBalance(OfflinePlayer player) { + double raw = isOnline(player) + ? this.api.getBalance(asOnline(player), this.currencyName) + : this.api.getBalanceAsync(player.getUniqueId(), this.currencyName).join(); + return BigDecimal.valueOf(raw); + } + + private boolean isOnline(OfflinePlayer player) { + return player instanceof Player; + } + + private Player asOnline(OfflinePlayer player) { + return (Player) player; + } +} \ No newline at end of file diff --git a/src/main/resources/currenciesapi.properties b/src/main/resources/currenciesapi.properties index 16d78b6..3e862dc 100644 --- a/src/main/resources/currenciesapi.properties +++ b/src/main/resources/currenciesapi.properties @@ -1 +1 @@ -version=1.0.11 \ No newline at end of file +version=1.0.12 \ No newline at end of file