From 38d9995d6c801223324b1974e4f46e5e32f69e9b Mon Sep 17 00:00:00 2001 From: Christian Koop Date: Fri, 31 Mar 2023 20:40:07 +0200 Subject: [PATCH] Adds experimental support `EconomyShopGUI` support for AutoSell Pretty stupid/ugly how the API is accessed and users enabled this feature. Something for the future when the new SongodaCore release is ready. Requested by multiple users on Discord. --- pom.xml | 7 +++++++ .../hopper/levels/modules/ModuleAutoSell.java | 20 +++++++++++++++--- .../epichoppers/settings/Settings.java | 8 +++++-- src/main/resources/plugin.yml | 21 ++++++++++++++++++- 4 files changed, 50 insertions(+), 6 deletions(-) diff --git a/pom.xml b/pom.xml index b3526b1..26cbca5 100644 --- a/pom.xml +++ b/pom.xml @@ -151,6 +151,13 @@ provided + + com.github.Gypopo + EconomyShopGUI-API + 1.4.0 + provided + + com.songoda UltimateStacker diff --git a/src/main/java/com/songoda/epichoppers/hopper/levels/modules/ModuleAutoSell.java b/src/main/java/com/songoda/epichoppers/hopper/levels/modules/ModuleAutoSell.java index 7cde2f3..90863f0 100644 --- a/src/main/java/com/songoda/epichoppers/hopper/levels/modules/ModuleAutoSell.java +++ b/src/main/java/com/songoda/epichoppers/hopper/levels/modules/ModuleAutoSell.java @@ -10,6 +10,7 @@ import com.songoda.epichoppers.hopper.Hopper; import com.songoda.epichoppers.settings.Settings; import com.songoda.epichoppers.utils.Methods; import com.songoda.epichoppers.utils.StorageContainerCache; +import me.gypopo.economyshopgui.api.EconomyShopGUIHook; import org.bukkit.Bukkit; import org.bukkit.Material; import org.bukkit.OfflinePlayer; @@ -75,7 +76,7 @@ public class ModuleAutoSell extends Module { continue; } - // Get the value from config or ShopGuiPlus + // Get the value from config or ShopGuiPlus or EconomyShopGui double value; if (Settings.AUTOSELL_SHOPGUIPLUS.getBoolean() && player.isOnline()) { try { @@ -85,9 +86,22 @@ public class ModuleAutoSell extends Module { } catch (Exception e) { value = 0; } - } else + } else if (Settings.AUTOSELL_ECONOMY_SHOP_GUI.getBoolean() && player.isOnline() && (Bukkit.getPluginManager().isPluginEnabled("EconomyShopGUI") || Bukkit.getPluginManager().isPluginEnabled("EconomyShopGUI-Premium"))) { + value = 0; + try { + ItemStack clone = itemStack.clone(); + clone.setAmount(1); + Double sellPrice = EconomyShopGUIHook.getItemSellPrice(player.getPlayer(), clone); + if (sellPrice != null) { + value = sellPrice; + } + } catch (Exception ex) { + ex.printStackTrace(); + } + } else { value = Settings.AUTOSELL_PRICES.getStringList().stream().filter(line -> CompatibleMaterial.valueOf(line.split(",")[0]) == CompatibleMaterial.getMaterial(itemStack)).findFirst() .map(s -> Double.valueOf(s.split(",")[1])).orElse(0.0); + } if (value <= 0) continue; @@ -186,4 +200,4 @@ public class ModuleAutoSell extends Module { if (time == null) return -9999; return (int) time; } -} \ No newline at end of file +} diff --git a/src/main/java/com/songoda/epichoppers/settings/Settings.java b/src/main/java/com/songoda/epichoppers/settings/Settings.java index 007b058..416491a 100644 --- a/src/main/java/com/songoda/epichoppers/settings/Settings.java +++ b/src/main/java/com/songoda/epichoppers/settings/Settings.java @@ -86,9 +86,13 @@ public class Settings { public static final ConfigSetting AUTOSELL_SHOPGUIPLUS = new ConfigSetting(config, "Main.Use ShopGuiPlus for Prices", false, "Should prices be grabbed from ShopGuiPlus?", - "If ShopGuiPlus is not enabled or the player is offline the default price list will be used.", + "If ShopGuiPlus is not enabled or the player is offline the default price list will be used (or EconomyShopGUI if enabled).", "If this is something that you do not want then you should empty the default list."); + public static final ConfigSetting AUTOSELL_ECONOMY_SHOP_GUI = new ConfigSetting(config, "Main.Use EconomyShopGUI for Prices", false, + "Should prices be grabbed from EconomyShopGUI?", + "If 'Use ShopGuiPlus for Prices' is enabled and the player is online, this will be ignored."); + public static final ConfigSetting ECONOMY_PLUGIN = new ConfigSetting(config, "Main.Economy", EconomyManager.getEconomy() == null ? "Vault" : EconomyManager.getEconomy().getName(), "Which economy plugin should be used?", "Supported plugins you have installed: \"" + EconomyManager.getManager().getRegisteredPlugins().stream().collect(Collectors.joining("\", \"")) + "\"."); @@ -150,4 +154,4 @@ public class Settings { config.saveChanges(); } -} \ No newline at end of file +} diff --git a/src/main/resources/plugin.yml b/src/main/resources/plugin.yml index d203a20..64c9f68 100644 --- a/src/main/resources/plugin.yml +++ b/src/main/resources/plugin.yml @@ -1,7 +1,26 @@ name: EpicHoppers description: EpicHoppers main: com.songoda.epichoppers.EpicHoppers -softdepend: [ FabledSkyBlock, LiquidTanks, UltimateStacker, WildStacker, Reserve, Towny, RedProtect, Kingdoms, PlotsSquared, GriefPrevention, USkyBlock, ASkyBlock, WorldGuard, Factions, Vault, EpicFarming, AdvancedChests ] +softdepend: + - ASkyBlock + - AdvancedChests + - EconomyShopGUI + - EconomyShopGUI-Premium + - EpicFarming + - FabledSkyBlock + - Factions + - GriefPrevention + - Kingdoms + - LiquidTanks + - PlotsSquared + - RedProtect + - Reserve + - Towny + - USkyBlock + - UltimateStacker + - Vault + - WildStacker + - WorldGuard version: maven-version-number author: Songoda api-version: 1.13