|
1 | 1 | package fr.maxlego08.shop.economy; |
2 | 2 |
|
3 | | -import fr.maxlego08.menu.hooks.currencies.Currencies; |
4 | | -import fr.maxlego08.menu.hooks.currencies.CurrencyProvider; |
5 | 3 | import fr.maxlego08.shop.ShopPlugin; |
6 | 4 | import fr.maxlego08.shop.api.economy.EconomyManager; |
7 | 5 | import fr.maxlego08.shop.api.economy.ShopEconomy; |
8 | 6 | import fr.maxlego08.shop.api.event.events.ZShopEconomyRegisterEvent; |
9 | 7 | import fr.maxlego08.shop.save.Config; |
10 | 8 | import fr.maxlego08.shop.zcore.logger.Logger; |
| 9 | +import fr.traqueur.currencies.Currencies; |
| 10 | +import fr.traqueur.currencies.CurrencyProvider; |
| 11 | +import fr.traqueur.currencies.providers.ZMenuItemProvider; |
11 | 12 | import org.bukkit.configuration.file.YamlConfiguration; |
12 | 13 |
|
13 | 14 | import java.io.File; |
14 | | -import java.util.ArrayList; |
15 | | -import java.util.Collection; |
16 | | -import java.util.Collections; |
17 | | -import java.util.List; |
18 | | -import java.util.Optional; |
| 15 | +import java.util.*; |
19 | 16 |
|
20 | 17 | public class ZEconomyManager implements EconomyManager { |
21 | 18 |
|
@@ -63,27 +60,37 @@ public void loadEconomies() { |
63 | 60 |
|
64 | 61 | YamlConfiguration configuration = YamlConfiguration.loadConfiguration(file); |
65 | 62 | for (String key : configuration.getConfigurationSection("economies.").getKeys(false)) { |
66 | | - String path = "economies." + key + "."; |
67 | | - |
68 | | - if (!configuration.getBoolean(path + "isEnable", configuration.getBoolean(path + "is-enable"))) continue; |
69 | | - |
70 | | - String name = configuration.getString(path + "name", "VAULT"); |
71 | | - String type = configuration.getString(path + "type", "VAULT"); |
72 | | - String currency = configuration.getString(path + "currency", "$"); |
73 | | - String denyMessage = configuration.getString(path + "denyMessage", configuration.getString(path + "deny-message")); |
74 | | - |
75 | | - Currencies currencies = Currencies.valueOf(type.toUpperCase()); |
76 | | - CurrencyProvider currencyProvider = switch (currencies) { |
77 | | - case ZMENUITEMS, ITEM -> Currencies.ZMENUITEMS.createProvider(plugin, file, path + "item."); |
78 | | - case ZESSENTIALS, ECOBITS, COINSENGINE, REDISECONOMY -> { |
79 | | - String currencyName = configuration.getString(path + "currencyName", configuration.getString(path + "currency-name")); |
80 | | - yield currencies.createProvider(currencyName); |
81 | | - } |
82 | | - default -> currencies.createProvider(); |
83 | | - }; |
84 | | - |
85 | | - if (Config.enableDebug) Logger.info("Register Vault economy"); |
86 | | - registerEconomy(new ZShopEconomy(name, currency, denyMessage, currencyProvider)); |
| 63 | + try { |
| 64 | + |
| 65 | + String path = "economies." + key + "."; |
| 66 | + |
| 67 | + if (!configuration.getBoolean(path + "isEnable", configuration.getBoolean(path + "is-enable"))) |
| 68 | + continue; |
| 69 | + |
| 70 | + String name = configuration.getString(path + "name", "VAULT"); |
| 71 | + String type = configuration.getString(path + "type", "VAULT"); |
| 72 | + String currency = configuration.getString(path + "currency", "$"); |
| 73 | + String denyMessage = configuration.getString(path + "denyMessage", configuration.getString(path + "deny-message")); |
| 74 | + |
| 75 | + Currencies currencies = Currencies.valueOf(type.toUpperCase()); |
| 76 | + CurrencyProvider currencyProvider = switch (currencies) { |
| 77 | + case ZMENUITEMS, ITEM -> { |
| 78 | + var itemStack = this.plugin.getIManager().loadItemStack(configuration, path + "item.", file); |
| 79 | + yield new ZMenuItemProvider(plugin, itemStack); |
| 80 | + } |
| 81 | + case ZESSENTIALS, ECOBITS, COINSENGINE, REDISECONOMY -> { |
| 82 | + String currencyName = configuration.getString(path + "currencyName", configuration.getString(path + "currency-name")); |
| 83 | + yield currencies.createProvider(currencyName); |
| 84 | + } |
| 85 | + default -> currencies.createProvider(); |
| 86 | + }; |
| 87 | + |
| 88 | + if (Config.enableDebug) Logger.info("Register " + name + " economy"); |
| 89 | + registerEconomy(new ZShopEconomy(name, currency, denyMessage, currencyProvider)); |
| 90 | + } catch (Exception exception) { |
| 91 | + this.plugin.getLogger().severe("Error while loading " + key + " economy"); |
| 92 | + exception.printStackTrace(); |
| 93 | + } |
87 | 94 | } |
88 | 95 |
|
89 | 96 | ZShopEconomyRegisterEvent event = new ZShopEconomyRegisterEvent(this); |
|
0 commit comments