Skip to content

Commit

Permalink
feat: coins engine currency
Browse files Browse the repository at this point in the history
  • Loading branch information
ProdPreva1l committed Oct 24, 2024
1 parent f78433c commit 97e4dcd
Show file tree
Hide file tree
Showing 7 changed files with 78 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ public final class CurrencyRegistry {
private static Map<Integer, String> enumerator = new ConcurrentHashMap<>();
private static Map<String, Currency> values = new ConcurrentHashMap<>();
public static final Currency VAULT = get("vault");
public static final Currency REDIS_ECONOMY = get("redis_economy");

public static void registerMulti(MultiCurrency currency) {
if (!currency.getRequiredPlugin().isEmpty()) {
Expand Down
1 change: 1 addition & 0 deletions Bukkit/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ dependencies {
compileOnly 'com.influxdb:influxdb-client-java:3.3.0' // InfluxDB logging
// Currency
compileOnly 'com.github.Emibergo02:RedisEconomy:4.3.9'
compileOnly files('../libs/CoinsEngine-2.3.5.jar')

// Migrators
compileOnly 'com.github.Maxlego08:zAuctionHouseV3-API:3.2.1.9' // zAuctionHouse
Expand Down
4 changes: 3 additions & 1 deletion Bukkit/src/main/java/info/preva1l/fadah/Fadah.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import info.preva1l.fadah.config.Config;
import info.preva1l.fadah.config.Lang;
import info.preva1l.fadah.config.Menus;
import info.preva1l.fadah.currency.CoinsEngineCurrency;
import info.preva1l.fadah.currency.CurrencyRegistry;
import info.preva1l.fadah.currency.RedisEconomyCurrency;
import info.preva1l.fadah.currency.VaultCurrency;
Expand Down Expand Up @@ -260,7 +261,8 @@ private void loadCurrencies() {
new VaultCurrency()
).forEach(CurrencyRegistry::register);
Stream.of(
new RedisEconomyCurrency()
new RedisEconomyCurrency(),
new CoinsEngineCurrency()
).forEach(CurrencyRegistry::registerMulti);
getConsole().info("Currencies Loaded!");
}
Expand Down
15 changes: 14 additions & 1 deletion Bukkit/src/main/java/info/preva1l/fadah/config/Config.java
Original file line number Diff line number Diff line change
Expand Up @@ -139,14 +139,27 @@ public static class Vault {
private String name = "Money";
}

private CoinsEngine coinsEngine = new CoinsEngine();

@Getter
@Configuration
@NoArgsConstructor(access = AccessLevel.PRIVATE)
public static class CoinsEngine {
private String name = "Coins Engine";
@Comment("Which currencies to use from coins engine.")
private List<SubEconomy> currencies = List.of(
new SubEconomy("mob_coins", "Mob Coins"),
new SubEconomy("coins", "Coins"));
}

private RedisEconomy redisEconomy = new RedisEconomy();

@Getter
@Configuration
@NoArgsConstructor(access = AccessLevel.PRIVATE)
public static class RedisEconomy {
private String name = "Redis Economy";
@Comment("Which currency to use from redis economy, if your using the default currency use the vault currency instead.")
@Comment("Which currencies to use from redis economy, if your using the default currency use the vault currency instead.")
private List<SubEconomy> currencies = List.of(
new SubEconomy("dollar", "Dollar"),
new SubEconomy("euro", "Euro"));
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
package info.preva1l.fadah.currency;

import info.preva1l.fadah.Fadah;
import info.preva1l.fadah.config.Config;
import info.preva1l.fadah.config.SubEconomy;
import lombok.Getter;
import org.bukkit.OfflinePlayer;
import su.nightexpress.coinsengine.api.CoinsEngineAPI;

import java.util.ArrayList;
import java.util.List;

@Getter
public class CoinsEngineCurrency implements MultiCurrency {
private final String id = "coins_engine";
private final String name = "Coins Engine";
private final String requiredPlugin = "CoinsEngine";
private final List<Currency> currencies = new ArrayList<>();

@Override
public boolean preloadChecks() {
for (SubEconomy eco : Config.i().getCurrency().getCoinsEngine().getCurrencies()) {
Currency subCur = new SubCurrency(id + "_" + eco.economy(), eco.displayName(), requiredPlugin) {
@Override
public void withdraw(OfflinePlayer player, double amountToTake) {
CoinsEngineAPI.addBalance(player.getUniqueId(), getCurrency(), amountToTake);
}

@Override
public void add(OfflinePlayer player, double amountToAdd) {
CoinsEngineAPI.addBalance(player.getUniqueId(), getCurrency(), amountToAdd);
}

@Override
public double getBalance(OfflinePlayer player) {
return CoinsEngineAPI.getBalance(player.getUniqueId(), getCurrency());
}

private su.nightexpress.coinsengine.api.currency.Currency getCurrency() {
return CoinsEngineAPI.getCurrency(eco.economy());
}

@Override
public boolean preloadChecks() {
if (getCurrency() == null) {
Fadah.getConsole().severe("-------------------------------------");
Fadah.getConsole().severe("Cannot enable coins engine currency!");
Fadah.getConsole().severe("No currency with name: " + eco.economy());
Fadah.getConsole().severe("-------------------------------------");
return false;
}
return true;
}
};
currencies.add(subCur);
}
return true;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public boolean preloadChecks() {
return false;
}
for (SubEconomy eco : Config.i().getCurrency().getRedisEconomy().getCurrencies()) {
Currency subCur = new SubCurrency(eco.economy(), eco.displayName(), requiredPlugin) {
Currency subCur = new SubCurrency(id + "_" + eco.economy(), eco.displayName(), requiredPlugin) {
private final RedisEconomyAPI api = getApi();

@Override
Expand Down
Binary file added libs/CoinsEngine-2.3.5.jar
Binary file not shown.

0 comments on commit 97e4dcd

Please sign in to comment.