diff --git a/src/main/java/ca/tweetzy/auctionhouse/impl/currency/EcoBitsCurrency.java b/src/main/java/ca/tweetzy/auctionhouse/impl/currency/EcoBitsCurrency.java new file mode 100644 index 0000000..ec2c57c --- /dev/null +++ b/src/main/java/ca/tweetzy/auctionhouse/impl/currency/EcoBitsCurrency.java @@ -0,0 +1,59 @@ +package ca.tweetzy.auctionhouse.impl.currency; + +import ca.tweetzy.auctionhouse.api.currency.IconableCurrency; +import ca.tweetzy.flight.comp.enums.CompMaterial; +import com.willfp.ecobits.currencies.Currencies; +import com.willfp.ecobits.currencies.Currency; +import com.willfp.ecobits.currencies.CurrencyUtils; +import org.bukkit.OfflinePlayer; + +import java.math.BigDecimal; + +public final class EcoBitsCurrency extends IconableCurrency { + + private final Currency currency; + + public EcoBitsCurrency(String currencyName) { + super("EcoBits", currencyName, "", CompMaterial.PAPER.parseItem()); + this.currency = Currencies.getByID(currencyName.toLowerCase()); + + if (this.currency != null) { + setDisplayName(this.currency.getName()); + } + } + + @Override + public boolean has(OfflinePlayer player, double amount) { + if (this.currency == null) + return false; + + return CurrencyUtils.getBalance(player, currency).doubleValue() >= amount; + } + + @Override + public boolean withdraw(OfflinePlayer player, double amount) { + if (this.currency == null) + return false; + + CurrencyUtils.setBalance(player, currency, BigDecimal.valueOf(CurrencyUtils.getBalance(player, currency).doubleValue() - amount)); + return true; + } + + @Override + public boolean deposit(OfflinePlayer player, double amount) { + if (this.currency == null) + return false; + + CurrencyUtils.setBalance(player, currency, BigDecimal.valueOf(CurrencyUtils.getBalance(player, currency).doubleValue() + amount)); + return true; + } + + @Override + public double getBalance(OfflinePlayer player) { + if (this.currency == null) + return 0; + + return CurrencyUtils.getBalance(player, currency).doubleValue(); + } +} + diff --git a/src/main/java/ca/tweetzy/auctionhouse/model/currency/EcoBitsEconomyLoader.java b/src/main/java/ca/tweetzy/auctionhouse/model/currency/EcoBitsEconomyLoader.java new file mode 100644 index 0000000..11890ed --- /dev/null +++ b/src/main/java/ca/tweetzy/auctionhouse/model/currency/EcoBitsEconomyLoader.java @@ -0,0 +1,43 @@ +package ca.tweetzy.auctionhouse.model.currency; + +import ca.tweetzy.auctionhouse.api.currency.AbstractCurrency; +import ca.tweetzy.auctionhouse.impl.currency.EcoBitsCurrency; +import ca.tweetzy.auctionhouse.settings.Settings; +import com.willfp.ecobits.currencies.Currencies; +import com.willfp.ecobits.currencies.Currency; + +import java.util.ArrayList; +import java.util.List; + +public final class EcoBitsEconomyLoader extends CurrencyLoader { + + public EcoBitsEconomyLoader() { + super("EcoBits"); + } + + + @Override + public List getCurrencies() { + final List currencies = new ArrayList<>(); + + for (Currency currency : Currencies.values()) { + boolean blackListed = false; + + for (String blacklisted : Settings.CURRENCY_BLACKLISTED.getStringList()) { + final String[] blacklistSplit = blacklisted.split(":"); + + if (blacklistSplit.length != 2) continue; + if (!blacklistSplit[0].equalsIgnoreCase(this.owningPlugin)) continue; + + if (blacklistSplit[1].equalsIgnoreCase(currency.getName())) + blackListed = true; + + } + + if (!blackListed) + currencies.add(new EcoBitsCurrency(currency.getId())); + } + + return currencies; + } +} diff --git a/src/main/java/ca/tweetzy/auctionhouse/model/manager/CurrencyManager.java b/src/main/java/ca/tweetzy/auctionhouse/model/manager/CurrencyManager.java index fbbdcd0..6c95e19 100644 --- a/src/main/java/ca/tweetzy/auctionhouse/model/manager/CurrencyManager.java +++ b/src/main/java/ca/tweetzy/auctionhouse/model/manager/CurrencyManager.java @@ -5,6 +5,7 @@ import ca.tweetzy.auctionhouse.api.currency.AbstractCurrency; import ca.tweetzy.auctionhouse.api.manager.ListManager; import ca.tweetzy.auctionhouse.impl.currency.ItemCurrency; import ca.tweetzy.auctionhouse.impl.currency.VaultCurrency; +import ca.tweetzy.auctionhouse.model.currency.EcoBitsEconomyLoader; import ca.tweetzy.auctionhouse.model.currency.FundsEconomyLoader; import ca.tweetzy.auctionhouse.model.currency.UltraEconomyLoader; import ca.tweetzy.auctionhouse.settings.Settings; @@ -123,5 +124,8 @@ public final class CurrencyManager extends ListManager { if (Bukkit.getServer().getPluginManager().isPluginEnabled("Funds")) new FundsEconomyLoader().getCurrencies().forEach(this::add); + + if (Bukkit.getServer().getPluginManager().isPluginEnabled("EcoBits")) + new EcoBitsEconomyLoader().getCurrencies().forEach(this::add); } } diff --git a/src/main/resources/plugin.yml b/src/main/resources/plugin.yml index 0c473f5..be764ea 100644 --- a/src/main/resources/plugin.yml +++ b/src/main/resources/plugin.yml @@ -3,6 +3,6 @@ version: maven-version-number api-version: 1.13 main: ca.tweetzy.auctionhouse.AuctionHouse description: Auction House is a premium auction solution for your server. -website: https://tweetzy.ca/ +website: https://discord.tweetzy.ca/ authors: [ Kiran Hart ] -softdepend: [ Vault, PlayerPoints, PlaceholderAPI, MMOItemsHook, UltraEconomy, CMI, Essentials, ChestShop, EcoEnchants ] +softdepend: [ Vault, PlayerPoints, PlaceholderAPI, MMOItemsHook, UltraEconomy, CMI, Essentials, ChestShop, EcoEnchants, EcoBits, Funds ]