Skip to content

Commit

Permalink
various minor fixes
Browse files Browse the repository at this point in the history
1.Fixed an issue where the sound effect was too loud when using the 'sell all' command
2.Removed unnecessary exception messages when the economy plug-in does not exist and is forcefully terminated.
3.Min unit change in price: 0.01 -> 0.0001
  • Loading branch information
7sat committed Apr 21, 2023
1 parent 2898e18 commit 050f8dc
Show file tree
Hide file tree
Showing 18 changed files with 90 additions and 71 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.14.3</version>
<version>3.15.0</version>
<packaging>jar</packaging>

<name>DynamicShop</name>
Expand Down
12 changes: 10 additions & 2 deletions src/main/java/me/sat7/dynamicshop/DynaShopAPI.java
Original file line number Diff line number Diff line change
Expand Up @@ -442,9 +442,17 @@ public static String[] FindTheBestShopToSell(Player player, ItemStack itemStack,
*/
public static double QuickSell(Player player, ItemStack itemStack)
{
return QuickSell(player, itemStack, -1);
return QuickSell(player, itemStack, -1, true);
}
public static double QuickSell(Player player, ItemStack itemStack, boolean playSound)
{
return QuickSell(player, itemStack, -1, playSound);
}
public static double QuickSell(Player player, ItemStack itemStack, int slot)
{
return QuickSell(player,itemStack, slot, true);
}
public static double QuickSell(Player player, ItemStack itemStack, int slot, boolean playSound)
{
if (itemStack == null || itemStack.getType().isAir())
return 0;
Expand All @@ -457,7 +465,7 @@ public static double QuickSell(Player player, ItemStack itemStack, int slot)
if (!validateShopName(ret[0]))
return 0;

return Sell.quickSellItem(player, itemStack, ret[0], Integer.parseInt(ret[1]), slot == -1, slot);
return Sell.quickSellItem(player, itemStack, ret[0], Integer.parseInt(ret[1]), slot == -1, slot, playSound);
}

/**
Expand Down
11 changes: 7 additions & 4 deletions src/main/java/me/sat7/dynamicshop/DynamicShop.java
Original file line number Diff line number Diff line change
Expand Up @@ -238,9 +238,9 @@ private void SetupRSP()
}

setupRspRetryCount++;
console.sendMessage(Constants.DYNAMIC_SHOP_PREFIX + " Economy provider not found. Retry... " + setupRspRetryCount + "/3");
//console.sendMessage(Constants.DYNAMIC_SHOP_PREFIX + " Economy provider not found. Retry... " + setupRspRetryCount + "/3");

Bukkit.getScheduler().runTaskLater(this, this::SetupRSP, 30L);
Bukkit.getScheduler().runTaskLater(this, this::SetupRSP, 40L);
}
}

Expand Down Expand Up @@ -503,8 +503,11 @@ public List<String> onTabComplete(CommandSender sender, Command cmd, String comm
@Override
public void onDisable()
{
UserUtil.OnPluginDisable();
ShopUtil.ForceSaveAllShop();
if (econ != null)
{
UserUtil.OnPluginDisable();
ShopUtil.ForceSaveAllShop();
}

Bukkit.getScheduler().cancelTasks(this);
console.sendMessage(Constants.DYNAMIC_SHOP_PREFIX + " Disabled");
Expand Down
7 changes: 6 additions & 1 deletion src/main/java/me/sat7/dynamicshop/commands/Sell.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import me.sat7.dynamicshop.utilities.HashUtil;
import org.bukkit.Bukkit;
import org.bukkit.GameMode;
import org.bukkit.Sound;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
Expand Down Expand Up @@ -101,7 +102,7 @@ else if (args[0].equalsIgnoreCase("all"))
if (temp.contains(hash))
continue;

sum += DynaShopAPI.QuickSell(player, stack);
sum += DynaShopAPI.QuickSell(player, stack, false);
temp.add(hash);
}

Expand All @@ -110,6 +111,10 @@ else if (args[0].equalsIgnoreCase("all"))
player.sendMessage(DynamicShop.dsPrefix(player) + t(player, "MESSAGE.NO_ITEM_TO_SELL_2"));
return false;
}
else
{
player.playSound(player.getLocation(), Sound.valueOf("ENTITY_EXPERIENCE_ORB_PICKUP"), 1, 1);
}

return true;
}
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/me/sat7/dynamicshop/commands/shop/Add.java
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public void RunCMD(String[] args, CommandSender sender)

Material mat;
double buyValue;
double valueMin = 0.01;
double valueMin = 0.0001;
double valueMax = -1;
int median;
int stock;
Expand Down Expand Up @@ -87,7 +87,7 @@ public void RunCMD(String[] args, CommandSender sender)
}
}

if (buyValue < 0.01 || median == 0 || stock == 0)
if (buyValue < 0.0001 || median == 0 || stock == 0)
{
sender.sendMessage(DynamicShop.dsPrefix(sender) + t(sender, "ERR.VALUE_ZERO"));
return;
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/me/sat7/dynamicshop/commands/shop/AddHand.java
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public void RunCMD(String[] args, CommandSender sender)

String shopName = Shop.GetShopName(args);
double buyValue;
double valueMin = 0.01;
double valueMin = 0.0001;
double valueMax = -1;
int median;
int stock;
Expand Down Expand Up @@ -81,7 +81,7 @@ public void RunCMD(String[] args, CommandSender sender)
}
}

if (buyValue < 0.01 || median == 0 || stock == 0)
if (buyValue < 0.0001 || median == 0 || stock == 0)
{
player.sendMessage(DynamicShop.dsPrefix(player) + t(player, "ERR.VALUE_ZERO"));
return;
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/me/sat7/dynamicshop/commands/shop/Edit.java
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ public void RunCMD(String[] args, CommandSender sender)

int idx;
double buyValue;
double valueMin = 0.01;
double valueMin = 0.0001;
double valueMax = -1;
int median;
int stock;
Expand Down
6 changes: 3 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 @@ -153,9 +153,9 @@ else if (mod.equalsIgnoreCase("*"))
result = originalValue * newValue;
}

if (dataType.equals("value") && result < 0.01)
if (dataType.equals("value") && result < 0.0001)
{
result = 0.01;
result = 0.0001;
}

if (dataType.equals("stock") || dataType.equals("median") || dataType.equals("maxStock") || dataType.equals("discount"))
Expand All @@ -165,7 +165,7 @@ else if (mod.equalsIgnoreCase("*"))
}
else
{
result = Math.round(result * 1000) / 1000.0;
result = Math.round(result * 10000) / 10000.0;
shopData.get().set(s + "." + dataType, result);
}

Expand Down
8 changes: 4 additions & 4 deletions src/main/java/me/sat7/dynamicshop/guis/ItemPalette.java
Original file line number Diff line number Diff line change
Expand Up @@ -393,7 +393,7 @@ private void AddAll(boolean applyRecommend)

targetSlotIdx = ShopUtil.findEmptyShopSlot(shopName, shopSlotIndex, true);

DSItem temp = new DSItem(itemStack, 1, 1, 0.01, -1, 10000, 10000);
DSItem temp = new DSItem(itemStack, 1, 1, 0.0001, -1, 10000, 10000);
ShopUtil.addItemToShop(shopName, targetSlotIdx, temp);
}
}
Expand Down Expand Up @@ -431,12 +431,12 @@ private void OnClickItem(boolean isLeft, boolean isRight, boolean isShift, ItemS
{
if (isShift)
{
DSItem dsItem = new DSItem(itemStack, 10, 10, 0.01, -1, 10000, 10000);
DSItem dsItem = new DSItem(itemStack, 10, 10, 0.0001, -1, 10000, 10000);
DynaShopAPI.openItemSettingGui(player, shopName, shopSlotIndex,0, dsItem);
} else
{
int targetSlotIdx = ShopUtil.findEmptyShopSlot(shopName, shopSlotIndex, true);
DSItem temp = new DSItem(itemStack, 1, 1, 0.01, -1, 10000, 10000);
DSItem temp = new DSItem(itemStack, 1, 1, 0.0001, -1, 10000, 10000);
ShopUtil.addItemToShop(shopName, targetSlotIdx, temp);
player.sendMessage(DynamicShop.dsPrefix(player) + t(player, "MESSAGE.ITEM_ADDED"));

Expand Down Expand Up @@ -492,7 +492,7 @@ private void OnClickUserItem(boolean isLeft, boolean isRight, ItemStack item)
{
if (isLeft)
{
DSItem dsItem = new DSItem(item, 10, 10, 0.01, -1, 10000, 10000);
DSItem dsItem = new DSItem(item, 10, 10, 0.0001, -1, 10000, 10000);
DynaShopAPI.openItemSettingGui(player, shopName, shopSlotIndex, 0, dsItem);
} else if (isRight)
{
Expand Down
46 changes: 20 additions & 26 deletions src/main/java/me/sat7/dynamicshop/guis/ItemSettings.java
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ public Inventory getGui(Player player, String shopName, int shopSlotIndex, int t
// 조절버튼
if (dsItem.getBuyValue() == dsItem.getSellValue())
sellValueStr = "§8" + ChatColor.stripColor(sellValueStr);
if (dsItem.getMinPrice() <= 0.01)
if (dsItem.getMinPrice() <= 0.0001)
priceMinStr = "§8" + ChatColor.stripColor(priceMinStr);
if (dsItem.getMaxPrice() <= 0)
priceMaxStr = "§8" + ChatColor.stripColor(priceMaxStr);
Expand Down Expand Up @@ -171,8 +171,8 @@ public Inventory getGui(Player player, String shopName, int shopSlotIndex, int t
} else
{
buyPrice = (dsItem.getBuyValue() * dsItem.getMedian()) / dsItem.getStock();
if(buyPrice < 0.01)
buyPrice = 0.01;
if(buyPrice < 0.0001)
buyPrice = 0.0001;

if (dsItem.getBuyValue() != dsItem.getSellValue()) // 판매가 별도설정
{
Expand All @@ -191,7 +191,7 @@ public Inventory getGui(Player player, String shopName, int shopSlotIndex, int t
taxStr += ConfigUtil.getCurrentTax() + "%";
sellPrice = buyPrice - ((buyPrice / 100.0) * ConfigUtil.getCurrentTax());
}
sellPrice = (Math.round(sellPrice * 100) / 100.0);
sellPrice = (Math.round(sellPrice * 10000) / 10000.0);

editBtnLore.add(taxStr);
}
Expand Down Expand Up @@ -247,19 +247,13 @@ public Inventory getGui(Player player, String shopName, int shopSlotIndex, int t

String worthChanged = (dsItem.getBuyValue() == worth) ? " ▶§f " : " ▶§a ";
String worthChanged2 = (dsItem.getSellValue() == worth) ? " ▶§f " : " ▶§a ";
//String minChanged = (dsItem.getMinPrice() == 0.01) ? " ▶§f " : " ▶§a ";
//String maxChanged = (dsItem.getMaxPrice() == -1) ? " ▶§f " : " ▶§a ";
String medianChanged = (dsItem.getMedian() == sugMid) ? " ▶§f " : " ▶§a ";
String stockChanged = (dsItem.getStock() == sugMid) ? " ▶§f " : " ▶§a ";

recommendLore = t(null, "ITEM_SETTING.VALUE_BUY") + "\n"
+ "§7 " + dsItem.getBuyValue() + worthChanged + worth + "\n"
+ t(null, "ITEM_SETTING.VALUE_SELL") + "\n"
+ "§7 " + dsItem.getSellValue() + worthChanged2 + worth + "\n"
//+ t(null, "ITEM_SETTING.PRICE_MIN") + "\n"
//+ "§7 " + dsItem.getMinPrice() + minChanged + 0.01 + "\n"
//+ t(null, "ITEM_SETTING.PRICE_MAX") + "\n"
//+ "§7 " + dsItem.getMaxPrice() + maxChanged + -1 + "\n"
+ t(null, "ITEM_SETTING.MEDIAN") + "\n"
+ "§7 " + dsItem.getMedian() + medianChanged + sugMid + "\n"
+ t(null, "ITEM_SETTING.STOCK") + "\n"
Expand Down Expand Up @@ -309,7 +303,7 @@ public void OnClickUpperInventory(InventoryClickEvent e)
if (e.getCurrentItem() == null)
return;

if(dsItem.minPrice <= 0) dsItem.minPrice = 0.01;
if(dsItem.minPrice <= 0) dsItem.minPrice = 0.0001;
if(dsItem.maxPrice <= 0) dsItem.maxPrice = -1;

oldSbSame = dsItem.sellValue == dsItem.buyValue;
Expand Down Expand Up @@ -548,7 +542,7 @@ private void Reset()
{
if (currentTab == BUY_VALUE) dsItem.buyValue = 10;
else if (currentTab == SELL_VALUE) dsItem.sellValue = 10;
else if (currentTab == MIN_VALUE) dsItem.minPrice = 0.01;
else if (currentTab == MIN_VALUE) dsItem.minPrice = 0.0001;
else if (currentTab == MAX_VALUE) dsItem.maxPrice = -1;
else if (currentTab == MEDIAN) dsItem.median = 10000;
else if (currentTab == STOCK) dsItem.stock = 10000;
Expand All @@ -566,26 +560,26 @@ private void PlusMinus(boolean isShift, ItemStack clickedButton)
if (currentTab == BUY_VALUE)
{
dsItem.buyValue += editNum;
if (dsItem.buyValue < 0.01) dsItem.buyValue = 0.01f;
if (dsItem.buyValue < 0.0001) dsItem.buyValue = 0.0001f;

if(oldSbSame)
dsItem.sellValue = dsItem.buyValue;
} else if (currentTab == SELL_VALUE)
{
dsItem.sellValue += editNum;
if (dsItem.sellValue < 0.01) dsItem.sellValue = 0.01f;
if (dsItem.sellValue < 0.0001) dsItem.sellValue = 0.0001f;
} else if (currentTab == MIN_VALUE)
{
dsItem.minPrice += editNum;
if (dsItem.minPrice < 0.01) dsItem.minPrice = 0.01f;
if (dsItem.minPrice < 0.0001) dsItem.minPrice = 0.0001f;
} else if (currentTab == MAX_VALUE)
{
if (dsItem.maxPrice <= 0 && editNum > 0)
dsItem.maxPrice = editNum;
else
{
dsItem.maxPrice += editNum;
if (dsItem.maxPrice < 0.01)
if (dsItem.maxPrice < 0.0001)
dsItem.maxPrice = -1;
}
} else if (currentTab == MEDIAN)
Expand Down Expand Up @@ -643,22 +637,22 @@ private void Divide(boolean isShift)
if (currentTab == BUY_VALUE)
{
dsItem.buyValue /= div;
if(dsItem.buyValue < 0.01) dsItem.buyValue = 0.01;
if(dsItem.buyValue < 0.0001) dsItem.buyValue = 0.0001;

if(oldSbSame)
dsItem.sellValue = dsItem.buyValue;
} else if (currentTab == SELL_VALUE)
{
dsItem.sellValue /= div;
if(dsItem.sellValue < 0.01) dsItem.sellValue = 0.01;
if(dsItem.sellValue < 0.0001) dsItem.sellValue = 0.0001;
} else if (currentTab == MIN_VALUE)
{
dsItem.minPrice /= div;
if(dsItem.minPrice < 0.01) dsItem.minPrice = 0.01;
if(dsItem.minPrice < 0.0001) dsItem.minPrice = 0.0001;
} else if (currentTab == MAX_VALUE)
{
dsItem.maxPrice /= div;
if(dsItem.maxPrice < 0.01) dsItem.maxPrice = 0.01;
if(dsItem.maxPrice < 0.0001) dsItem.maxPrice = 0.0001;
} else if (currentTab == MEDIAN)
{
if(dsItem.median > 1)
Expand Down Expand Up @@ -740,12 +734,12 @@ private void SetEqualToOther()

private void ValueValidation()
{
if (dsItem.buyValue < 0.01)
dsItem.buyValue = 0.01;
if (dsItem.sellValue < 0.01)
dsItem.sellValue = 0.01;
if (dsItem.minPrice < 0.01)
dsItem.minPrice = 0.01;
if (dsItem.buyValue < 0.0001)
dsItem.buyValue = 0.0001;
if (dsItem.sellValue < 0.0001)
dsItem.sellValue = 0.0001;
if (dsItem.minPrice < 0.0001)
dsItem.minPrice = 0.0001;
if (dsItem.maxPrice < -1)
dsItem.maxPrice = -1;
if (dsItem.median < -1)
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/me/sat7/dynamicshop/guis/Shop.java
Original file line number Diff line number Diff line change
Expand Up @@ -610,7 +610,7 @@ else if (e.isRightClick() && player.hasPermission(P_ADMIN_SHOP_EDIT))
sellValue = shopData.getDouble(idx + ".value2");
}
double valueMin = shopData.getDouble(idx + ".valueMin");
if (valueMin <= 0.01) valueMin = 0.01;
if (valueMin <= 0.0001) valueMin = 0.0001;
double valueMax = shopData.getDouble(idx + ".valueMax");
if (valueMax <= 0) valueMax = -1;
int median = shopData.getInt(idx + ".median");
Expand Down
16 changes: 8 additions & 8 deletions src/main/java/me/sat7/dynamicshop/models/DSItem.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,21 +26,21 @@ public class DSItem
public DSItem(ItemStack itemStack, double buyValue, double sellValue, double minPrice, double maxPrice, int median, int stock)
{
setItemStack(itemStack);
setBuyValue(Math.round(buyValue * 100) / 100.0);
setSellValue(Math.round(sellValue * 100) / 100.0);
setMinPrice(Math.round(minPrice * 100) / 100.0);
setMaxPrice(Math.round(maxPrice * 100) / 100.0);
setBuyValue(Math.round(buyValue * 10000) / 10000.0);
setSellValue(Math.round(sellValue * 10000) / 10000.0);
setMinPrice(Math.round(minPrice * 10000) / 10000.0);
setMaxPrice(Math.round(maxPrice * 10000) / 10000.0);
setMedian(median);
setStock(stock);
maxStock = -1;
}
public DSItem(ItemStack itemStack, double buyValue, double sellValue, double minPrice, double maxPrice, int median, int stock, int maxStock, int discount, int sellLimit, int buyLimit, long tradeLimitInterval, long tradeLimitNextTimer)
{
setItemStack(itemStack);
setBuyValue(Math.round(buyValue * 100) / 100.0);
setSellValue(Math.round(sellValue * 100) / 100.0);
setMinPrice(Math.round(minPrice * 100) / 100.0);
setMaxPrice(Math.round(maxPrice * 100) / 100.0);
setBuyValue(Math.round(buyValue * 10000) / 10000.0);
setSellValue(Math.round(sellValue * 10000) / 10000.0);
setMinPrice(Math.round(minPrice * 10000) / 10000.0);
setMaxPrice(Math.round(maxPrice * 10000) / 10000.0);
setMedian(median);
setStock(stock);
setMaxStock(maxStock);
Expand Down
6 changes: 3 additions & 3 deletions src/main/java/me/sat7/dynamicshop/transactions/Calc.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public static double getCurrentPrice(String shopName, String idx, boolean buy, b
value = data.getDouble(idx + ".value");
}

double min = data.getDouble(idx + ".valueMin", 0.01);
double min = data.getDouble(idx + ".valueMin", 0.0001);
double max = data.getDouble(idx + ".valueMax");
int median = data.getInt(idx + ".median");
int stock = data.getInt(idx + ".stock");
Expand Down Expand Up @@ -114,7 +114,7 @@ public static double[] calcTotalCost(String shopName, String idx, int amount)
stock++;
}
double temp = median * value / stock;
double min = data.getDouble(idx + ".valueMin", 0.01);
double min = data.getDouble(idx + ".valueMin", 0.0001);
double max = data.getDouble(idx + ".valueMax");

if (temp < min)
Expand Down Expand Up @@ -163,7 +163,7 @@ public static double[] calcTotalCost(String shopName, String idx, int amount)
}
else
{
total = (Math.round(total * 100) / 100.0);
total = (Math.round(total * 10000) / 10000.0);
}

return new double[]{total, tax};
Expand Down
Loading

0 comments on commit 050f8dc

Please sign in to comment.