From 82ac56badff1103021ff3612592a69e4b00c45c8 Mon Sep 17 00:00:00 2001 From: Kiran Hart Date: Sat, 28 Dec 2024 13:19:33 -0500 Subject: [PATCH] =?UTF-8?q?=E2=9C=A8=20Added=20CoinsEngine=20support=20?= =?UTF-8?q?=E2=9C=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../impl/currency/CoinEngineCurrency.java | 52 +++++++++++++++++++ .../currency/CoinEngineEconomyLoader.java | 42 +++++++++++++++ .../model/manager/CurrencyManager.java | 4 ++ .../auctionhouse/settings/Settings.java | 4 ++ src/main/resources/plugin.yml | 2 +- 5 files changed, 103 insertions(+), 1 deletion(-) create mode 100644 src/main/java/ca/tweetzy/auctionhouse/impl/currency/CoinEngineCurrency.java create mode 100644 src/main/java/ca/tweetzy/auctionhouse/model/currency/CoinEngineEconomyLoader.java diff --git a/src/main/java/ca/tweetzy/auctionhouse/impl/currency/CoinEngineCurrency.java b/src/main/java/ca/tweetzy/auctionhouse/impl/currency/CoinEngineCurrency.java new file mode 100644 index 0000000..fdac75a --- /dev/null +++ b/src/main/java/ca/tweetzy/auctionhouse/impl/currency/CoinEngineCurrency.java @@ -0,0 +1,52 @@ +package ca.tweetzy.auctionhouse.impl.currency; + +import ca.tweetzy.auctionhouse.api.currency.IconableCurrency; +import ca.tweetzy.flight.comp.enums.CompMaterial; +import org.bukkit.OfflinePlayer; +import su.nightexpress.coinsengine.api.CoinsEngineAPI; +import su.nightexpress.coinsengine.api.currency.Currency; + +public final class CoinEngineCurrency extends IconableCurrency { + + private final Currency currency; + + public CoinEngineCurrency(String currencyName) { + super("CoinsEngine", currencyName, "", CompMaterial.PAPER.parseItem()); + this.currency = CoinsEngineAPI.getCurrency(currencyName); + + if (this.currency != null) { + setDisplayName(this.currency.getName()); + setIcon(this.currency.getIcon()); + } + } + + @Override + public boolean has(OfflinePlayer player, double amount) { + if (this.currency == null) + return false; + + return CoinsEngineAPI.getBalance(player.getUniqueId(), this.currency) >= amount; + } + + @Override + public boolean withdraw(OfflinePlayer player, double amount) { + if (this.currency == null) + return false; + + return CoinsEngineAPI.removeBalance(player.getUniqueId(), this.currency, amount); + } + + @Override + public boolean deposit(OfflinePlayer player, double amount) { + if (this.currency == null) + return false; + + return CoinsEngineAPI.addBalance(player.getUniqueId(), this.currency, amount); + } + + @Override + public double getBalance(OfflinePlayer player) { + return CoinsEngineAPI.getBalance(player.getUniqueId(), this.currency); + } +} + diff --git a/src/main/java/ca/tweetzy/auctionhouse/model/currency/CoinEngineEconomyLoader.java b/src/main/java/ca/tweetzy/auctionhouse/model/currency/CoinEngineEconomyLoader.java new file mode 100644 index 0000000..24cc476 --- /dev/null +++ b/src/main/java/ca/tweetzy/auctionhouse/model/currency/CoinEngineEconomyLoader.java @@ -0,0 +1,42 @@ +package ca.tweetzy.auctionhouse.model.currency; + +import ca.tweetzy.auctionhouse.api.currency.AbstractCurrency; +import ca.tweetzy.auctionhouse.impl.currency.CoinEngineCurrency; +import ca.tweetzy.auctionhouse.settings.Settings; +import su.nightexpress.coinsengine.api.CoinsEngineAPI; +import su.nightexpress.coinsengine.api.currency.Currency; + +import java.util.ArrayList; +import java.util.List; + +public final class CoinEngineEconomyLoader extends CurrencyLoader { + + public CoinEngineEconomyLoader() { + super("CoinsEngine"); + } + + @Override + public List getCurrencies() { + final List currencies = new ArrayList<>(); + + for (Currency currency : CoinsEngineAPI.getCurrencyManager().getCurrencies()) { + 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.getId())) + blackListed = true; + + } + + if (!blackListed) + currencies.add(new CoinEngineCurrency(currency.getId())); + } + + return currencies; + } +} \ No newline at end of file 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 6747f0b..8010d29 100644 --- a/src/main/java/ca/tweetzy/auctionhouse/model/manager/CurrencyManager.java +++ b/src/main/java/ca/tweetzy/auctionhouse/model/manager/CurrencyManager.java @@ -6,6 +6,7 @@ import ca.tweetzy.auctionhouse.api.manager.ListManager; import ca.tweetzy.auctionhouse.impl.currency.AllCurrency; import ca.tweetzy.auctionhouse.impl.currency.ItemCurrency; import ca.tweetzy.auctionhouse.impl.currency.VaultCurrency; +import ca.tweetzy.auctionhouse.model.currency.CoinEngineEconomyLoader; import ca.tweetzy.auctionhouse.model.currency.EcoBitsEconomyLoader; import ca.tweetzy.auctionhouse.model.currency.FundsEconomyLoader; import ca.tweetzy.auctionhouse.model.currency.UltraEconomyLoader; @@ -154,5 +155,8 @@ public final class CurrencyManager extends ListManager { if (Bukkit.getServer().getPluginManager().isPluginEnabled("EcoBits")) new EcoBitsEconomyLoader().getCurrencies().forEach(this::add); + + if (Bukkit.getServer().getPluginManager().isPluginEnabled("CoinsEngine")) + new CoinEngineEconomyLoader().getCurrencies().forEach(this::add); } } diff --git a/src/main/java/ca/tweetzy/auctionhouse/settings/Settings.java b/src/main/java/ca/tweetzy/auctionhouse/settings/Settings.java index 7006007..fcd1d0d 100644 --- a/src/main/java/ca/tweetzy/auctionhouse/settings/Settings.java +++ b/src/main/java/ca/tweetzy/auctionhouse/settings/Settings.java @@ -97,6 +97,10 @@ public class Settings { public static final ConfigSetting LISTING_PRIORITY_TIME_ALLOW_MULTI_BOOST = new ConfigSetting(config, "auction setting.listing priority.allow multiple boost", false, "If true players can boost an item multiple times before it runs out. (ex. if they have a boost active they can extend by paying before it expires)"); public static final ConfigSetting LISTING_PRIORITY_TIME_COST_PER_BOOST = new ConfigSetting(config, "auction setting.listing priority.cost per boost", 1000, "How much should it cost the player to boost their item each time"); + // Timed Usage + public static final ConfigSetting TIMED_USAGE = new ConfigSetting(config, "auction setting.access hours.use access hours", false, "If true, the auction house will be only accessible"); + + public static final ConfigSetting SHOW_LISTING_ERROR_IN_CONSOLE = new ConfigSetting(config, "auction setting.show listing error in console", false, "If true, an exception will be thrown and shown in the console if something goes wrong during item listing"); public static final ConfigSetting STORE_PAYMENTS_FOR_MANUAL_COLLECTION = new ConfigSetting(config, "auction setting.store payments for manual collection", false, "If true, auction house will store the payments to be manually collected rather than automatically given to the player"); public static final ConfigSetting MANUAL_PAYMENTS_ONLY_FOR_OFFLINE_USERS = new ConfigSetting(config, "auction setting.use stored payments for offline only", false, "If true, the usage of the manual payment collection will only be done if the user is offline"); diff --git a/src/main/resources/plugin.yml b/src/main/resources/plugin.yml index be764ea..0886551 100644 --- a/src/main/resources/plugin.yml +++ b/src/main/resources/plugin.yml @@ -5,4 +5,4 @@ main: ca.tweetzy.auctionhouse.AuctionHouse description: Auction House is a premium auction solution for your server. website: https://discord.tweetzy.ca/ authors: [ Kiran Hart ] -softdepend: [ Vault, PlayerPoints, PlaceholderAPI, MMOItemsHook, UltraEconomy, CMI, Essentials, ChestShop, EcoEnchants, EcoBits, Funds ] +softdepend: [ Vault, PlayerPoints, PlaceholderAPI, MMOItemsHook, UltraEconomy, CMI, Essentials, ChestShop, EcoEnchants, EcoBits, Funds, CoinsEngine ]