From 2956bd3bda3ca8a80f3debc9a5ff01a3847c1838 Mon Sep 17 00:00:00 2001 From: 7sat <49030779+7sat@users.noreply.github.com> Date: Sun, 19 Feb 2023 22:50:12 +0900 Subject: [PATCH] Minor bug fixes and improvements related to sell/buy commands --- .../dynamicshop/commands/shop/Command.java | 21 ++-------------- .../sat7/dynamicshop/utilities/ShopUtil.java | 25 +++++++++++++++++++ 2 files changed, 27 insertions(+), 19 deletions(-) diff --git a/src/main/java/me/sat7/dynamicshop/commands/shop/Command.java b/src/main/java/me/sat7/dynamicshop/commands/shop/Command.java index 1409f7c..fd65124 100644 --- a/src/main/java/me/sat7/dynamicshop/commands/shop/Command.java +++ b/src/main/java/me/sat7/dynamicshop/commands/shop/Command.java @@ -125,7 +125,7 @@ private void subCmd(CommandSender sender, String[] args, CustomConfig shopData, } shopData.get().set("Options.command." + sellBuyString + "." + idx, null); - CleanupIndex(shopData, "sellBuyString"); + ShopUtil.CleanupCommandIndex(Shop.GetShopName(args), sellBuyString); PrintCurrentState(sender, Shop.GetShopName(args), true, true); } else if(args[4].equalsIgnoreCase("add") && args.length >= 7) @@ -153,7 +153,7 @@ else if(args[4].equalsIgnoreCase("add") && args.length >= 7) } shopData.get().set("Options.command." + sellBuyString + "." + idx, cmdString); - CleanupIndex(shopData, "sellBuyString"); + ShopUtil.CleanupCommandIndex(Shop.GetShopName(args), sellBuyString); PrintCurrentState(sender, Shop.GetShopName(args), true, true); } else @@ -161,21 +161,4 @@ else if(args[4].equalsIgnoreCase("add") && args.length >= 7) sender.sendMessage(DynamicShop.dsPrefix(sender) + t(sender, "ERR.WRONG_USAGE")); } } - - private void CleanupIndex(CustomConfig shopData, String sellBuyString) - { - ArrayList tempDatas = new ArrayList<>(); - if (shopData.get().getConfigurationSection("Options.command." + sellBuyString) != null) - { - for (Map.Entry s : shopData.get().getConfigurationSection("Options.command." + sellBuyString).getValues(false).entrySet()) - { - tempDatas.add(s.getValue()); - } - } - shopData.get().set("Options.command." + sellBuyString, null); - for (int i = 0; i < tempDatas.size(); i++) - { - shopData.get().set("Options.command." + sellBuyString + "." + i, tempDatas.get(i)); - } - } } diff --git a/src/main/java/me/sat7/dynamicshop/utilities/ShopUtil.java b/src/main/java/me/sat7/dynamicshop/utilities/ShopUtil.java index e33084e..2b8564f 100644 --- a/src/main/java/me/sat7/dynamicshop/utilities/ShopUtil.java +++ b/src/main/java/me/sat7/dynamicshop/utilities/ShopUtil.java @@ -1193,6 +1193,8 @@ public static void SetShopSellCommand(String shopName, int idx, String command) return; shopConf.set("command.sell." + idx, command); + CleanupCommandIndex(shopName, "sell"); + shopData.save(); } @@ -1207,6 +1209,29 @@ public static void SetShopBuyCommand(String shopName, int idx, String command) return; shopConf.set("command.buy." + idx, command); + CleanupCommandIndex(shopName, "buy"); + shopData.save(); } + + public static void CleanupCommandIndex(String shopName, String sellBuyString) + { + CustomConfig shopData = ShopUtil.shopConfigFiles.get(shopName); + if (shopData == null) + return; + + ArrayList tempDatas = new ArrayList<>(); + if (shopData.get().getConfigurationSection("Options.command." + sellBuyString) != null) + { + for (Map.Entry s : shopData.get().getConfigurationSection("Options.command." + sellBuyString).getValues(false).entrySet()) + { + tempDatas.add(s.getValue()); + } + } + shopData.get().set("Options.command." + sellBuyString, null); + for (int i = 0; i < tempDatas.size(); i++) + { + shopData.get().set("Options.command." + sellBuyString + "." + i, tempDatas.get(i)); + } + } }