diff --git a/pom.xml b/pom.xml index 3d9fab1..f7e3f3c 100644 --- a/pom.xml +++ b/pom.xml @@ -6,7 +6,7 @@ me.sat7 DynamicShop - 3.11.2 + 3.12.0 jar DynamicShop diff --git a/src/main/java/me/sat7/dynamicshop/DynaShopAPI.java b/src/main/java/me/sat7/dynamicshop/DynaShopAPI.java index 30fed58..366adf7 100644 --- a/src/main/java/me/sat7/dynamicshop/DynaShopAPI.java +++ b/src/main/java/me/sat7/dynamicshop/DynaShopAPI.java @@ -103,9 +103,9 @@ public static void openItemPalette(Player player, int uiSubType, String shopName } // 아이탬 셋팅창 - public static void openItemSettingGui(Player player, String shopName, int shopSlotIndex, int tab, ItemStack itemStack, double buyValue, double sellValue, double minPrice, double maxPrice, int median, int stock, int maxStock) + public static void openItemSettingGui(Player player, String shopName, int shopSlotIndex, int tab, ItemStack itemStack, double buyValue, double sellValue, double minPrice, double maxPrice, int median, int stock, int maxStock, int discount) { - DSItem dsItem = new DSItem(itemStack, buyValue, sellValue, minPrice, maxPrice, median, stock, maxStock); + DSItem dsItem = new DSItem(itemStack, buyValue, sellValue, minPrice, maxPrice, median, stock, maxStock, discount); openItemSettingGui(player, shopName, shopSlotIndex, tab, dsItem); } diff --git a/src/main/java/me/sat7/dynamicshop/DynamicShop.java b/src/main/java/me/sat7/dynamicshop/DynamicShop.java index 7a6b84b..40ab480 100644 --- a/src/main/java/me/sat7/dynamicshop/DynamicShop.java +++ b/src/main/java/me/sat7/dynamicshop/DynamicShop.java @@ -452,7 +452,7 @@ private void InitConfig() ConfigUtil.Load(); - LangUtil.setupLangFile(ConfigUtil.GetLanguage()); + LangUtil.setupLangFile(ConfigUtil.GetLanguage()); // ConfigUtil.Load() 보다 밑에 있어야함. LayoutUtil.Setup(); setupUserFile(); diff --git a/src/main/java/me/sat7/dynamicshop/commands/Reload.java b/src/main/java/me/sat7/dynamicshop/commands/Reload.java index dd8b72b..019a75f 100644 --- a/src/main/java/me/sat7/dynamicshop/commands/Reload.java +++ b/src/main/java/me/sat7/dynamicshop/commands/Reload.java @@ -51,6 +51,7 @@ public void RunCMD(String[] args, CommandSender sender) SoundUtil.setupSoundFile(); ConfigUtil.Load(); + DynamicShop.plugin.PeriodicRepetitiveTask(); DynamicShop.plugin.startSaveLogsTask(); @@ -60,7 +61,7 @@ public void RunCMD(String[] args, CommandSender sender) QuickSell.quickSellGui.reload(); QuickSell.SetupQuickSellGUIFile(); - LangUtil.setupLangFile(ConfigUtil.GetLanguage()); + LangUtil.setupLangFile(ConfigUtil.GetLanguage()); // ConfigUtil.Load() 보다 밑에 있어야함. sender.sendMessage(DynamicShop.dsPrefix(sender) + t(sender, "HELP.RELOADED")); } diff --git a/src/main/java/me/sat7/dynamicshop/commands/RenameShop.java b/src/main/java/me/sat7/dynamicshop/commands/RenameShop.java index fbf8673..021c6eb 100644 --- a/src/main/java/me/sat7/dynamicshop/commands/RenameShop.java +++ b/src/main/java/me/sat7/dynamicshop/commands/RenameShop.java @@ -1,6 +1,8 @@ package me.sat7.dynamicshop.commands; +import me.sat7.dynamicshop.guis.StartPage; import org.bukkit.command.CommandSender; +import org.bukkit.configuration.ConfigurationSection; import org.bukkit.entity.Player; import me.sat7.dynamicshop.DynamicShop; @@ -30,7 +32,7 @@ public void SendHelpMessage(Player player) @Override public void RunCMD(String[] args, CommandSender sender) { - if(!CheckValid(args, sender)) + if (!CheckValid(args, sender)) return; if (ShopUtil.shopConfigFiles.containsKey(args[1])) @@ -44,7 +46,28 @@ public void RunCMD(String[] args, CommandSender sender) String newName = args[2].replace("/", ""); ShopUtil.renameShop(args[1], newName); sender.sendMessage(DynamicShop.dsPrefix(sender) + t(sender, "MESSAGE.CHANGES_APPLIED") + newName); - } else + + ConfigurationSection cs = StartPage.ccStartPage.get().getConfigurationSection("Buttons"); + if (cs != null) + { + for (String c : cs.getKeys(false)) + { + String actionString = cs.getString(c + ".action"); + if (actionString == null || !actionString.contains(args[1]) || !actionString.contains("ds shop")) + continue; + + cs.set(c + ".action", actionString.replace(args[1], args[2])); + + String nameString = cs.getString(c + ".displayName"); + if (nameString == null || !nameString.contains(args[1])) + continue; + + cs.set(c + ".displayName", nameString.replace(args[1], args[2])); + } + StartPage.ccStartPage.save(); + } + } + else { sender.sendMessage(DynamicShop.dsPrefix(sender) + t(sender, "ERR.SHOP_NOT_FOUND")); } diff --git a/src/main/java/me/sat7/dynamicshop/commands/shop/EditAll.java b/src/main/java/me/sat7/dynamicshop/commands/shop/EditAll.java index 353afd4..9e10e91 100644 --- a/src/main/java/me/sat7/dynamicshop/commands/shop/EditAll.java +++ b/src/main/java/me/sat7/dynamicshop/commands/shop/EditAll.java @@ -24,7 +24,7 @@ public EditAll() public void SendHelpMessage(Player player) { player.sendMessage(DynamicShop.dsPrefix(player) + t(player, "HELP.TITLE").replace("{command}", "editall")); - player.sendMessage(" - " + t(player, "HELP.USAGE") + ": ... editall <= | + | - | * | /> "); + player.sendMessage(" - " + t(player, "HELP.USAGE") + ": ... editall <= | + | - | * | /> "); player.sendMessage(" - " + t(player, "HELP.EDIT_ALL")); player.sendMessage(""); @@ -52,7 +52,7 @@ public void RunCMD(String[] args, CommandSender sender) try { dataType = args[3]; - if (!dataType.equals("stock") && !dataType.equals("median") && !dataType.equals("purchaseValue") && !dataType.equals("salesValue") && !dataType.equals("valueMin") && !dataType.equals("valueMax") && !dataType.equals("maxStock")) + if (!dataType.equals("stock") && !dataType.equals("median") && !dataType.equals("purchaseValue") && !dataType.equals("salesValue") && !dataType.equals("valueMin") && !dataType.equals("valueMax") && !dataType.equals("maxStock") && !dataType.equals("discount")) { sender.sendMessage(DynamicShop.dsPrefix(sender) + t(sender, "ERR.WRONG_DATATYPE")); return; @@ -72,6 +72,12 @@ public void RunCMD(String[] args, CommandSender sender) if (!args[5].equals("stock") && !args[5].equals("median") && !args[5].equals("purchaseValue") && !args[5].equals("salesValue") && !args[5].equals("valueMin") && !args[5].equals("valueMax") && !args[5].equals("maxStock")) newValue = Double.parseDouble(args[5]); + + if (args[3].equals("discount") && args[5].length() > 3) + { + sender.sendMessage(DynamicShop.dsPrefix(sender) + t(sender, "ERR.WRONG_DATATYPE")); + return; + } } catch (Exception e) { @@ -115,6 +121,9 @@ public void RunCMD(String[] args, CommandSender sender) case "maxStock": newValue = shopData.get().getInt(s + ".maxStock", -1); break; + case "discount": + newValue = shopData.get().getInt(s + ".discount", 0); + break; } if (newValue < 0) @@ -149,7 +158,7 @@ else if (mod.equalsIgnoreCase("*")) result = 0.01; } - if (dataType.equals("stock") || dataType.equals("median") || dataType.equals("maxStock")) + if (dataType.equals("stock") || dataType.equals("median") || dataType.equals("maxStock") || dataType.equals("discount")) { int intResult = (int)result; shopData.get().set(s + "." + dataType, intResult); @@ -172,6 +181,14 @@ else if (mod.equalsIgnoreCase("*")) { shopData.get().set(s + ".maxStock", null); } + if (shopData.get().getDouble(s + ".discount") > 90) + { + shopData.get().set(s + ".discount", 90); + } + if (shopData.get().getDouble(s + ".discount") <= 0) + { + shopData.get().set(s + ".discount", null); + } Double value2 = shopData.get().getDouble(s + ".value2"); if (value2 < 0 || value2.equals(shopData.get().getDouble(s + ".value"))) diff --git a/src/main/java/me/sat7/dynamicshop/guis/ItemPalette.java b/src/main/java/me/sat7/dynamicshop/guis/ItemPalette.java index be2f42b..3c1190e 100644 --- a/src/main/java/me/sat7/dynamicshop/guis/ItemPalette.java +++ b/src/main/java/me/sat7/dynamicshop/guis/ItemPalette.java @@ -432,7 +432,7 @@ private void OnClickItem(boolean isLeft, boolean isRight, boolean isShift, ItemS { if (isShift) { - DynaShopAPI.openItemSettingGui(player, shopName, shopSlotIndex,0, itemStack, 10, 10, 0.01, -1, 10000, 10000, -1); + DynaShopAPI.openItemSettingGui(player, shopName, shopSlotIndex,0, itemStack, 10, 10, 0.01, -1, 10000, 10000, -1, 0); } else { int targetSlotIdx = ShopUtil.findEmptyShopSlot(shopName, shopSlotIndex, true); @@ -491,7 +491,7 @@ private void OnClickUserItem(boolean isLeft, boolean isRight, ItemStack item) { if (isLeft) { - DynaShopAPI.openItemSettingGui(player, shopName, shopSlotIndex, 0, item, 10, 10, 0.01, -1, 10000, 10000, -1); + DynaShopAPI.openItemSettingGui(player, shopName, shopSlotIndex, 0, item, 10, 10, 0.01, -1, 10000, 10000, -1, 0); } else if (isRight) { ShopUtil.addItemToShop(shopName, shopSlotIndex, item, -1, -1, -1, -1, -1, -1); diff --git a/src/main/java/me/sat7/dynamicshop/guis/ItemSettings.java b/src/main/java/me/sat7/dynamicshop/guis/ItemSettings.java index 2298bc0..7c82c2f 100644 --- a/src/main/java/me/sat7/dynamicshop/guis/ItemSettings.java +++ b/src/main/java/me/sat7/dynamicshop/guis/ItemSettings.java @@ -31,9 +31,10 @@ public ItemSettings() private final int SAMPLE_ITEM = 0; private final int DONE = 8; - private final int CLOSE = 27; - private final int RECOMMEND = 31; - private final int REMOVE = 35; + private final int CLOSE = 45; + private final int DISCOUNT = 47; + private final int RECOMMEND = 49; + private final int REMOVE = 53; private final int BUY_VALUE = 1; private final int SELL_VALUE = 2; @@ -45,12 +46,12 @@ public ItemSettings() private final int TAB_START = BUY_VALUE; private final int TAB_END = MAX_STOCK; - private final int RESET = 13; - private final int ROUND_DOWN = 20; - private final int DIVIDE = 21; - private final int SHIFT = 22; - private final int MULTIPLY = 23; - private final int SET_TO_OTHER = 24; + private final int RESET = 22; + private final int ROUND_DOWN = 29; + private final int DIVIDE = 30; + private final int SHIFT = 31; + private final int MULTIPLY = 32; + private final int SET_TO_OTHER = 33; private Player player; private String shopName; @@ -65,6 +66,7 @@ public ItemSettings() private int median; private int stock; private int maxStock; + private int discount; private boolean oldSbSame; @@ -76,7 +78,7 @@ public Inventory getGui(Player player, String shopName, int shopSlotIndex, int t this.dsItem = dsItem; this.currentTab = Clamp(tab, TAB_START, TAB_END); - inventory = Bukkit.createInventory(player, 36, t(player, "ITEM_SETTING_TITLE") + "§7 | §8" + shopName); + inventory = Bukkit.createInventory(player, 54, t(player, "ITEM_SETTING_TITLE") + "§7 | §8" + shopName); String buyValueStr = t(null, "ITEM_SETTING.VALUE_BUY") + n(dsItem.getBuyValue()); String sellValueStr = t(null, "ITEM_SETTING.VALUE_SELL") + n(dsItem.getSellValue()); @@ -204,26 +206,26 @@ public Inventory getGui(Player player, String shopName, int shopSlotIndex, int t if (currentTab <= MAX_VALUE) { - CreateButton(9, white, "-100", editBtnLore); - CreateButton(10, white, "-10", editBtnLore); - CreateButton(11, white, "-1", editBtnLore); - CreateButton(12, white, "-0.1", editBtnLore); - CreateButton(14, white, "+0.1", editBtnLore); - CreateButton(15, white, "+1", editBtnLore); - CreateButton(16, white, "+10", editBtnLore); - CreateButton(17, white, "+100", editBtnLore); + CreateButton(18, white, "-100", editBtnLore); + CreateButton(19, white, "-10", editBtnLore); + CreateButton(20, white, "-1", editBtnLore); + CreateButton(21, white, "-0.1", editBtnLore); + CreateButton(23, white, "+0.1", editBtnLore); + CreateButton(24, white, "+1", editBtnLore); + CreateButton(25, white, "+10", editBtnLore); + CreateButton(26, white, "+100", editBtnLore); if (currentTab >= SELL_VALUE) CreateButton(SET_TO_OTHER, yellow, t(null, "ITEM_SETTING.SET_TO_VALUE"), editBtnLore); } else { - CreateButton(9, white, "-1000", editBtnLore); - CreateButton(10, white, "-100", editBtnLore); - CreateButton(11, white, "-10", editBtnLore); - CreateButton(12, white, "-1", editBtnLore); - CreateButton(14, white, "+1", editBtnLore); - CreateButton(15, white, "+10", editBtnLore); - CreateButton(16, white, "+100", editBtnLore); - CreateButton(17, white, "+1000", editBtnLore); + CreateButton(18, white, "-1000", editBtnLore); + CreateButton(19, white, "-100", editBtnLore); + CreateButton(20, white, "-10", editBtnLore); + CreateButton(21, white, "-1", editBtnLore); + CreateButton(23, white, "+1", editBtnLore); + CreateButton(24, white, "+10", editBtnLore); + CreateButton(25, white, "+100", editBtnLore); + CreateButton(26, white, "+1000", editBtnLore); if (currentTab == MEDIAN) CreateButton(SET_TO_OTHER, yellow, t(null, "ITEM_SETTING.SET_TO_STOCK"), editBtnLore); else if (currentTab == STOCK) CreateButton(SET_TO_OTHER, yellow, t(null, "ITEM_SETTING.SET_TO_MEDIAN"), editBtnLore); @@ -263,6 +265,12 @@ public Inventory getGui(Player player, String shopName, int shopSlotIndex, int t + "§7 " + dsItem.getStock() + stockChanged + sugMid; } + discount = dsItem.getDiscount(); + Material discountMat = discount == 0 ? Material.IRON_NUGGET : Material.GOLD_NUGGET; + int discountMatAmount = discount/10; + if (discountMatAmount < 1) + discountMatAmount = 1; + CreateButton(DISCOUNT, discountMat, t(player, "ITEM_SETTING.DISCOUNT"), t(player, "ITEM_SETTING.DISCOUNT_LORE").replace("{num}", discount+""), discountMatAmount); CreateButton(RECOMMEND, Material.NETHER_STAR, t(player, "ITEM_SETTING.RECOMMEND"), recommendLore); // 추천 버튼 CreateButton(DONE, Material.STRUCTURE_VOID, t(player, "ITEM_SETTING.DONE"), t(player, "ITEM_SETTING.DONE_LORE")); // 완료 버튼 CreateButton(CLOSE, Material.BARRIER, t(player, "ITEM_SETTING.CLOSE"), t(player, "ITEM_SETTING.CLOSE_LORE")); // 닫기 버튼 @@ -294,9 +302,10 @@ public void OnClickUpperInventory(InventoryClickEvent e) if (e.getSlot() == CLOSE) DynaShopAPI.openShopGui(player, shopName, shopSlotIndex / 45 + 1); else if (e.getSlot() == REMOVE) RemoveItem(); else if (e.getSlot() == RECOMMEND) SetToRecommend(); + else if (e.getSlot() == DISCOUNT) OnDiscountButtonClick(e.isLeftClick()); else if (e.getSlot() >= TAB_START && e.getSlot() <= TAB_END) ChangeTab(e.getSlot()); else if (e.getSlot() == RESET) Reset(); - else if (e.getSlot() >= 9 && e.getSlot() < 18) PlusMinus(e.isShiftClick(), e.getCurrentItem()); // RESET 이 13인것에 주의 + else if (e.getSlot() >= 18 && e.getSlot() < 27) PlusMinus(e.isShiftClick(), e.getCurrentItem()); // RESET 이 22인것에 주의 else if (e.getSlot() == DIVIDE) Divide(e.isShiftClick()); else if (e.getSlot() == MULTIPLY) Multiply(e.isShiftClick()); else if (e.getSlot() == ROUND_DOWN) RoundDown(); @@ -338,6 +347,7 @@ private void SaveSetting() if (-1 != existSlot) { ShopUtil.editShopItem(shopName, existSlot, buyValue, sellValue, minValue, maxValue, median, stock, maxStock); + ShopUtil.setDiscount(shopName,existSlot, discount); DynaShopAPI.openShopGui(player, shopName, existSlot / 45 + 1); SoundUtil.playerSoundEffect(player, "addItem"); } else @@ -350,6 +360,7 @@ private void SaveSetting() if (idx != -1) { ShopUtil.addItemToShop(shopName, idx, inventory.getItem(SAMPLE_ITEM), buyValue, sellValue, minValue, maxValue, median, stock, maxStock); + ShopUtil.setDiscount(shopName,existSlot, discount); DynaShopAPI.openShopGui(player, shopName, shopSlotIndex / 45 + 1); SoundUtil.playerSoundEffect(player, "addItem"); } @@ -364,6 +375,16 @@ private void RemoveItem() SoundUtil.playerSoundEffect(player, "deleteItem"); } + private void OnDiscountButtonClick(boolean isLeftClick) + { + if (isLeftClick) + discount += 10; + else + discount -= 10; + + RefreshWindow(); + } + private void SetToRecommend() { double worth = TryGetWorth(dsItem.getItemStack().getType().name()); @@ -378,7 +399,7 @@ private void SetToRecommend() 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); + worth, worth, minValue, maxValue, sugMid, sugMid, maxStock, discount); } } @@ -612,12 +633,16 @@ private void ValueValidation() stock = -1; if (maxStock < -1) maxStock = -1; + if (discount < 0) + discount = 0; + if (discount > 90) + discount = 90; } private void RefreshWindow() { ValueValidation(); - DynaShopAPI.openItemSettingGui(player, shopName, shopSlotIndex, currentTab, inventory.getItem(SAMPLE_ITEM), buyValue, sellValue, minValue, maxValue, median, stock, maxStock); + DynaShopAPI.openItemSettingGui(player, shopName, shopSlotIndex, currentTab, inventory.getItem(SAMPLE_ITEM), buyValue, sellValue, minValue, maxValue, median, stock, maxStock, discount); SoundUtil.playerSoundEffect(player, "editItem"); } } diff --git a/src/main/java/me/sat7/dynamicshop/guis/ItemTrade.java b/src/main/java/me/sat7/dynamicshop/guis/ItemTrade.java index f10b387..36d3021 100644 --- a/src/main/java/me/sat7/dynamicshop/guis/ItemTrade.java +++ b/src/main/java/me/sat7/dynamicshop/guis/ItemTrade.java @@ -270,14 +270,44 @@ private void CreateTradeButtons(boolean sell) double price = Calc.calcTotalCost(shopName, tradeIdx, sell ? -amount : amount)[0]; String lore; String priceText; + + String currencyKey = ""; + if (shopData.contains("Options.flag.jobpoint")) + { + currencyKey = "_JP"; + } + else if (shopData.contains("Options.flag.playerpoint")) + { + currencyKey = "_PP"; + } + if (sell) { lore = l("TRADE_VIEW.SELL"); - priceText = t(player, "TRADE.SELL_PRICE").replace("{num}", n(price)); - } else + + if (shopData.contains(tradeIdx + ".discount")) + { + String original = n(price * 100 / (double) (100 - shopData.getInt(tradeIdx + ".discount"))); + priceText = t(player, "TRADE.SELL_PRICE_DISCOUNTED" + currencyKey).replace("{num}", original).replace("{num2}", n(price)); + } + else + { + priceText = t(player, "TRADE.SELL_PRICE" + currencyKey).replace("{num}", n(price)); + } + } + else { lore = l("TRADE_VIEW.BUY"); - priceText = t(player, "TRADE.PRICE").replace("{num}", n(price)); + + if (shopData.contains(tradeIdx + ".discount")) + { + String original = n(price * 100 / (double) (100 - shopData.getInt(tradeIdx + ".discount"))); + priceText = t(player, "TRADE.PRICE_DISCOUNTED" + currencyKey).replace("{num}", original).replace("{num2}", n(price)); + } + else + { + priceText = t(player, "TRADE.PRICE" + currencyKey).replace("{num}", n(price)); + } } if (!sell) @@ -299,23 +329,23 @@ private void CreateTradeButtons(boolean sell) { stockText = n(stock); } - } - String maxStockText; - if (shopData.contains("Options.flag.showmaxstock") && maxStock != -1) - { - if (ConfigUtil.GetDisplayStockAsStack()) + String maxStockText; + if (shopData.contains("Options.flag.showmaxstock") && maxStock != -1) { - maxStockText = t(player, "TRADE.STACKS").replace("{num}", n(maxStock / 64)); + if (ConfigUtil.GetDisplayStockAsStack()) + { + maxStockText = t(player, "TRADE.STACKS").replace("{num}", n(maxStock / 64)); + } else + { + maxStockText = n(maxStock); + } + + stockText = t(player, "SHOP.STOCK_2").replace("{stock}", stockText).replace("{max_stock}", maxStockText); } else { - maxStockText = n(maxStock); + stockText = t(player, "SHOP.STOCK").replace("{num}", stockText); } - - stockText = t(player, "SHOP.STOCK_2").replace("{stock}", stockText).replace("{max_stock}", maxStockText); - } else - { - stockText = t(player, "SHOP.STOCK").replace("{num}", stockText); } String deliveryChargeText = ""; diff --git a/src/main/java/me/sat7/dynamicshop/guis/Shop.java b/src/main/java/me/sat7/dynamicshop/guis/Shop.java index f2f982b..51d85f4 100644 --- a/src/main/java/me/sat7/dynamicshop/guis/Shop.java +++ b/src/main/java/me/sat7/dynamicshop/guis/Shop.java @@ -217,17 +217,44 @@ private void ShowItems() boolean showValueChange = shopData.contains("Options.flag.showvaluechange"); + String currencyKey = ""; + if (DynaShopAPI.isJobsPointShop(shopName)) + { + currencyKey = "_JP"; + } + else if (DynaShopAPI.isPlayerPointShop(shopName)) + { + currencyKey = "_PP"; + } + String buyText = ""; String sellText = ""; if (!tradeType.equalsIgnoreCase("SellOnly")) { - buyText = t(player, "SHOP.BUY_PRICE").replace("{num}", n(buyPrice)); + if(shopData.contains(s + ".discount")) + { + String original = n(buyPrice * 100 / (double) (100 - shopData.getInt(s + ".discount"))); + buyText = t(player, "SHOP.BUY_PRICE_DISCOUNTED" + currencyKey).replace("{num}", original).replace("{num2}", n(buyPrice)); + } + else + { + buyText = t(player, "SHOP.BUY_PRICE" + currencyKey).replace("{num}", n(buyPrice)); + } buyText += showValueChange ? " " + valueChanged_Buy : ""; } if (!tradeType.equalsIgnoreCase("BuyOnly")) { - sellText = t(player, "SHOP.SELL_PRICE").replace("{num}", n(sellPrice)); + if(shopData.contains(s + ".discount")) + { + String original = n(sellPrice * 100 / (double) (100 - shopData.getInt(s + ".discount"))); + sellText = t(player, "SHOP.SELL_PRICE_DISCOUNTED" + currencyKey).replace("{num}", original).replace("{num2}", n(sellPrice)); + } + else + { + sellText = t(player, "SHOP.SELL_PRICE" + currencyKey).replace("{num}", n(sellPrice)); + } + sellText += showValueChange ? " " + valueChanged_Sell : ""; } @@ -548,11 +575,12 @@ else if (e.isRightClick() && player.hasPermission(P_ADMIN_SHOP_EDIT)) int median = shopData.getInt(idx + ".median"); int stock = shopData.getInt(idx + ".stock"); int maxStock = shopData.getInt(idx + ".maxStock", -1); + int discount = shopData.getInt(idx + ".discount", 0); ItemStack iStack = new ItemStack(e.getCurrentItem().getType()); iStack.setItemMeta((ItemMeta) shopData.get(idx + ".itemStack")); - DynaShopAPI.openItemSettingGui(player, shopName, idx, 0, iStack, buyValue, sellValue, valueMin, valueMax, median, stock, maxStock); + DynaShopAPI.openItemSettingGui(player, shopName, idx, 0, iStack, buyValue, sellValue, valueMin, valueMax, median, stock, maxStock, discount); } else { ShopUtil.removeItemFromShop(shopName, idx); diff --git a/src/main/java/me/sat7/dynamicshop/guis/ShopList.java b/src/main/java/me/sat7/dynamicshop/guis/ShopList.java index 176fb24..7ae344a 100644 --- a/src/main/java/me/sat7/dynamicshop/guis/ShopList.java +++ b/src/main/java/me/sat7/dynamicshop/guis/ShopList.java @@ -5,10 +5,13 @@ import me.sat7.dynamicshop.utilities.ShopUtil; import org.bukkit.Bukkit; import org.bukkit.Material; +import org.bukkit.configuration.ConfigurationSection; import org.bukkit.entity.Player; import org.bukkit.event.inventory.InventoryClickEvent; import org.bukkit.inventory.Inventory; +import java.util.ArrayList; + import static me.sat7.dynamicshop.utilities.LangUtil.t; public class ShopList extends InGameUI @@ -33,11 +36,12 @@ public Inventory getGui(Player player, int page, int slotIndex) this.page = MathUtil.Clamp(page, 1, maxPage); this.slotIndex = slotIndex; + CreateExistShopList(); CreateShopButtons(); CreateCloseButton(player, CLOSE); CreateButton(PAGE, GetPageButtonIconMat(), - t(player, "START_PAGE.SHOP_LIST.PAGE_TITLE").replace("{curPage}", String.valueOf(this.page)).replace("{maxPage}", String.valueOf(this.maxPage)), - t(player, "START_PAGE.SHOP_LIST.PAGE_LORE")); + t(player, "START_PAGE.SHOP_LIST.PAGE_TITLE").replace("{curPage}", String.valueOf(this.page)).replace("{maxPage}", String.valueOf(this.maxPage)), + t(player, "START_PAGE.SHOP_LIST.PAGE_LORE")); return inventory; } @@ -65,7 +69,8 @@ public void OnClickUpperInventory(InventoryClickEvent e) } DynaShopAPI.openShopListUI(player, page, slotIndex); - } else if (e.getCurrentItem() != null && e.getCurrentItem().getType() == Material.CHEST) + } else if (e.getCurrentItem() != null && + (e.getCurrentItem().getType() == Material.GREEN_STAINED_GLASS || e.getCurrentItem().getType() == Material.GRAY_STAINED_GLASS)) { String shopName = e.getCurrentItem().getItemMeta().getDisplayName(); StartPage.ccStartPage.get().set("Buttons." + slotIndex + ".displayName", "§3" + shopName); @@ -88,11 +93,29 @@ private void CreateShopButtons() if (idx >= (page - 1) * 45) { - CreateButton(slotIdx, Material.CHEST, shopName, ""); + CreateButton(slotIdx, existShopList.contains(shopName) ? Material.GREEN_STAINED_GLASS : Material.GRAY_STAINED_GLASS, shopName, ""); slotIdx++; } idx++; } } + + ArrayList existShopList = new ArrayList<>(); + private void CreateExistShopList() + { + existShopList.clear(); + ConfigurationSection cs = StartPage.ccStartPage.get().getConfigurationSection("Buttons"); + if (cs != null) + { + for (String c : cs.getKeys(false)) + { + String actionString = cs.getString(c + ".action"); + if (actionString == null || !actionString.contains("ds shop")) + continue; + + existShopList.add(actionString.replace("ds shop ", "")); + } + } + } } diff --git a/src/main/java/me/sat7/dynamicshop/models/DSItem.java b/src/main/java/me/sat7/dynamicshop/models/DSItem.java index 720c20d..bee094d 100644 --- a/src/main/java/me/sat7/dynamicshop/models/DSItem.java +++ b/src/main/java/me/sat7/dynamicshop/models/DSItem.java @@ -17,8 +17,9 @@ public class DSItem private int median; private int stock; private int maxStock; + private int discount; - public DSItem(ItemStack itemStack, double buyValue, double sellValue, double minPrice, double maxPrice, int median, int stock, int maxStock) + public DSItem(ItemStack itemStack, double buyValue, double sellValue, double minPrice, double maxPrice, int median, int stock, int maxStock, int discount) { setItemStack(itemStack); setBuyValue(Math.round(buyValue * 100) / 100.0); @@ -28,5 +29,6 @@ public DSItem(ItemStack itemStack, double buyValue, double sellValue, double min setMedian(median); setStock(stock); setMaxStock(maxStock); + setDiscount(discount); } } diff --git a/src/main/java/me/sat7/dynamicshop/transactions/Calc.java b/src/main/java/me/sat7/dynamicshop/transactions/Calc.java index f16fae0..2713634 100644 --- a/src/main/java/me/sat7/dynamicshop/transactions/Calc.java +++ b/src/main/java/me/sat7/dynamicshop/transactions/Calc.java @@ -57,6 +57,13 @@ public static double getCurrentPrice(String shopName, String idx, boolean buy, b price = max; } + // 할인 + if (data.contains(idx + ".discount")) + { + int discount = data.getInt(idx + ".discount"); + price = price * (100 - discount) / 100; + } + // 판매세 계산 (임의 지정된 판매가치가 없는 경우에만) if (!buy && !data.contains(idx + ".value2")) { @@ -132,6 +139,13 @@ public static double[] calcTotalCost(String shopName, String idx, int amount) } } + // 할인 + if (data.contains(idx + ".discount")) + { + int discount = data.getInt(idx + ".discount"); + total = total * (100 - discount) / 100; + } + // 세금 적용 (판매가 별도지정시 세금계산 안함) double tax = 0; if (amount < 0 && !data.contains(idx + ".value2")) diff --git a/src/main/java/me/sat7/dynamicshop/transactions/Sell.java b/src/main/java/me/sat7/dynamicshop/transactions/Sell.java index 9e121e5..2c5e42c 100644 --- a/src/main/java/me/sat7/dynamicshop/transactions/Sell.java +++ b/src/main/java/me/sat7/dynamicshop/transactions/Sell.java @@ -135,8 +135,7 @@ else if (data.get().contains("Options.flag.playerpoint")) priceSum += calcResult[0]; Economy econ = DynamicShop.getEconomy(); - EconomyResponse r = null; - if (!CheckTransactionSuccess(currencyType, r, player, priceSum)) + if (!CheckTransactionSuccess(currencyType, player, priceSum)) return 0; //로그 기록 @@ -217,8 +216,7 @@ public static void sell(ItemTrade.CURRENCY currency, Player player, String shopN priceSum += calcResult[0]; Economy econ = DynamicShop.getEconomy(); - EconomyResponse r = null; - if (!CheckTransactionSuccess(currency, r, player, priceSum)) + if (!CheckTransactionSuccess(currency, player, priceSum)) return; //로그 기록 @@ -252,10 +250,11 @@ public static void sell(ItemTrade.CURRENCY currency, Player player, String shopN Bukkit.getPluginManager().callEvent(event); } - private static boolean CheckTransactionSuccess(ItemTrade.CURRENCY currencyType, EconomyResponse r, Player player, double priceSum) + private static boolean CheckTransactionSuccess(ItemTrade.CURRENCY currencyType, Player player, double priceSum) { if (currencyType == ItemTrade.CURRENCY.VAULT) { + EconomyResponse r = null; if (player != null) r = DynamicShop.getEconomy().depositPlayer(player, priceSum); diff --git a/src/main/java/me/sat7/dynamicshop/utilities/LangUtil.java b/src/main/java/me/sat7/dynamicshop/utilities/LangUtil.java index 67d98fa..2cfa178 100644 --- a/src/main/java/me/sat7/dynamicshop/utilities/LangUtil.java +++ b/src/main/java/me/sat7/dynamicshop/utilities/LangUtil.java @@ -60,6 +60,16 @@ public static void setupLangFile(String lang) ccLang.get().addDefault("SHOP.TRADE_LORE", "§f§n클릭: 거래"); ccLang.get().addDefault("SHOP.BUY_PRICE", "§f구매: {num}"); ccLang.get().addDefault("SHOP.SELL_PRICE", "§f판매: {num}"); + ccLang.get().addDefault("SHOP.BUY_PRICE_DISCOUNTED", "§f구매: §8§m{num}§r §a{num2}"); + ccLang.get().addDefault("SHOP.SELL_PRICE_DISCOUNTED", "§f판매: §8§m{num}§r §c{num2}"); + ccLang.get().addDefault("SHOP.BUY_PRICE_PP", "§f구매: {num}PP"); + ccLang.get().addDefault("SHOP.SELL_PRICE_PP", "§f판매: {num}PP"); + ccLang.get().addDefault("SHOP.BUY_PRICE_DISCOUNTED_PP", "§f구매: §8§m{num}PP§r §a{num2}PP"); + ccLang.get().addDefault("SHOP.SELL_PRICE_DISCOUNTED_PP", "§f판매: §8§m{num}PP§r §c{num2}PP"); + ccLang.get().addDefault("SHOP.BUY_PRICE_JP", "§f구매: {num}JP"); + ccLang.get().addDefault("SHOP.SELL_PRICE_JP", "§f판매: {num}JP"); + ccLang.get().addDefault("SHOP.BUY_PRICE_DISCOUNTED_JP", "§f구매: §8§m{num}JP§r §a{num2}JP"); + ccLang.get().addDefault("SHOP.SELL_PRICE_DISCOUNTED_JP", "§f판매: §8§m{num}JP§r §c{num2}JP"); ccLang.get().addDefault("SHOP.STOCK", "§8재고: {num}"); ccLang.get().addDefault("SHOP.STOCK_2", "§8재고: {stock}/{max_stock}"); ccLang.get().addDefault("SHOP.INF_STOCK", "§8무한"); @@ -161,6 +171,8 @@ public static void setupLangFile(String lang) ccLang.get().addDefault("ITEM_SETTING.MEDIAN_HELP", "§f중앙값이 작을수록 가격이 급격이 변화합니다."); ccLang.get().addDefault("ITEM_SETTING.TAX_IGNORED", "판매세 설정이 무시됩니다."); ccLang.get().addDefault("ITEM_SETTING.RECOMMEND", "§f추천 값 적용"); + ccLang.get().addDefault("ITEM_SETTING.DISCOUNT", "§f할인"); + ccLang.get().addDefault("ITEM_SETTING.DISCOUNT_LORE", "§f할인율: {num}%\n§e좌클릭: +10, 우클릭: -10"); ccLang.get().addDefault("ITEM_SETTING.DONE", "§f완료"); ccLang.get().addDefault("ITEM_SETTING.DONE_LORE", "§f완료!"); ccLang.get().addDefault("ITEM_SETTING.ROUND_DOWN", "§f내림"); @@ -182,6 +194,16 @@ public static void setupLangFile(String lang) ccLang.get().addDefault("TRADE.BALANCE", "§3내 잔액"); ccLang.get().addDefault("TRADE.PRICE", "§f구매: {num}"); ccLang.get().addDefault("TRADE.SELL_PRICE", "§f판매: {num}"); + ccLang.get().addDefault("TRADE.PRICE_DISCOUNTED", "§f구매: §8§m{num}§r §a{num2}"); + ccLang.get().addDefault("TRADE.SELL_PRICE_DISCOUNTED", "§f판매: §8§m{num}§r §c{num2}"); + ccLang.get().addDefault("TRADE.PRICE_PP", "§f구매: {num}PP"); + ccLang.get().addDefault("TRADE.SELL_PRICE_PP", "§f판매: {num}PP"); + ccLang.get().addDefault("TRADE.PRICE_DISCOUNTED_PP", "§f구매: §8§m{num}PP§r §a{num2}PP"); + ccLang.get().addDefault("TRADE.SELL_PRICE_DISCOUNTED_PP", "§f판매: §8§m{num}PP§r §c{num2}PP"); + ccLang.get().addDefault("TRADE.PRICE_JP", "§f구매: {num}JP"); + ccLang.get().addDefault("TRADE.SELL_PRICE_JP", "§f판매: {num}JP"); + ccLang.get().addDefault("TRADE.PRICE_DISCOUNTED_JP", "§f구매: §8§m{num}JP§r §a{num2}JP"); + ccLang.get().addDefault("TRADE.SELL_PRICE_DISCOUNTED_JP", "§f판매: §8§m{num}JP§r §c{num2}JP"); ccLang.get().addDefault("TRADE.BUY", "§c구매"); ccLang.get().addDefault("TRADE.SELL", "§2판매"); ccLang.get().addDefault("TRADE.STOCK", "§8재고: "); @@ -451,6 +473,16 @@ public static void setupLangFile(String lang) ccLang.get().addDefault("SHOP.TRADE_LORE", "§f§nClick: Trade"); ccLang.get().addDefault("SHOP.BUY_PRICE", "§fBuy: {num}"); ccLang.get().addDefault("SHOP.SELL_PRICE", "§fSell: {num}"); + ccLang.get().addDefault("SHOP.BUY_PRICE_DISCOUNTED", "§fBuy: §8§m{num}§r §a{num2}"); + ccLang.get().addDefault("SHOP.SELL_PRICE_DISCOUNTED", "§fSell: §8§m{num}§r §c{num2}"); + ccLang.get().addDefault("SHOP.BUY_PRICE_PP", "§fBuy: {num}PP"); + ccLang.get().addDefault("SHOP.SELL_PRICE_PP", "§fSell: {num}PP"); + ccLang.get().addDefault("SHOP.BUY_PRICE_DISCOUNTED_PP", "§fBuy: §8§m{num}PP§r §a{num2}PP"); + ccLang.get().addDefault("SHOP.SELL_PRICE_DISCOUNTED_PP", "§fSell: §8§m{num}PP§r §c{num2}PP"); + ccLang.get().addDefault("SHOP.BUY_PRICE_JP", "§fBuy: {num}JP"); + ccLang.get().addDefault("SHOP.SELL_PRICE_JP", "§fSell: {num}JP"); + ccLang.get().addDefault("SHOP.BUY_PRICE_DISCOUNTED_JP", "§fBuy: §8§m{num}JP§r §a{num2}JP"); + ccLang.get().addDefault("SHOP.SELL_PRICE_DISCOUNTED_JP", "§fSell: §8§m{num}JP§r §c{num2}JP"); ccLang.get().addDefault("SHOP.STOCK", "§8Stock: {num}"); ccLang.get().addDefault("SHOP.STOCK_2", "§8Stock: {stock}/{max_stock}"); ccLang.get().addDefault("SHOP.INF_STOCK", "§8Infinite"); @@ -552,6 +584,8 @@ public static void setupLangFile(String lang) ccLang.get().addDefault("ITEM_SETTING.MEDIAN_HELP", "§fThe smaller the median,\n§fthe steeper the price change."); ccLang.get().addDefault("ITEM_SETTING.TAX_IGNORED", "Sales tax settings are ignored."); ccLang.get().addDefault("ITEM_SETTING.RECOMMEND", "§fApply recommended values"); + ccLang.get().addDefault("ITEM_SETTING.DISCOUNT", "§fDiscount"); + ccLang.get().addDefault("ITEM_SETTING.DISCOUNT_LORE", "§fDiscount rate: {num}%\n§eLMB: +10, RMB: -10"); ccLang.get().addDefault("ITEM_SETTING.DONE", "§fDone"); ccLang.get().addDefault("ITEM_SETTING.DONE_LORE", "§fDone!"); ccLang.get().addDefault("ITEM_SETTING.ROUND_DOWN", "§fRound down"); @@ -573,6 +607,16 @@ public static void setupLangFile(String lang) ccLang.get().addDefault("TRADE.BALANCE", "§3My balance"); ccLang.get().addDefault("TRADE.PRICE", "§fBuy: {num}"); ccLang.get().addDefault("TRADE.SELL_PRICE", "§fSell: {num}"); + ccLang.get().addDefault("TRADE.PRICE_DISCOUNTED", "§fBuy: §8§m{num}§r §a{num2}"); + ccLang.get().addDefault("TRADE.SELL_PRICE_DISCOUNTED", "§fSell: §8§m{num}§r §c{num2}"); + ccLang.get().addDefault("TRADE.PRICE_PP", "§fBuy: {num}PP"); + ccLang.get().addDefault("TRADE.SELL_PRICE_PP", "§fSell: {num}PP"); + ccLang.get().addDefault("TRADE.PRICE_DISCOUNTED_PP", "§fBuy: §8§m{num}PP§r §a{num2}PP"); + ccLang.get().addDefault("TRADE.SELL_PRICE_DISCOUNTED_PP", "§fSell: §8§m{num}PP§r §c{num2}PP"); + ccLang.get().addDefault("TRADE.PRICE_JP", "§fBuy: {num}JP"); + ccLang.get().addDefault("TRADE.SELL_PRICE_JP", "§fSell: {num}JP"); + ccLang.get().addDefault("TRADE.PRICE_DISCOUNTED_JP", "§fBuy: §8§m{num}JP§r §a{num2}JP"); + ccLang.get().addDefault("TRADE.SELL_PRICE_DISCOUNTED_JP", "§fSell: §8§m{num}JP§r §c{num2}JP"); ccLang.get().addDefault("TRADE.BUY", "§cBuy"); ccLang.get().addDefault("TRADE.SELL", "§2Sell"); ccLang.get().addDefault("TRADE.STOCK", "§8Stock: "); diff --git a/src/main/java/me/sat7/dynamicshop/utilities/LayoutUtil.java b/src/main/java/me/sat7/dynamicshop/utilities/LayoutUtil.java index 29fd283..efc9da5 100644 --- a/src/main/java/me/sat7/dynamicshop/utilities/LayoutUtil.java +++ b/src/main/java/me/sat7/dynamicshop/utilities/LayoutUtil.java @@ -16,16 +16,16 @@ public static void Setup() ccLayout.setup("Layout", null); ccLayout.get().options().header( "{Tag} : A predefined placeholder. Available for each item only." + - "\n{\\nTag} : Line breaks when this item is displayed." + - "\nSHOP.INFO: §f{ShopLore}{\\nPermission}{\\nTax}{\\nShopBalance}{\\nShopHour}{\\nShopPosition}" + - "\nSHOP.ITEM_INFO: §f{Sell}{\\nBuy}{\\nStock}{\\nPricingType}{\\nItemMetaLore}{\\nTradeLore}" + - "\nTRADE_VIEW.BUY: §f{Price}{\\nStock}{\\nDeliveryCharge}{\\nTradeLore}" + - "\nTRADE_VIEW.SELL: §f{Price}{\\nStock}{\\nDeliveryCharge}{\\nTradeLore}" + - "\nTRADE_VIEW.BALANCE: §f{PlayerBalance}{\\nShopBalance}" + "\n{\\nTag} : Line breaks when this item is displayed." + + "\nSHOP.INFO: §f{ShopLore}{\\nPermission}{\\nTax}{\\nShopBalance}{\\nShopHour}{\\nShopPosition}" + + "\nSHOP.ITEM_INFO: §f{\\nItemMetaLore}{\\nSell}{\\nBuy}{\\nStock}{\\nPricingType}\n{\\nTradeLore}" + + "\nTRADE_VIEW.BUY: §f{Price}{\\nStock}{\\nDeliveryCharge}\n{\\nTradeLore}" + + "\nTRADE_VIEW.SELL: §f{Price}{\\nStock}{\\nDeliveryCharge}\n{\\nTradeLore}" + + "\nTRADE_VIEW.BALANCE: §f{PlayerBalance}{\\nShopBalance}" ); ccLayout.get().addDefault("SHOP.INFO", "§f{ShopLore}{\\nPermission}{\\nTax}{\\nShopBalance}{\\nShopHour}{\\nShopPosition}"); - ccLayout.get().addDefault("SHOP.ITEM_INFO", "§f{Sell}{\\nBuy}{\\nStock}{\\nPricingType}\n{\\nItemMetaLore}{\\nTradeLore}"); + ccLayout.get().addDefault("SHOP.ITEM_INFO", "§f{\\nItemMetaLore}{\\nSell}{\\nBuy}{\\nStock}{\\nPricingType}\n{\\nTradeLore}"); ccLayout.get().addDefault("TRADE_VIEW.BUY", "§f{Price}{\\nStock}{\\nDeliveryCharge}\n{\\nTradeLore}"); ccLayout.get().addDefault("TRADE_VIEW.SELL", "§f{Price}{\\nStock}{\\nDeliveryCharge}\n{\\nTradeLore}"); ccLayout.get().addDefault("TRADE_VIEW.BALANCE", "§f{PlayerBalance}{\\nShopBalance}"); diff --git a/src/main/java/me/sat7/dynamicshop/utilities/ShopUtil.java b/src/main/java/me/sat7/dynamicshop/utilities/ShopUtil.java index f3e99b7..37428e0 100644 --- a/src/main/java/me/sat7/dynamicshop/utilities/ShopUtil.java +++ b/src/main/java/me/sat7/dynamicshop/utilities/ShopUtil.java @@ -260,6 +260,24 @@ public static void editShopItem(String shopName, int idx, double buyValue, doubl data.save(); } + public static void setDiscount(String shopName, int idx, int discount) + { + CustomConfig data = shopConfigFiles.get(shopName); + if (data == null) + return; + + if (discount == 0) + { + data.get().set(idx + ".discount", null); + } + else + { + data.get().set(idx + ".discount", discount); + } + + data.save(); + } + // 상점에서 아이탬 제거 public static void removeItemFromShop(String shopName, int idx) { @@ -360,15 +378,15 @@ public static boolean SwapPage(String shopName, int pageA, int pageB) } tempA.forEach((key, value) -> - { - key += (pageB - pageA) * 45; - data.get().set(String.valueOf(key), value); - }); + { + key += (pageB - pageA) * 45; + data.get().set(String.valueOf(key), value); + }); tempB.forEach((key, value) -> - { - key += (pageA - pageB) * 45; - data.get().set(String.valueOf(key), value); - }); + { + key += (pageA - pageB) * 45; + data.get().set(String.valueOf(key), value); + }); tempA.clear(); tempB.clear(); @@ -526,8 +544,8 @@ public static double getShopBalance(String shopName) } catch (Exception e) { DynamicShop.console.sendMessage(Constants.DYNAMIC_SHOP_PREFIX + - shopName + ", " + linkedShop + "/ " + - t(null, "ERR.SHOP_LINK_TARGET_ERR")); + shopName + ", " + linkedShop + "/ " + + t(null, "ERR.SHOP_LINK_TARGET_ERR")); data.get().set("Options.Balance", null); data.save(); diff --git a/src/main/java/me/sat7/dynamicshop/utilities/TabCompleteUtil.java b/src/main/java/me/sat7/dynamicshop/utilities/TabCompleteUtil.java index 0154967..e8cfc6a 100644 --- a/src/main/java/me/sat7/dynamicshop/utilities/TabCompleteUtil.java +++ b/src/main/java/me/sat7/dynamicshop/utilities/TabCompleteUtil.java @@ -228,6 +228,7 @@ public static List onTabCompleteBody(DynamicShop dynamicShop, CommandSen temp.add("stock"); temp.add("median"); temp.add("maxStock"); + temp.add("discount"); AddToAutoCompleteIfValid(args[3]); } else if (args.length == 5) @@ -241,7 +242,7 @@ public static List onTabCompleteBody(DynamicShop dynamicShop, CommandSen AddToAutoCompleteIfValid(args[4]); } else if (args.length == 6) { - if (args[4].equals("=")) + if (args[4].equals("=") && !args[3].equals("discount")) { temp.add("purchaseValue"); temp.add("salesValue"); @@ -250,6 +251,7 @@ public static List onTabCompleteBody(DynamicShop dynamicShop, CommandSen temp.add("stock"); temp.add("median"); temp.add("maxStock"); + temp.add("discount"); AddToAutoCompleteIfValid(args[5]); }