From 265548767ef17e2d3900f740707525aa1a3b0729 Mon Sep 17 00:00:00 2001 From: AfkF24 <12214250+AfkF24@users.noreply.github.com> Date: Sun, 3 Sep 2023 11:01:01 +0200 Subject: [PATCH] Add configurable buttons in Trade menu Adds configurable balance, sell and buy buttons in the trading menu --- .../me/sat7/dynamicshop/guis/InGameUI.java | 39 +++++++++++++++++++ .../me/sat7/dynamicshop/guis/ItemTrade.java | 6 +-- .../dynamicshop/utilities/ConfigUtil.java | 30 ++++++++++++++ src/main/resources/config.yml | 3 ++ 4 files changed, 75 insertions(+), 3 deletions(-) diff --git a/src/main/java/me/sat7/dynamicshop/guis/InGameUI.java b/src/main/java/me/sat7/dynamicshop/guis/InGameUI.java index dc0b5df..c859ed2 100644 --- a/src/main/java/me/sat7/dynamicshop/guis/InGameUI.java +++ b/src/main/java/me/sat7/dynamicshop/guis/InGameUI.java @@ -155,4 +155,43 @@ public static Material GetShopInfoButtonIconMat() } return mat; } + + public static Material GetBalanceButtonIconMat() + { + String iconName = ConfigUtil.GetBalanceButtonIcon(); + Material mat = Material.getMaterial(iconName); + if (mat == null) + { + mat = Material.EMERALD; + ConfigUtil.SetBalanceButtonIcon("EMERALD"); + ConfigUtil.Save(); + } + return mat; + } + + public static Material GetSellToggleButtonIconMat() + { + String iconName = ConfigUtil.GetSellToggleButtonIcon(); + Material mat = Material.getMaterial(iconName); + if (mat == null) + { + mat = Material.GREEN_STAINED_GLASS; + ConfigUtil.SetSellToggleButtonIcon("GREEN_STAINED_GLASS"); + ConfigUtil.Save(); + } + return mat; + } + + public static Material GetBuyToggleButtonIconMat() + { + String iconName = ConfigUtil.GetBuyToggleButtonIcon(); + Material mat = Material.getMaterial(iconName); + if (mat == null) + { + mat = Material.RED_STAINED_GLASS; + ConfigUtil.SetBuyToggleButtonIcon("RED_STAINED_GLASS"); + ConfigUtil.Save(); + } + return mat; + } } diff --git a/src/main/java/me/sat7/dynamicshop/guis/ItemTrade.java b/src/main/java/me/sat7/dynamicshop/guis/ItemTrade.java index 822377c..6cf8b32 100644 --- a/src/main/java/me/sat7/dynamicshop/guis/ItemTrade.java +++ b/src/main/java/me/sat7/dynamicshop/guis/ItemTrade.java @@ -233,7 +233,7 @@ else if (ShopUtil.GetCurrency(shopData).equalsIgnoreCase(Constants.S_EXP)) if (ChatColor.stripColor(temp).startsWith("\n")) moneyLore = moneyLore.replaceFirst("\n", ""); - CreateButton(CHECK_BALANCE, Material.EMERALD, t(player, "TRADE.BALANCE"), moneyLore); + CreateButton(CHECK_BALANCE, InGameUI.GetBalanceButtonIconMat(), t(player, "TRADE.BALANCE"), moneyLore); } private void CreateSellBuyOnlyToggle() @@ -252,8 +252,8 @@ private void CreateSellBuyOnlyToggle() if (player.hasPermission(P_ADMIN_SHOP_EDIT)) buyLore.add(t(player,"TRADE.TOGGLE_BUYABLE")); - CreateButton(SELL_ONLY_TOGGLE, Material.GREEN_STAINED_GLASS, t(player, "TRADE.SELL"), sellLore); - CreateButton(BUY_ONLY_TOGGLE, Material.RED_STAINED_GLASS, t(player, "TRADE.BUY"), buyLore); + CreateButton(SELL_ONLY_TOGGLE, InGameUI.GetSellToggleButtonIconMat(), t(player, "TRADE.SELL"), sellLore); + CreateButton(BUY_ONLY_TOGGLE, InGameUI.GetBuyToggleButtonIconMat(), t(player, "TRADE.BUY"), buyLore); } private void CreateTradeButtons() diff --git a/src/main/java/me/sat7/dynamicshop/utilities/ConfigUtil.java b/src/main/java/me/sat7/dynamicshop/utilities/ConfigUtil.java index 7acc10e..c14145e 100644 --- a/src/main/java/me/sat7/dynamicshop/utilities/ConfigUtil.java +++ b/src/main/java/me/sat7/dynamicshop/utilities/ConfigUtil.java @@ -214,6 +214,36 @@ public static void SetShopInfoButtonIcon(String value) config.set("UI.ShopInfoButtonIcon", value); } + public static String GetBalanceButtonIcon() + { + return config.getString("UI.BalanceButtonIcon"); + } + + public static void SetBalanceButtonIcon(String value) + { + config.set("UI.BalanceButtonIcon", value); + } + + public static String GetSellToggleButtonIcon() + { + return config.getString("UI.SellToggleButtonIcon"); + } + + public static void SetSellToggleButtonIcon(String value) + { + config.set("UI.SellToggleButtonIcon", value); + } + + public static String GetBuyToggleButtonIcon() + { + return config.getString("UI.BuyToggleButtonIcon"); + } + + public static void SetBuyToggleButtonIcon(String value) + { + config.set("UI.BuyToggleButtonIcon", value); + } + public static String GetIntFormat() { return config.getString("UI.IntFormat"); diff --git a/src/main/resources/config.yml b/src/main/resources/config.yml index 0465fb9..e0fd01d 100644 --- a/src/main/resources/config.yml +++ b/src/main/resources/config.yml @@ -15,6 +15,9 @@ UI.OpenStartPageWhenClickCloseButton: true UI.CloseButtonIcon : BARRIER UI.PageButtonIcon : PAPER UI.ShopInfoButtonIcon : OAK_SIGN +UI.BalanceButtonIcon : EMERALD +UI.SellToggleButtonIcon : GREEN_STAINED_GLASS +UI.BuyToggleButtonIcon : RED_STAINED_GLASS UI.IntFormat: '###,###' UI.DoubleFormat: '###,##0.00' UI.LocalizedItemName: true