Skip to content

Commit

Permalink
Minor bug fixes and improvements related to sell/buy commands
Browse files Browse the repository at this point in the history
  • Loading branch information
7sat committed Feb 19, 2023
1 parent 061d508 commit 2956bd3
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 19 deletions.
21 changes: 2 additions & 19 deletions src/main/java/me/sat7/dynamicshop/commands/shop/Command.java
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -153,29 +153,12 @@ 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
{
sender.sendMessage(DynamicShop.dsPrefix(sender) + t(sender, "ERR.WRONG_USAGE"));
}
}

private void CleanupIndex(CustomConfig shopData, String sellBuyString)
{
ArrayList<Object> tempDatas = new ArrayList<>();
if (shopData.get().getConfigurationSection("Options.command." + sellBuyString) != null)
{
for (Map.Entry<String, Object> 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));
}
}
}
25 changes: 25 additions & 0 deletions src/main/java/me/sat7/dynamicshop/utilities/ShopUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}

Expand All @@ -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<Object> tempDatas = new ArrayList<>();
if (shopData.get().getConfigurationSection("Options.command." + sellBuyString) != null)
{
for (Map.Entry<String, Object> 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));
}
}
}

0 comments on commit 2956bd3

Please sign in to comment.