Skip to content

Commit

Permalink
Discounts, various improvements and fixes
Browse files Browse the repository at this point in the history
[New Features]
1. Add item discount rate setting.
2. Add 'discount' to 'editAll' command.

[improvement]
1. Improved so that changing the store name is also reflected on the start page.
2. Improved shop selection UI in the start page button editor.
3. Separate text keys for JobPoint and PlayerPoint.

[bug fix]
1. (Premium) Fixed a problem where the unique name, description, and page count data of the rotation store did not respond correctly to the '/ds reload' command.
2. Fixed an issue where the stock-related text was displayed even when the 'hideStock' flag was enabled.

Other minor fixes and improvements.
  • Loading branch information
7sat committed Mar 7, 2023
1 parent 15a595f commit 521bf7f
Show file tree
Hide file tree
Showing 18 changed files with 313 additions and 87 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

<groupId>me.sat7</groupId>
<artifactId>DynamicShop</artifactId>
<version>3.11.2</version>
<version>3.12.0</version>
<packaging>jar</packaging>

<name>DynamicShop</name>
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/me/sat7/dynamicshop/DynaShopAPI.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down
2 changes: 1 addition & 1 deletion src/main/java/me/sat7/dynamicshop/DynamicShop.java
Original file line number Diff line number Diff line change
Expand Up @@ -452,7 +452,7 @@ private void InitConfig()

ConfigUtil.Load();

LangUtil.setupLangFile(ConfigUtil.GetLanguage());
LangUtil.setupLangFile(ConfigUtil.GetLanguage()); // ConfigUtil.Load() 보다 밑에 있어야함.
LayoutUtil.Setup();

setupUserFile();
Expand Down
3 changes: 2 additions & 1 deletion src/main/java/me/sat7/dynamicshop/commands/Reload.java
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ public void RunCMD(String[] args, CommandSender sender)
SoundUtil.setupSoundFile();

ConfigUtil.Load();

DynamicShop.plugin.PeriodicRepetitiveTask();

DynamicShop.plugin.startSaveLogsTask();
Expand All @@ -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"));
}
Expand Down
27 changes: 25 additions & 2 deletions src/main/java/me/sat7/dynamicshop/commands/RenameShop.java
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -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]))
Expand All @@ -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"));
}
Expand Down
23 changes: 20 additions & 3 deletions src/main/java/me/sat7/dynamicshop/commands/shop/EditAll.java
Original file line number Diff line number Diff line change
Expand Up @@ -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 <purchaseValue | salesValue | valueMin | valueMax | median | stock | max stock> <= | + | - | * | /> <amount>");
player.sendMessage(" - " + t(player, "HELP.USAGE") + ": ... editall <purchaseValue | salesValue | valueMin | valueMax | median | stock | max stock | discount> <= | + | - | * | /> <amount>");
player.sendMessage(" - " + t(player, "HELP.EDIT_ALL"));

player.sendMessage("");
Expand Down Expand Up @@ -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;
Expand All @@ -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)
{
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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);
Expand All @@ -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")))
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/me/sat7/dynamicshop/guis/ItemPalette.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down
83 changes: 54 additions & 29 deletions src/main/java/me/sat7/dynamicshop/guis/ItemSettings.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand All @@ -65,6 +66,7 @@ public ItemSettings()
private int median;
private int stock;
private int maxStock;
private int discount;

private boolean oldSbSame;

Expand All @@ -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());
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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")); // 닫기 버튼
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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
Expand All @@ -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");
}
Expand All @@ -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());
Expand All @@ -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);
}
}

Expand Down Expand Up @@ -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");
}
}
Loading

0 comments on commit 521bf7f

Please sign in to comment.