diff --git a/src/main/java/me/sat7/dynamicshop/DynamicShop.java b/src/main/java/me/sat7/dynamicshop/DynamicShop.java index f3cd894..7a6b84b 100644 --- a/src/main/java/me/sat7/dynamicshop/DynamicShop.java +++ b/src/main/java/me/sat7/dynamicshop/DynamicShop.java @@ -39,7 +39,6 @@ import java.io.File; import java.util.*; -import static me.sat7.dynamicshop.utilities.ConfigUtil.configVersion; import static me.sat7.dynamicshop.utilities.LangUtil.t; public final class DynamicShop extends JavaPlugin implements Listener @@ -68,10 +67,10 @@ public static String dsPrefix(Player player) { String temp = dsPrefix_; - if(plugin.getConfig().getBoolean("UI.UseHexColorCode")) + if(ConfigUtil.GetUseHexColorCode()) temp = LangUtil.TranslateHexColor(temp); - if(isPapiExist && player != null && plugin.getConfig().getBoolean("UI.UsePlaceholderAPI")) + if(isPapiExist && player != null && ConfigUtil.GetUsePlaceholderAPI()) return PlaceholderAPI.setPlaceholders(player, temp); return temp; @@ -316,7 +315,7 @@ private void InitPapi() public void startSaveLogsTask() { - if (getConfig().getBoolean("Log.SaveLogs")) + if (ConfigUtil.GetSaveLogs()) { if (saveLogsTask != null) { @@ -328,13 +327,15 @@ public void startSaveLogsTask() public void startCullLogsTask() { - if (getConfig().getBoolean("Log.CullLogs")) + if (ConfigUtil.GetCullLogs()) { if (cullLogsTask != null) { cullLogsTask.cancel(); } - cullLogsTask = Bukkit.getScheduler().runTaskTimerAsynchronously(this, LogUtil::cullLogs, 0L, (20L * 60L * (long) getConfig().getInt("Log.LogCullTimeMinutes"))); + cullLogsTask = Bukkit.getScheduler().runTaskTimerAsynchronously( + this, LogUtil::cullLogs, 0L, (20L * 60L * (long) ConfigUtil.GetLogCullTimeMinutes()) + ); } } @@ -449,9 +450,9 @@ private void InitConfig() ShopUtil.Reload(); - ConfigUtil.configSetup(this); + ConfigUtil.Load(); - LangUtil.setupLangFile(getConfig().getString("Language")); + LangUtil.setupLangFile(ConfigUtil.GetLanguage()); LayoutUtil.Setup(); setupUserFile(); @@ -462,40 +463,6 @@ private void InitConfig() QuickSell.quickSellGui = new CustomConfig(); QuickSell.SetupQuickSellGUIFile(); - - ConfigUpdate(); - - getConfig().set("Version", configVersion); - saveConfig(); - } - - private void ConfigUpdate() - { - int userVersion = getConfig().getInt("Version"); - if (userVersion == 3) - { - for(Map.Entry entry : ShopUtil.shopConfigFiles.entrySet()) - { - ConfigurationSection cmdCS = entry.getValue().get().getConfigurationSection("Options.command"); - if(cmdCS == null) - continue; - - boolean somethingChanged = false; - if(cmdCS.contains("sell")) - { - cmdCS.set("sell.0", cmdCS.get("sell")); - somethingChanged = true; - } - if(cmdCS.contains("buy")) - { - cmdCS.set("buy.0", cmdCS.get("buy")); - somethingChanged = true; - } - - if(somethingChanged) - entry.getValue().save(); - } - } } private void setupUserFile() @@ -503,7 +470,7 @@ private void setupUserFile() ccUser.setup("User", null); ccUser.get().options().copyDefaults(true); - int userVersion = getConfig().getInt("Version"); + int userVersion = ConfigUtil.GetConfigVersion(); if (userVersion < 3) { for (String s : ccUser.get().getKeys(false)) diff --git a/src/main/java/me/sat7/dynamicshop/commands/Optional.java b/src/main/java/me/sat7/dynamicshop/commands/Optional.java index f21cb89..b1d28f2 100644 --- a/src/main/java/me/sat7/dynamicshop/commands/Optional.java +++ b/src/main/java/me/sat7/dynamicshop/commands/Optional.java @@ -3,6 +3,7 @@ import me.sat7.dynamicshop.DynamicShop; import me.sat7.dynamicshop.constants.Constants; +import me.sat7.dynamicshop.utilities.ConfigUtil; import org.bukkit.Bukkit; import org.bukkit.GameMode; import org.bukkit.command.Command; @@ -17,7 +18,8 @@ public class Optional implements CommandExecutor @Override public boolean onCommand(CommandSender sender, Command command, String label, String[] args) { - if (!DynamicShop.plugin.getConfig().getBoolean("Command.UseShopCommand")) return true; + if (!ConfigUtil.GetUseShopCommand()) + return true; if (sender instanceof Player) { diff --git a/src/main/java/me/sat7/dynamicshop/commands/Reload.java b/src/main/java/me/sat7/dynamicshop/commands/Reload.java index 27ddaad..dd8b72b 100644 --- a/src/main/java/me/sat7/dynamicshop/commands/Reload.java +++ b/src/main/java/me/sat7/dynamicshop/commands/Reload.java @@ -9,7 +9,6 @@ import me.sat7.dynamicshop.guis.StartPage; import static me.sat7.dynamicshop.constants.Constants.P_ADMIN_RELOAD; -import static me.sat7.dynamicshop.utilities.ConfigUtil.configVersion; import static me.sat7.dynamicshop.utilities.LangUtil.t; public final class Reload extends DSCMD @@ -51,8 +50,7 @@ public void RunCMD(String[] args, CommandSender sender) SoundUtil.ccSound.reload(); SoundUtil.setupSoundFile(); - DynamicShop.plugin.reloadConfig(); - ConfigUtil.configSetup(DynamicShop.plugin); + ConfigUtil.Load(); DynamicShop.plugin.PeriodicRepetitiveTask(); DynamicShop.plugin.startSaveLogsTask(); @@ -62,9 +60,7 @@ public void RunCMD(String[] args, CommandSender sender) QuickSell.quickSellGui.reload(); QuickSell.SetupQuickSellGUIFile(); - LangUtil.setupLangFile(DynamicShop.plugin.getConfig().getString("Language")); - - DynamicShop.plugin.getConfig().set("Version", configVersion); + LangUtil.setupLangFile(ConfigUtil.GetLanguage()); sender.sendMessage(DynamicShop.dsPrefix(sender) + t(sender, "HELP.RELOADED")); } diff --git a/src/main/java/me/sat7/dynamicshop/commands/SetDefaultShop.java b/src/main/java/me/sat7/dynamicshop/commands/SetDefaultShop.java index 5135f27..991282e 100644 --- a/src/main/java/me/sat7/dynamicshop/commands/SetDefaultShop.java +++ b/src/main/java/me/sat7/dynamicshop/commands/SetDefaultShop.java @@ -1,5 +1,6 @@ package me.sat7.dynamicshop.commands; +import me.sat7.dynamicshop.utilities.ConfigUtil; import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; @@ -35,8 +36,8 @@ public void RunCMD(String[] args, CommandSender sender) if (ShopUtil.shopConfigFiles.containsKey(args[1])) { - DynamicShop.plugin.getConfig().set("Command.DefaultShopName", args[1]); - DynamicShop.plugin.saveConfig(); + ConfigUtil.SetDefaultShopName(args[1]); + ConfigUtil.Save(); sender.sendMessage(DynamicShop.dsPrefix(sender) + t(sender, "MESSAGE.CHANGES_APPLIED") + args[1]); } else diff --git a/src/main/java/me/sat7/dynamicshop/commands/SetTax.java b/src/main/java/me/sat7/dynamicshop/commands/SetTax.java index 0f3432e..662508e 100644 --- a/src/main/java/me/sat7/dynamicshop/commands/SetTax.java +++ b/src/main/java/me/sat7/dynamicshop/commands/SetTax.java @@ -46,9 +46,8 @@ public void RunCMD(String[] args, CommandSender sender) try { int newValue = Clamp(Integer.parseInt(args[1]), 1, 99); - - DynamicShop.plugin.getConfig().set("Shop.SalesTax", newValue); - DynamicShop.plugin.saveConfig(); + ConfigUtil.SetSalesTax(newValue); + ConfigUtil.Save(); ConfigUtil.setCurrentTax(newValue); diff --git a/src/main/java/me/sat7/dynamicshop/commands/Shop.java b/src/main/java/me/sat7/dynamicshop/commands/Shop.java index 65a2272..ec2af2f 100644 --- a/src/main/java/me/sat7/dynamicshop/commands/Shop.java +++ b/src/main/java/me/sat7/dynamicshop/commands/Shop.java @@ -1,6 +1,7 @@ package me.sat7.dynamicshop.commands; import me.sat7.dynamicshop.files.CustomConfig; +import me.sat7.dynamicshop.utilities.ConfigUtil; import org.bukkit.command.CommandSender; import org.bukkit.configuration.ConfigurationSection; import org.bukkit.entity.Player; @@ -25,7 +26,7 @@ public static String GetShopName(String[] args) { if (args.length == 1) { - return DynamicShop.plugin.getConfig().getString("Command.DefaultShopName"); + return ConfigUtil.GetDefaultShopName(); } else if (args.length > 1) { @@ -44,7 +45,7 @@ static void shopCommand(String[] args, CommandSender sender) if(sender instanceof Player) player = (Player) sender; - if (player != null && args.length == 1 && DynamicShop.plugin.getConfig().getBoolean("Command.OpenStartPageInsteadOfDefaultShop")) + if (player != null && args.length == 1 && ConfigUtil.GetOpenStartPageInsteadOfDefaultShop()) { DynaShopAPI.openStartPage(player); return; diff --git a/src/main/java/me/sat7/dynamicshop/guis/InGameUI.java b/src/main/java/me/sat7/dynamicshop/guis/InGameUI.java index 7467894..27b5f44 100644 --- a/src/main/java/me/sat7/dynamicshop/guis/InGameUI.java +++ b/src/main/java/me/sat7/dynamicshop/guis/InGameUI.java @@ -1,6 +1,6 @@ package me.sat7.dynamicshop.guis; -import me.sat7.dynamicshop.DynamicShop; +import me.sat7.dynamicshop.utilities.ConfigUtil; import me.sat7.dynamicshop.utilities.ItemsUtil; import org.bukkit.Material; import org.bukkit.entity.Player; @@ -116,39 +116,39 @@ protected void CreateCloseButton(Player player, int slotIndex) public static Material GetCloseButtonIconMat() { - String iconName = DynamicShop.plugin.getConfig().getString("UI.CloseButtonIcon"); + String iconName = ConfigUtil.GetCloseButtonIcon(); Material mat = Material.getMaterial(iconName); if (mat == null) { mat = Material.BARRIER; - DynamicShop.plugin.getConfig().set("UI.CloseButtonIcon", "BARRIER"); - DynamicShop.plugin.saveConfig(); + ConfigUtil.SetCloseButtonIcon("BARRIER"); + ConfigUtil.Save(); } return mat; } public static Material GetPageButtonIconMat() { - String iconName = DynamicShop.plugin.getConfig().getString("UI.PageButtonIcon"); + String iconName = ConfigUtil.GetPageButtonIcon(); Material mat = Material.getMaterial(iconName); if (mat == null) { mat = Material.PAPER; - DynamicShop.plugin.getConfig().set("UI.PageButtonIcon", "PAPER"); - DynamicShop.plugin.saveConfig(); + ConfigUtil.SetPageButtonIcon("PAPER"); + ConfigUtil.Save(); } return mat; } public static Material GetShopInfoButtonIconMat() { - String iconName = DynamicShop.plugin.getConfig().getString("UI.ShopInfoButtonIcon"); + String iconName = ConfigUtil.GetShopInfoButtonIcon(); Material mat = Material.getMaterial(iconName); if (mat == null) { mat = Material.GOLD_BLOCK; - DynamicShop.plugin.getConfig().set("UI.ShopInfoButtonIcon", "GOLD_BLOCK"); - DynamicShop.plugin.saveConfig(); + ConfigUtil.SetShopInfoButtonIcon("GOLD_BLOCK"); + ConfigUtil.Save(); } return mat; } diff --git a/src/main/java/me/sat7/dynamicshop/guis/ItemSettings.java b/src/main/java/me/sat7/dynamicshop/guis/ItemSettings.java index 1230a91..2298bc0 100644 --- a/src/main/java/me/sat7/dynamicshop/guis/ItemSettings.java +++ b/src/main/java/me/sat7/dynamicshop/guis/ItemSettings.java @@ -240,7 +240,7 @@ public Inventory getGui(Player player, String shopName, int shopSlotIndex, int t recommendLore = t(player, "ERR.NO_RECOMMEND_DATA"); } else { - int sugMid = ShopUtil.CalcRecommendedMedian(worth, DynamicShop.plugin.getConfig().getInt("Shop.NumberOfPlayer")); + int sugMid = ShopUtil.CalcRecommendedMedian(worth, ConfigUtil.GetNumberOfPlayer()); String worthChanged = (dsItem.getBuyValue() == worth) ? " ▶§f " : " ▶§a "; String worthChanged2 = (dsItem.getSellValue() == worth) ? " ▶§f " : " ▶§a "; @@ -373,10 +373,9 @@ private void SetToRecommend() player.sendMessage(DynamicShop.dsPrefix(player) + t(player, "ERR.NO_RECOMMEND_DATA")); } else { - int numberOfPlayer = DynamicShop.plugin.getConfig().getInt("Shop.NumberOfPlayer"); - int sugMid = ShopUtil.CalcRecommendedMedian(worth, numberOfPlayer); + int sugMid = ShopUtil.CalcRecommendedMedian(worth, ConfigUtil.GetNumberOfPlayer()); - player.sendMessage(DynamicShop.dsPrefix(player) + t(player, "MESSAGE.RECOMMEND_APPLIED").replace("{playerNum}", numberOfPlayer + "")); + player.sendMessage(DynamicShop.dsPrefix(player) + t(player, "MESSAGE.RECOMMEND_APPLIED").replace("{playerNum}", ConfigUtil.GetNumberOfPlayer() + "")); DynaShopAPI.openItemSettingGui(player, shopName, shopSlotIndex, currentTab, inventory.getItem(SAMPLE_ITEM), worth, worth, minValue, maxValue, sugMid, sugMid, maxStock); diff --git a/src/main/java/me/sat7/dynamicshop/guis/ItemTrade.java b/src/main/java/me/sat7/dynamicshop/guis/ItemTrade.java index 689dff3..f10b387 100644 --- a/src/main/java/me/sat7/dynamicshop/guis/ItemTrade.java +++ b/src/main/java/me/sat7/dynamicshop/guis/ItemTrade.java @@ -8,6 +8,7 @@ import me.sat7.dynamicshop.files.CustomConfig; import me.sat7.dynamicshop.transactions.Buy; import me.sat7.dynamicshop.transactions.Sell; +import me.sat7.dynamicshop.utilities.ConfigUtil; import org.bukkit.Bukkit; import org.bukkit.ChatColor; import org.bukkit.Material; @@ -291,7 +292,7 @@ private void CreateTradeButtons(boolean sell) if (stock <= 0) { stockText = t(player, "TRADE.INF_STOCK"); - } else if (DynamicShop.plugin.getConfig().getBoolean("UI.DisplayStockAsStack")) + } else if (ConfigUtil.GetDisplayStockAsStack()) { stockText = t(player, "TRADE.STACKS").replace("{num}", n(stock / 64)); } else @@ -303,7 +304,7 @@ private void CreateTradeButtons(boolean sell) String maxStockText; if (shopData.contains("Options.flag.showmaxstock") && maxStock != -1) { - if (DynamicShop.plugin.getConfig().getBoolean("UI.DisplayStockAsStack")) + if (ConfigUtil.GetDisplayStockAsStack()) { maxStockText = t(player, "TRADE.STACKS").replace("{num}", n(maxStock / 64)); } else diff --git a/src/main/java/me/sat7/dynamicshop/guis/Shop.java b/src/main/java/me/sat7/dynamicshop/guis/Shop.java index 4a7ebc3..6b845d4 100644 --- a/src/main/java/me/sat7/dynamicshop/guis/Shop.java +++ b/src/main/java/me/sat7/dynamicshop/guis/Shop.java @@ -5,6 +5,7 @@ import java.util.regex.Pattern; import me.sat7.dynamicshop.DynaShopAPI; +import me.sat7.dynamicshop.utilities.ConfigUtil; import me.sat7.dynamicshop.utilities.SoundUtil; import org.bukkit.Bukkit; import org.bukkit.ChatColor; @@ -109,7 +110,7 @@ public void OnClickLowerInventory(InventoryClickEvent e) if(!CheckShopIsEnable()) return; - if(!DynamicShop.plugin.getConfig().getBoolean("UI.EnableInventoryClickSearch.Shop")) + if(!ConfigUtil.GetEnableInventoryClickSearch_Shop()) return; player = (Player) e.getWhoClicked(); @@ -156,7 +157,7 @@ private void ShowItems() if (stock <= 0) { stockStr = t(player, "SHOP.INF_STOCK"); - } else if (DynamicShop.plugin.getConfig().getBoolean("UI.DisplayStockAsStack")) + } else if (ConfigUtil.GetDisplayStockAsStack()) { stockStr = t(player, "SHOP.STACKS").replace("{num}", n(stock / 64)); } else @@ -166,7 +167,7 @@ private void ShowItems() if (maxStock != -1) { - if (DynamicShop.plugin.getConfig().getBoolean("UI.DisplayStockAsStack")) + if (ConfigUtil.GetDisplayStockAsStack()) { maxStockStr = t(player, "SHOP.STACKS").replace("{num}", n(maxStock / 64)); } @@ -459,7 +460,7 @@ private void CloseUI() } else { - if (DynamicShop.plugin.getConfig().getBoolean("UI.OpenStartPageWhenClickCloseButton")) + if (ConfigUtil.GetOpenStartPageWhenClickCloseButton()) { DynaShopAPI.openStartPage(player); } else diff --git a/src/main/java/me/sat7/dynamicshop/guis/ShopSettings.java b/src/main/java/me/sat7/dynamicshop/guis/ShopSettings.java index a4e538e..19dc913 100644 --- a/src/main/java/me/sat7/dynamicshop/guis/ShopSettings.java +++ b/src/main/java/me/sat7/dynamicshop/guis/ShopSettings.java @@ -208,7 +208,7 @@ public Inventory getGui(Player player, String shopName) CreateButton(STABLE_INTERVAL, Material.COMPARATOR, t(player, "FLUCTUATION.INTERVAL"), stable_interval_Lore, Clamp(stockStableConf.getInt("interval") / 2, 1, 64)); ArrayList stable_strength_Lore = new ArrayList<>(Arrays.asList( - DynamicShop.plugin.getConfig().getBoolean("Shop.UseLegacyStockStabilization") ? t(player, "STOCK_STABILIZING.STRENGTH_LORE_A") : t(player, "STOCK_STABILIZING.STRENGTH_LORE_B"), + ConfigUtil.GetUseLegacyStockStabilization() ? t(player, "STOCK_STABILIZING.STRENGTH_LORE_A") : t(player, "STOCK_STABILIZING.STRENGTH_LORE_B"), "§9" + t(player, "CUR_STATE") + ": ~" + stockStableConf.get("strength") + "%", "§e" + t(player, "CLICK") + ": " + t(player, "STOCK_STABILIZING.L_R_SHIFT"))); CreateButton(STABLE_STRENGTH, Material.COMPARATOR, t(player, "FLUCTUATION.STRENGTH"), stable_strength_Lore, Clamp((int) (stockStableConf.getDouble("strength") * 10), 1, 64)); @@ -600,7 +600,7 @@ else if (e.getSlot() == TAX_TOGGLE || e.getSlot() == TAX_AMOUNT) data.get().set("Options.SalesTax", null); } else { - data.get().set("Options.SalesTax", DynamicShop.plugin.getConfig().getInt("Shop.SalesTax")); + data.get().set("Options.SalesTax", ConfigUtil.GetSalesTax()); } DynaShopAPI.openShopSettingGui(player, shopName); diff --git a/src/main/java/me/sat7/dynamicshop/guis/StartPage.java b/src/main/java/me/sat7/dynamicshop/guis/StartPage.java index 6c58284..64c1407 100644 --- a/src/main/java/me/sat7/dynamicshop/guis/StartPage.java +++ b/src/main/java/me/sat7/dynamicshop/guis/StartPage.java @@ -4,6 +4,7 @@ import java.util.Arrays; import me.sat7.dynamicshop.DynaShopAPI; +import me.sat7.dynamicshop.utilities.ConfigUtil; import me.sat7.dynamicshop.utilities.ItemsUtil; import me.sat7.dynamicshop.utilities.LangUtil; import me.sat7.dynamicshop.utilities.ShopUtil; @@ -222,7 +223,7 @@ else if (player.hasPermission(P_ADMIN_SHOP_EDIT)) @Override public void OnClickLowerInventory(InventoryClickEvent e) { - if(!DynamicShop.plugin.getConfig().getBoolean("UI.EnableInventoryClickSearch.StartPage")) + if(!ConfigUtil.GetEnableInventoryClickSearch_StartPage()) return; Player player = (Player) e.getWhoClicked(); @@ -260,7 +261,7 @@ public void OnClickLowerInventory(InventoryClickEvent e) DynaShopAPI.openShopGui(player, ret[0], Integer.parseInt(ret[1]) / 45 + 1); - boolean useLocalizedName = DynamicShop.plugin.getConfig().getBoolean("UI.LocalizedItemName"); + boolean useLocalizedName = ConfigUtil.GetLocalizedItemName(); String message; if(isSell) { diff --git a/src/main/java/me/sat7/dynamicshop/transactions/Buy.java b/src/main/java/me/sat7/dynamicshop/transactions/Buy.java index 7f691f6..38a38c8 100644 --- a/src/main/java/me/sat7/dynamicshop/transactions/Buy.java +++ b/src/main/java/me/sat7/dynamicshop/transactions/Buy.java @@ -199,7 +199,7 @@ private static void SendBuyMessage(ItemTrade.CURRENCY currency, Economy econ, Ec { String message = ""; boolean itemHasCustomName = tempIS.getItemMeta() != null && tempIS.getItemMeta().hasDisplayName(); - boolean useLocalizedName = !itemHasCustomName && DynamicShop.plugin.getConfig().getBoolean("UI.LocalizedItemName"); + boolean useLocalizedName = !itemHasCustomName && ConfigUtil.GetLocalizedItemName(); if (currency == ItemTrade.CURRENCY.VAULT) { message = DynamicShop.dsPrefix(player) + t(player, "MESSAGE.BUY_SUCCESS", !useLocalizedName) diff --git a/src/main/java/me/sat7/dynamicshop/transactions/Sell.java b/src/main/java/me/sat7/dynamicshop/transactions/Sell.java index 5e911ab..4bec26d 100644 --- a/src/main/java/me/sat7/dynamicshop/transactions/Sell.java +++ b/src/main/java/me/sat7/dynamicshop/transactions/Sell.java @@ -307,7 +307,7 @@ else if (currency == ItemTrade.CURRENCY.PLAYER_POINT) private static void SendSellMessage(ItemTrade.CURRENCY currency, Economy econ, EconomyResponse r, Player player, int actualAmount, double priceSum, ItemStack tempIS) { boolean itemHasCustomName = tempIS.getItemMeta() != null && tempIS.getItemMeta().hasDisplayName(); - boolean useLocalizedName = !itemHasCustomName && DynamicShop.plugin.getConfig().getBoolean("UI.LocalizedItemName"); + boolean useLocalizedName = !itemHasCustomName && ConfigUtil.GetLocalizedItemName(); String message = ""; if (currency == ItemTrade.CURRENCY.VAULT) { diff --git a/src/main/java/me/sat7/dynamicshop/utilities/ConfigUtil.java b/src/main/java/me/sat7/dynamicshop/utilities/ConfigUtil.java index c275088..96959a0 100644 --- a/src/main/java/me/sat7/dynamicshop/utilities/ConfigUtil.java +++ b/src/main/java/me/sat7/dynamicshop/utilities/ConfigUtil.java @@ -3,195 +3,420 @@ import lombok.Getter; import lombok.Setter; import me.sat7.dynamicshop.DynamicShop; +import me.sat7.dynamicshop.files.CustomConfig; +import org.bukkit.configuration.ConfigurationSection; import org.bukkit.configuration.file.FileConfiguration; +import java.util.ArrayList; +import java.util.Map; + import static me.sat7.dynamicshop.utilities.MathUtil.Clamp; public final class ConfigUtil { - @Getter - @Setter - private static int currentTax; + public final static int PluginConfigVersion = 4; - public final static int configVersion = 4; + public static int GetConfigVersion() + { + return DynamicShop.plugin.getConfig().getInt("Version"); + } - private final static String[] dataKeys = new String[] - { - "Language", - "Prefix", - "Command.UseShopCommand", - "Command.OpenStartPageInsteadOfDefaultShop", - "Command.DefaultShopName", - "Command.PermissionCheckWhenCreatingAShopList", - "Shop.SalesTax", - "Shop.DeliveryChargeScale", - "Shop.DeliveryChargeMin", - "Shop.DeliveryChargeMax", - "Shop.NumberOfPlayer", - "Shop.UseLegacyStockStabilization", - "UI.DisplayStockAsStack", - "UI.OpenStartPageWhenClickCloseButton", - "UI.CloseButtonIcon", - "UI.PageButtonIcon", - "UI.ShopInfoButtonIcon", - "UI.IntFormat", - "UI.DoubleFormat", - "UI.LocalizedItemName", - "UI.UsePlaceholderAPI", - "UI.UseHexColorCode", - "UI.EnableInventoryClickSearch.StartPage", - "UI.EnableInventoryClickSearch.Shop", - "Log.SaveLogs", - "Log.LogFileNameFormat", - "Log.CullLogs", - "Log.LogCullAgeMinutes", - "Log.LogCullTimeMinutes" - }; - - private ConfigUtil() - { - - } - - public static void configSetup(DynamicShop dynamicShop) - { - FileConfiguration config = dynamicShop.getConfig(); - - config.options().header( - "Language: ex) en-US,ko-KR" - + "\nUseShopCommand: Set this to false if you want to disable '/shop'" - + "\nDeliveryChargeScale: This is only used for shop with the 'delivery charge' flag. 0.01 ~" - + "\nNumberOfPlayer: This is used to calculate the recommended median. 3~100" - + "\nUseLegacyStockStabilization: false = Changed by n% of the gap with median. true = Changed by n% of median." - + "\nDisplayStockAsStack: ex) true: 10Stacks, false: 640" - + "\nVersion: Do NOT edit this" - ); - config.options().copyHeader(true); - - //기본값이 저장되어야 하는데 saveDefaultConfig() 가 작동 안해서 이렇게 처리함. - for(String s : dataKeys) - { - config.set(s, config.get(s)); - } + public static void SetConfigVersion(int value) + { + DynamicShop.plugin.getConfig().set("Version", value); + } + + // ============================================================ + + public static void Load() + { + ArrayList header = new ArrayList<>(); + header.add("Language: ex) en-US,ko-KR"); + header.add("UseShopCommand: Set this to false if you want to disable '/shop'"); + header.add("DeliveryChargeScale: This is only used for shop with the 'delivery charge' flag. 0.01 ~"); + header.add("NumberOfPlayer: This is used to calculate the recommended median. 3~100"); + header.add("UseLegacyStockStabilization: false = Changed by n% of the gap with median. true = Changed by n% of median."); + header.add("DisplayStockAsStack: ex) true: 10Stacks, false: 640"); + header.add("Version: Do NOT edit this"); + + DynamicShop.plugin.saveDefaultConfig(); + DynamicShop.plugin.reloadConfig(); + DynamicShop.plugin.getConfig().options().setHeader(header); + + ConvertV2toV3(); + ShopYMLUpdate(); + ValidateAndApply(); + SetConfigVersion(ConfigUtil.PluginConfigVersion); + Save(); + } + + public static void Save() + { + DynamicShop.plugin.saveConfig(); + } - DynamicShop.dsPrefix_ = config.getString("Prefix"); + public static String GetLanguage() + { + return DynamicShop.plugin.getConfig().getString("Language"); + } + + public static String GetPrefix() + { + return DynamicShop.plugin.getConfig().getString("Prefix"); + } - double salesTax = Clamp(config.getDouble("Shop.SalesTax"), 0, 99); - config.set("Shop.SalesTax", salesTax); - setCurrentTax((int) salesTax); + // [ Command ] ========== + + public static boolean GetUseShopCommand() + { + return DynamicShop.plugin.getConfig().getBoolean("Command.UseShopCommand"); + } + + public static boolean GetOpenStartPageInsteadOfDefaultShop() + { + return DynamicShop.plugin.getConfig().getBoolean("Command.OpenStartPageInsteadOfDefaultShop"); + } - double DeliveryChargeScale = config.getDouble("Shop.DeliveryChargeScale"); - if (DeliveryChargeScale < 0.01) DeliveryChargeScale = 0.01; - config.set("Shop.DeliveryChargeScale", DeliveryChargeScale); + public static String GetDefaultShopName() + { + return DynamicShop.plugin.getConfig().getString("Command.DefaultShopName"); + } - int DeliveryChargeMin = config.getInt("Shop.DeliveryChargeMin"); - if (DeliveryChargeMin < 1) DeliveryChargeMin = 1; - config.set("Shop.DeliveryChargeMin", DeliveryChargeMin); + public static void SetDefaultShopName(String value) + { + DynamicShop.plugin.getConfig().set("Command.DefaultShopName", value); + } - int DeliveryChargeMax = config.getInt("Shop.DeliveryChargeMax"); - if (DeliveryChargeMax < 1) DeliveryChargeMax = 1; - if (DeliveryChargeMax < DeliveryChargeMin) - DeliveryChargeMax = DeliveryChargeMin; - config.set("Shop.DeliveryChargeMax", DeliveryChargeMax); + public static boolean GetPermissionCheckWhenCreatingAShopList() + { + return DynamicShop.plugin.getConfig().getBoolean("Command.PermissionCheckWhenCreatingAShopList"); + } - int numPlayer = Clamp(config.getInt("Shop.NumberOfPlayer"), 3, 100); - config.set("Shop.NumberOfPlayer", numPlayer); + // [ Shop ] ========== - ConvertV2toV3(); + public static int GetSalesTax() + { + return DynamicShop.plugin.getConfig().getInt("Shop.SalesTax"); + } + + public static void SetSalesTax(int value) + { + DynamicShop.plugin.getConfig().set("Shop.SalesTax", value); + } + + public static double GetDeliveryChargeScale() + { + return DynamicShop.plugin.getConfig().getDouble("Shop.DeliveryChargeScale"); + } + + public static void SetDeliveryChargeScale(double value) + { + DynamicShop.plugin.getConfig().set("Shop.DeliveryChargeScale", value); + } + + public static int GetDeliveryChargeMin() + { + return DynamicShop.plugin.getConfig().getInt("Shop.DeliveryChargeMin"); + } + + public static void SetDeliveryChargeMin(int value) + { + DynamicShop.plugin.getConfig().set("Shop.DeliveryChargeMin", value); + } + + public static int GetDeliveryChargeMax() + { + return DynamicShop.plugin.getConfig().getInt("Shop.DeliveryChargeMax"); + } + + public static void SetDeliveryChargeMax(int value) + { + DynamicShop.plugin.getConfig().set("Shop.DeliveryChargeMax", value); + } + + public static int GetNumberOfPlayer() + { + return DynamicShop.plugin.getConfig().getInt("Shop.NumberOfPlayer"); + } + + public static void SetNumberOfPlayer(int value) + { + DynamicShop.plugin.getConfig().set("Shop.NumberOfPlayer", value); + } + + public static boolean GetUseLegacyStockStabilization() + { + return DynamicShop.plugin.getConfig().getBoolean("Shop.UseLegacyStockStabilization"); + } + + // [ UI ] ========== + + public static boolean GetDisplayStockAsStack() + { + return DynamicShop.plugin.getConfig().getBoolean("UI.DisplayStockAsStack"); + } + + public static boolean GetOpenStartPageWhenClickCloseButton() + { + return DynamicShop.plugin.getConfig().getBoolean("UI.OpenStartPageWhenClickCloseButton"); + } + + public static String GetCloseButtonIcon() + { + return DynamicShop.plugin.getConfig().getString("UI.CloseButtonIcon"); + } - dynamicShop.saveConfig(); + public static void SetCloseButtonIcon(String value) + { + DynamicShop.plugin.getConfig().set("UI.CloseButtonIcon", value); + } + + public static String GetPageButtonIcon() + { + return DynamicShop.plugin.getConfig().getString("UI.PageButtonIcon"); + } + + public static void SetPageButtonIcon(String value) + { + DynamicShop.plugin.getConfig().set("UI.PageButtonIcon", value); + } + + public static String GetShopInfoButtonIcon() + { + return DynamicShop.plugin.getConfig().getString("UI.ShopInfoButtonIcon"); + } + + public static void SetShopInfoButtonIcon(String value) + { + DynamicShop.plugin.getConfig().set("UI.ShopInfoButtonIcon", value); + } + + public static String GetIntFormat() + { + return DynamicShop.plugin.getConfig().getString("UI.IntFormat"); + } + + public static String GetDoubleFormat() + { + return DynamicShop.plugin.getConfig().getString("UI.DoubleFormat"); + } + + public static boolean GetLocalizedItemName() + { + return DynamicShop.plugin.getConfig().getBoolean("UI.LocalizedItemName"); + } + + public static boolean GetUsePlaceholderAPI() + { + return DynamicShop.plugin.getConfig().getBoolean("UI.UsePlaceholderAPI"); + } + + public static boolean GetUseHexColorCode() + { + return DynamicShop.plugin.getConfig().getBoolean("UI.UseHexColorCode"); + } + + public static boolean GetEnableInventoryClickSearch_StartPage() + { + return DynamicShop.plugin.getConfig().getBoolean("UI.EnableInventoryClickSearch.StartPage"); + } + + public static boolean GetEnableInventoryClickSearch_Shop() + { + return DynamicShop.plugin.getConfig().getBoolean("UI.EnableInventoryClickSearch.Shop"); + } + + // [ Log ] ========== + + public static boolean GetSaveLogs() + { + return DynamicShop.plugin.getConfig().getBoolean("Log.SaveLogs"); + } + + public static String GetLogFileNameFormat() + { + return DynamicShop.plugin.getConfig().getString("Log.LogFileNameFormat"); + } + + public static boolean GetCullLogs() + { + return DynamicShop.plugin.getConfig().getBoolean("Log.CullLogs"); + } + + public static int GetLogCullAgeMinutes() + { + return DynamicShop.plugin.getConfig().getInt("Log.LogCullAgeMinutes"); + } + + public static int GetLogCullTimeMinutes() + { + return DynamicShop.plugin.getConfig().getInt("Log.LogCullTimeMinutes"); + } + + // [ ShopYmlBackup ] ========== + + public static boolean GetShopYmlBackup_Enable() + { + return DynamicShop.plugin.getConfig().getBoolean("ShopYmlBackup.Enable"); + } + + public static int GetShopYmlBackup_IntervalMinutes() + { + return DynamicShop.plugin.getConfig().getInt("ShopYmlBackup.IntervalMinutes"); + } + + public static int GetShopYmlBackup_CullAgeMinutes() + { + return DynamicShop.plugin.getConfig().getInt("ShopYmlBackup.CullAgeMinutes"); } + // ============================================================ + + private static void ValidateAndApply() + { + DynamicShop.dsPrefix_ = GetPrefix(); + + SetSalesTax(Clamp(GetSalesTax(), 0, 99)); + setCurrentTax(GetSalesTax()); + + if (GetDeliveryChargeScale() < 0.01) + SetDeliveryChargeScale(0.01f); + + if (GetDeliveryChargeMin() < 1) + SetDeliveryChargeMin(1); + + if (GetDeliveryChargeMax() < 1) + SetDeliveryChargeMax(1); + + if (GetDeliveryChargeMax() < GetDeliveryChargeMin()) + SetDeliveryChargeMax(GetDeliveryChargeMin()); + + SetNumberOfPlayer(Clamp(GetNumberOfPlayer(), 3, 100)); + } + + @Getter + @Setter + private static int currentTax; + public static void resetTax() { - currentTax = DynamicShop.plugin.getConfig().getInt("Shop.SalesTax"); + currentTax = GetSalesTax(); } + // ============================================================ + private static void ConvertV2toV3() { - FileConfiguration config = DynamicShop.plugin.getConfig(); + if (DynamicShop.plugin.getConfig().get("ShowTax") != null) + { + DynamicShop.plugin.getConfig().set("ShowTax", null); + } - if(config.get("ShowTax") != null) + if (DynamicShop.plugin.getConfig().get("UseShopCommand") != null) { - config.set("ShowTax", null); + DynamicShop.plugin.getConfig().set("Command.UseShopCommand", DynamicShop.plugin.getConfig().get("UseShopCommand")); + DynamicShop.plugin.getConfig().set("UseShopCommand", null); } - if(config.get("UseShopCommand") != null) + if (DynamicShop.plugin.getConfig().get("OpenStartPageInsteadOfDefaultShop") != null) { - config.set("Command.UseShopCommand", config.get("UseShopCommand")); - config.set("UseShopCommand", null); + DynamicShop.plugin.getConfig().set("Command.OpenStartPageInsteadOfDefaultShop", DynamicShop.plugin.getConfig().get("OpenStartPageInsteadOfDefaultShop")); + DynamicShop.plugin.getConfig().set("OpenStartPageInsteadOfDefaultShop", null); } - if(config.get("OpenStartPageInsteadOfDefaultShop") != null) + if (DynamicShop.plugin.getConfig().get("DefaultShopName") != null) { - config.set("Command.OpenStartPageInsteadOfDefaultShop", config.get("OpenStartPageInsteadOfDefaultShop")); - config.set("OpenStartPageInsteadOfDefaultShop", null); + DynamicShop.plugin.getConfig().set("Command.DefaultShopName", DynamicShop.plugin.getConfig().get("DefaultShopName")); + DynamicShop.plugin.getConfig().set("DefaultShopName", null); } - if(config.get("DefaultShopName") != null) + if (DynamicShop.plugin.getConfig().get("SalesTax") != null) { - config.set("Command.DefaultShopName", config.get("DefaultShopName")); - config.set("DefaultShopName", null); + DynamicShop.plugin.getConfig().set("Shop.SalesTax", DynamicShop.plugin.getConfig().get("SalesTax")); + DynamicShop.plugin.getConfig().set("SalesTax", null); } - if(config.get("SalesTax") != null) + if (DynamicShop.plugin.getConfig().get("DeliveryChargeScale") != null) { - config.set("Shop.SalesTax", config.get("SalesTax")); - config.set("SalesTax", null); + DynamicShop.plugin.getConfig().set("Shop.DeliveryChargeScale", DynamicShop.plugin.getConfig().get("DeliveryChargeScale")); + DynamicShop.plugin.getConfig().set("DeliveryChargeScale", null); } - if(config.get("DeliveryChargeScale") != null) + if (DynamicShop.plugin.getConfig().get("NumberOfPlayer") != null) { - config.set("Shop.DeliveryChargeScale", config.get("DeliveryChargeScale")); - config.set("DeliveryChargeScale", null); + DynamicShop.plugin.getConfig().set("Shop.NumberOfPlayer", DynamicShop.plugin.getConfig().get("NumberOfPlayer")); + DynamicShop.plugin.getConfig().set("NumberOfPlayer", null); } - if(config.get("NumberOfPlayer") != null) + if (DynamicShop.plugin.getConfig().get("DisplayStockAsStack") != null) { - config.set("Shop.NumberOfPlayer", config.get("NumberOfPlayer")); - config.set("NumberOfPlayer", null); + DynamicShop.plugin.getConfig().set("UI.DisplayStockAsStack", DynamicShop.plugin.getConfig().get("DisplayStockAsStack")); + DynamicShop.plugin.getConfig().set("DisplayStockAsStack", null); } - if(config.get("DisplayStockAsStack") != null) + if (DynamicShop.plugin.getConfig().get("OnClickCloseButton_OpenStartPage") != null) { - config.set("UI.DisplayStockAsStack", config.get("DisplayStockAsStack")); - config.set("DisplayStockAsStack", null); + DynamicShop.plugin.getConfig().set("UI.OpenStartPageWhenClickCloseButton", DynamicShop.plugin.getConfig().get("OnClickCloseButton_OpenStartPage")); + DynamicShop.plugin.getConfig().set("OnClickCloseButton_OpenStartPage", null); } - if(config.get("OnClickCloseButton_OpenStartPage") != null) + if (DynamicShop.plugin.getConfig().get("ShopInfoButtonIcon") != null) { - config.set("UI.OpenStartPageWhenClickCloseButton", config.get("OnClickCloseButton_OpenStartPage")); - config.set("OnClickCloseButton_OpenStartPage", null); + DynamicShop.plugin.getConfig().set("UI.ShopInfoButtonIcon", DynamicShop.plugin.getConfig().get("ShopInfoButtonIcon")); + DynamicShop.plugin.getConfig().set("ShopInfoButtonIcon", null); } - if(config.get("ShopInfoButtonIcon") != null) + if (DynamicShop.plugin.getConfig().get("SaveLogs") != null) { - config.set("UI.ShopInfoButtonIcon", config.get("ShopInfoButtonIcon")); - config.set("ShopInfoButtonIcon", null); + DynamicShop.plugin.getConfig().set("Log.SaveLogs", DynamicShop.plugin.getConfig().get("SaveLogs")); + DynamicShop.plugin.getConfig().set("SaveLogs", null); } - if(config.get("SaveLogs") != null) + if (DynamicShop.plugin.getConfig().get("CullLogs") != null) { - config.set("Log.SaveLogs", config.get("SaveLogs")); - config.set("SaveLogs", null); + DynamicShop.plugin.getConfig().set("Log.CullLogs", DynamicShop.plugin.getConfig().get("CullLogs")); + DynamicShop.plugin.getConfig().set("CullLogs", null); } - if(config.get("CullLogs") != null) + if (DynamicShop.plugin.getConfig().get("LogCullAgeMinutes") != null) { - config.set("Log.CullLogs", config.get("CullLogs")); - config.set("CullLogs", null); + DynamicShop.plugin.getConfig().set("Log.LogCullAgeMinutes", DynamicShop.plugin.getConfig().get("LogCullAgeMinutes")); + DynamicShop.plugin.getConfig().set("LogCullAgeMinutes", null); } - if(config.get("LogCullAgeMinutes") != null) + if (DynamicShop.plugin.getConfig().get("LogCullTimeMinutes") != null) { - config.set("Log.LogCullAgeMinutes", config.get("LogCullAgeMinutes")); - config.set("LogCullAgeMinutes", null); + DynamicShop.plugin.getConfig().set("Log.LogCullTimeMinutes", DynamicShop.plugin.getConfig().get("LogCullTimeMinutes")); + DynamicShop.plugin.getConfig().set("LogCullTimeMinutes", null); } + } - if(config.get("LogCullTimeMinutes") != null) + private static void ShopYMLUpdate() + { + int userVersion = ConfigUtil.GetConfigVersion(); + if (userVersion == 3) { - config.set("Log.LogCullTimeMinutes", config.get("LogCullTimeMinutes")); - config.set("LogCullTimeMinutes", null); + for(Map.Entry entry : ShopUtil.shopConfigFiles.entrySet()) + { + ConfigurationSection cmdCS = entry.getValue().get().getConfigurationSection("Options.command"); + if(cmdCS == null) + continue; + + boolean somethingChanged = false; + if(cmdCS.contains("sell") && !cmdCS.contains("sell.0")) + { + cmdCS.set("sell.0", cmdCS.get("sell")); + somethingChanged = true; + } + if(cmdCS.contains("buy") && !cmdCS.contains("buy.0")) + { + cmdCS.set("buy.0", cmdCS.get("buy")); + somethingChanged = true; + } + + if(somethingChanged) + entry.getValue().save(); + } } } } diff --git a/src/main/java/me/sat7/dynamicshop/utilities/LangUtil.java b/src/main/java/me/sat7/dynamicshop/utilities/LangUtil.java index 45dc3cf..67d98fa 100644 --- a/src/main/java/me/sat7/dynamicshop/utilities/LangUtil.java +++ b/src/main/java/me/sat7/dynamicshop/utilities/LangUtil.java @@ -857,7 +857,7 @@ public static String t(Player player, String key, boolean hexConvert) if(temp == null || temp.isEmpty()) return key; - if (hexConvert && DynamicShop.plugin.getConfig().getBoolean("UI.UseHexColorCode")) + if (hexConvert && ConfigUtil.GetUseHexColorCode()) { Matcher matcher = HEX_PATTERN.matcher(temp); while (matcher.find()) @@ -866,7 +866,7 @@ public static String t(Player player, String key, boolean hexConvert) } } - if(player != null && DynamicShop.isPapiExist && DynamicShop.plugin.getConfig().getBoolean("UI.UsePlaceholderAPI")) + if(player != null && DynamicShop.isPapiExist && ConfigUtil.GetUsePlaceholderAPI()) return PlaceholderAPI.setPlaceholders(player, temp); else return temp; @@ -893,7 +893,7 @@ public static boolean sendMessageWithLocalizedItemName(Player player, String mes } String[] splitByRegex = null; - if(DynamicShop.plugin.getConfig().getBoolean("UI.UseHexColorCode")) + if(ConfigUtil.GetUseHexColorCode()) splitByRegex = HEX_PATTERN.split(message); if(splitByRegex != null && splitByRegex.length > 1) @@ -962,8 +962,8 @@ public static boolean sendMessageWithLocalizedItemName(Player player, String mes private static void ReloadNumberFormat() { - intFormat = new DecimalFormat(DynamicShop.plugin.getConfig().getString("UI.IntFormat", "###,###")); - doubleFormat = new DecimalFormat(DynamicShop.plugin.getConfig().getString("UI.DoubleFormat", "###,###.##")); + intFormat = new DecimalFormat(ConfigUtil.GetIntFormat()); + doubleFormat = new DecimalFormat(ConfigUtil.GetDoubleFormat()); } private static DecimalFormat intFormat; diff --git a/src/main/java/me/sat7/dynamicshop/utilities/LogUtil.java b/src/main/java/me/sat7/dynamicshop/utilities/LogUtil.java index 970b643..2285fe5 100644 --- a/src/main/java/me/sat7/dynamicshop/utilities/LogUtil.java +++ b/src/main/java/me/sat7/dynamicshop/utilities/LogUtil.java @@ -29,7 +29,7 @@ private LogUtil() // 거래 로그 기록 public static void addLog(String shopName, String itemName, int amount, double value, String curr, String player) { - if (DynamicShop.plugin.getConfig().getBoolean("Log.SaveLogs")) + if (ConfigUtil.GetSaveLogs()) { CustomConfig data = ShopUtil.shopConfigFiles.get(shopName); @@ -68,23 +68,6 @@ public static void addLog(String shopName, String itemName, int amount, double v { Bukkit.getServer().broadcast(message, Constants.P_ADMIN_SHOP_EDIT); } - - - //boolean useLocalizedName = DynamicShop.plugin.getConfig().getBoolean("UI.LocalizedItemName"); - //String message = DynamicShop.dsPrefix(null) + t(null, "LOG.SELL", !useLocalizedName) - // .replace("{player}", player) - // .replace("{shop}", shopName) - // .replace("{amount}", amount + ""); - - //if (useLocalizedName) - //{ - // message = message.replace("{item}", ""); - // - // LangUtil.sendMessageWithLocalizedItemName(player, message, Material.getMaterial(itemName)); - //} else - //{ - // message = message.replace("{item}", itemName); - //} } } } @@ -125,7 +108,7 @@ public static void SaveLogToCSV() private static String CreatePath(String shopName) { - SimpleDateFormat sdf = new SimpleDateFormat(DynamicShop.plugin.getConfig().getString("Log.LogFileNameFormat")); + SimpleDateFormat sdf = new SimpleDateFormat(ConfigUtil.GetLogFileNameFormat()); String timeForFileName = sdf.format(System.currentTimeMillis()); return DynamicShop.plugin.getDataFolder() + "/Log/" + shopName + "/" + timeForFileName + ".csv"; } @@ -157,7 +140,7 @@ public static void cullLogs() continue; int ageMins = (int) (System.currentTimeMillis() - log.lastModified()) / 60000; - if (ageMins > DynamicShop.plugin.getConfig().getInt("Log.LogCullAgeMinutes")) + if (ageMins > ConfigUtil.GetLogCullAgeMinutes()) { if (log.delete()) deleted++; @@ -168,8 +151,8 @@ public static void cullLogs() if (deleted > 0) { DynamicShop.console.sendMessage(Constants.DYNAMIC_SHOP_PREFIX + - " Found and deleted " + deleted + " log file(s) older than " + DynamicShop.plugin.getConfig().getInt("Log.LogCullAgeMinutes") + - " minutes. Checking again in " + DynamicShop.plugin.getConfig().getInt("Log.LogCullTimeMinutes") + " minutes."); + " Found and deleted " + deleted + " log file(s) older than " + ConfigUtil.GetLogCullAgeMinutes() + + " minutes. Checking again in " + ConfigUtil.GetLogCullTimeMinutes() + " minutes."); } } } diff --git a/src/main/java/me/sat7/dynamicshop/utilities/ShopUtil.java b/src/main/java/me/sat7/dynamicshop/utilities/ShopUtil.java index 200f6db..f3e99b7 100644 --- a/src/main/java/me/sat7/dynamicshop/utilities/ShopUtil.java +++ b/src/main/java/me/sat7/dynamicshop/utilities/ShopUtil.java @@ -606,8 +606,7 @@ public static void SetToRecommendedValueAll(String shop, CommandSender sender) if (worth != 0) { - int numberOfPlayer = DynamicShop.plugin.getConfig().getInt("Shop.NumberOfPlayer"); - int sugMid = CalcRecommendedMedian(worth, numberOfPlayer); + int sugMid = CalcRecommendedMedian(worth, ConfigUtil.GetNumberOfPlayer()); ShopUtil.editShopItem(shop, i, worth, worth, 0.01f, -1, sugMid, sugMid); } else @@ -839,7 +838,7 @@ public static int GetShopMaxPage(String shopName) private static int randomStockTimer = 1; public static void randomChange(Random generator) { - boolean legacyStabilizer = DynamicShop.plugin.getConfig().getBoolean("Shop.UseLegacyStockStabilization"); + boolean legacyStabilizer = ConfigUtil.GetUseLegacyStockStabilization(); // 인게임 30분마다 실행됨 (500틱) randomStockTimer += 1; @@ -1010,8 +1009,8 @@ public static int CalcShipping(String shopName, Player player) } else if (outside) { Location lo = new Location(player.getWorld(), x1, y1, z1); - int dist = (int) (player.getLocation().distance(lo) * 0.1 * DynamicShop.plugin.getConfig().getDouble("Shop.DeliveryChargeScale")); - deliverycharge = Clamp(dist, DynamicShop.plugin.getConfig().getInt("Shop.DeliveryChargeMin"), DynamicShop.plugin.getConfig().getInt("Shop.DeliveryChargeMax")); + int dist = (int) (player.getLocation().distance(lo) * 0.1 * ConfigUtil.GetDeliveryChargeScale()); + deliverycharge = Clamp(dist, ConfigUtil.GetDeliveryChargeMin(), ConfigUtil.GetDeliveryChargeMax()); } } diff --git a/src/main/java/me/sat7/dynamicshop/utilities/TabCompleteUtil.java b/src/main/java/me/sat7/dynamicshop/utilities/TabCompleteUtil.java index 430b7b5..0154967 100644 --- a/src/main/java/me/sat7/dynamicshop/utilities/TabCompleteUtil.java +++ b/src/main/java/me/sat7/dynamicshop/utilities/TabCompleteUtil.java @@ -42,7 +42,7 @@ public static List onTabCompleteBody(DynamicShop dynamicShop, CommandSen if (cmd.getName().equalsIgnoreCase("shop") && args.length == 1) { - if (!dynamicShop.getConfig().getBoolean("Command.UseShopCommand")) return autoCompleteList; + if (!ConfigUtil.GetUseShopCommand()) return autoCompleteList; for (Map.Entry entry : ShopUtil.shopConfigFiles.entrySet()) { @@ -56,7 +56,7 @@ public static List onTabCompleteBody(DynamicShop dynamicShop, CommandSen String permission = options.getString("permission", ""); if (permission.isEmpty() - || !DynamicShop.plugin.getConfig().getBoolean("Command.PermissionCheckWhenCreatingAShopList") + || !ConfigUtil.GetPermissionCheckWhenCreatingAShopList() || p.hasPermission(permission)) temp.add(entry.getKey()); } @@ -109,7 +109,7 @@ public static List onTabCompleteBody(DynamicShop dynamicShop, CommandSen String permission = options.getString("permission", ""); if (permission.isEmpty() - || !DynamicShop.plugin.getConfig().getBoolean("Command.PermissionCheckWhenCreatingAShopList") + || !ConfigUtil.GetPermissionCheckWhenCreatingAShopList() || p.hasPermission(permission)) temp.add(entry.getKey()); } diff --git a/src/main/resources/config.yml b/src/main/resources/config.yml index d7829ca..0465fb9 100644 --- a/src/main/resources/config.yml +++ b/src/main/resources/config.yml @@ -1,18 +1,15 @@ Language: en-US Prefix: §3DShop3 §7| §f - Command.UseShopCommand: true Command.OpenStartPageInsteadOfDefaultShop: true Command.DefaultShopName: SampleShop Command.PermissionCheckWhenCreatingAShopList: false - Shop.SalesTax: 25 Shop.DeliveryChargeScale: 0.3 Shop.DeliveryChargeMin: 1 Shop.DeliveryChargeMax: 25 Shop.NumberOfPlayer: 10 Shop.UseLegacyStockStabilization: false - UI.DisplayStockAsStack: false UI.OpenStartPageWhenClickCloseButton: true UI.CloseButtonIcon : BARRIER @@ -25,7 +22,6 @@ UI.UsePlaceholderAPI : true UI.UseHexColorCode : true UI.EnableInventoryClickSearch.StartPage: true UI.EnableInventoryClickSearch.Shop: true - Log.SaveLogs: true Log.LogFileNameFormat: MM_dd_yyyy Log.CullLogs: true