Skip to content

Commit

Permalink
Fixed UI string key error related to trading volume limit
Browse files Browse the repository at this point in the history
Added debug logs related to item transactions (available by entering the 'ds dbglog' command in the console)
  • Loading branch information
7sat committed Apr 24, 2023
1 parent 347163b commit ff6588a
Show file tree
Hide file tree
Showing 6 changed files with 109 additions and 4 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.15.1</version>
<version>3.15.2</version>
<packaging>jar</packaging>

<name>DynamicShop</name>
Expand Down
7 changes: 7 additions & 0 deletions src/main/java/me/sat7/dynamicshop/DynamicShop.java
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,13 @@ public static String dsPrefix(Player player)
public static final LocaleManager localeManager = new LocaleManager();
public static boolean isPapiExist;

public static boolean DEBUG_LOG_ENABLED = false;
public static void PrintConsoleDbgLog(String msg)
{
if (DEBUG_LOG_ENABLED)
console.sendMessage(DynamicShop.dsPrefix_ + msg);
}

public static boolean DEBUG_MODE = false;
public static void DebugLog()
{
Expand Down
6 changes: 6 additions & 0 deletions src/main/java/me/sat7/dynamicshop/commands/Root.java
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,12 @@ else if (args[0].equalsIgnoreCase("dummyUUID") && DynamicShop.DEBUG_MODE && play
sender.sendMessage(Constants.DYNAMIC_SHOP_PREFIX + "DebugMode " + DynamicShop.DEBUG_MODE);
return true;
}
else if (args[0].equalsIgnoreCase("dbgLog"))
{
DynamicShop.DEBUG_LOG_ENABLED = !DynamicShop.DEBUG_LOG_ENABLED;
sender.sendMessage(Constants.DYNAMIC_SHOP_PREFIX + "DebugLog " + DynamicShop.DEBUG_LOG_ENABLED);
return true;
}
else if (args[0].equalsIgnoreCase("dbg") && DynamicShop.DEBUG_MODE)
{
DynamicShop.DebugLog();
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/me/sat7/dynamicshop/guis/ItemTrade.java
Original file line number Diff line number Diff line change
Expand Up @@ -272,7 +272,7 @@ private void CreateTradeButtons(boolean sell)
int tradeLimitLeft = UserUtil.GetTradingLimitLeft(player, shopName, tradeIdxInt, HashUtil.GetItemHash(new ItemStack(Material.getMaterial(material))), sell);
if (tradeLimitLeft != Integer.MAX_VALUE)
{
String limitString = sell ? t(player, "SHOP.SALES_LIMIT_PER_PLAYER") : t(player, "SHOP.PURCHASE_LIMIT_PER_PLAYER");
String limitString = sell ? t(player, "TRADE.SALES_LIMIT_PER_PLAYER") : t(player, "TRADE.PURCHASE_LIMIT_PER_PLAYER");
String tradeLimitResetTime = ShopUtil.GetTradeLimitNextResetTime(shopName, tradeIdxInt);
tradeLimitString = limitString.replace("{num}", String.valueOf(tradeLimitLeft)).replace("{time}", tradeLimitResetTime);
}
Expand Down
7 changes: 7 additions & 0 deletions src/main/java/me/sat7/dynamicshop/transactions/Sell.java
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ public static double quickSellItem(Player player, ItemStack itemStack, String sh
if (player != null)
player.sendMessage(DynamicShop.dsPrefix(player) + t(player, "MESSAGE.NO_ITEM_TO_SELL"));

DynamicShop.PrintConsoleDbgLog("QSellFail-Player does not have an item. player:" + player + " itemType:" + itemStack.getType() + " shopName:" + shopName + " tradeIdx:" + tradeIdx);
return 0;
}

Expand All @@ -86,7 +87,10 @@ public static double quickSellItem(Player player, ItemStack itemStack, String sh
{
tradeAmount = UserUtil.CheckTradeLimitPerPlayer(player, shopName, tradeIdx, HashUtil.GetItemHash(itemStack), tradeAmount, true);
if (tradeAmount == 0)
{
DynamicShop.PrintConsoleDbgLog("QSellFail-Trading volume limit reached. player:" + player + " itemType:" + itemStack.getType() + " shopName:" + shopName + " tradeIdx:" + tradeIdx);
return 0;
}
}

// 비용 계산
Expand All @@ -96,7 +100,10 @@ public static double quickSellItem(Player player, ItemStack itemStack, String sh
// 계산된 비용에 대한 처리 시도
Economy econ = DynamicShop.getEconomy();
if (!CheckTransactionSuccess(currencyType, player, priceSum))
{
DynamicShop.PrintConsoleDbgLog("QSellFail-Transaction failed. player:" + player + " itemType:" + itemStack.getType() + " shopName:" + shopName + " tradeIdx:" + tradeIdx);
return 0;
}

// 플레이어 인벤토리에서 아이템 제거
if (player != null)
Expand Down
89 changes: 87 additions & 2 deletions src/main/java/me/sat7/dynamicshop/utilities/ShopUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -857,6 +857,7 @@ public static String[] FindTheBestShopToSell(Player player, ItemStack itemStack)
int tradeIdx = -1;

String currency = "";
ArrayList<String> failReason = new ArrayList<>();

// 접근가능한 상점중 최고가 찾기
for(Map.Entry<String, CustomConfig> entry : shopConfigFiles.entrySet())
Expand All @@ -869,40 +870,62 @@ public static String[] FindTheBestShopToSell(Player player, ItemStack itemStack)
String permission = data.get().getString("Options.permission");
if (permission != null && permission.length() > 0 && !player.hasPermission(permission) && !player.hasPermission(permission + ".sell"))
{
if (DynamicShop.DEBUG_LOG_ENABLED)
failReason.add("shopName:" + entry.getKey() + "-no permission");
continue;
}
}

// 비활성화된 상점
boolean enable = data.get().getBoolean("Options.enable", true);
if (!enable)
{
if (DynamicShop.DEBUG_LOG_ENABLED)
failReason.add("shopName:" + entry.getKey() + "-shop is disabled");
continue;
}

// 표지판 전용 상점, 지역상점, 잡포인트 상점
boolean outside = !CheckShopLocation(entry.getKey(), player);
if (outside && data.get().contains("Options.flag.localshop") && !data.get().contains("Options.flag.deliverycharge")) {
if (DynamicShop.DEBUG_LOG_ENABLED)
failReason.add("shopName:" + entry.getKey() + "-local shop");
continue;
}

if (data.get().contains("Options.flag.signshop"))
{
if (DynamicShop.DEBUG_LOG_ENABLED)
failReason.add("shopName:" + entry.getKey() + "-sign shop");
continue;
}

// 영업시간 확인
if (player != null && !CheckShopHour(entry.getKey(), player))
{
if (DynamicShop.DEBUG_LOG_ENABLED)
failReason.add("shopName:" + entry.getKey() + "-not open hours");
continue;
}

double deliveryCosts = CalcShipping(entry.getKey(), player);

if (deliveryCosts == -1)
{
if (DynamicShop.DEBUG_LOG_ENABLED)
failReason.add("shopName:" + entry.getKey() + "-Infinite Delivery Fee (Other World)");
continue;
}

int sameItemIdx = ShopUtil.findItemFromShop(entry.getKey(), itemStack);

if (sameItemIdx != -1)
{
String tradeType = data.get().getString(sameItemIdx + ".tradeType");
if (tradeType != null && tradeType.equalsIgnoreCase("BuyOnly"))
{
if (DynamicShop.DEBUG_LOG_ENABLED)
failReason.add("shopName:" + entry.getKey() + "-buy only");
continue; // 구매만 가능함
}

// 여러 재화로 취급중인 경우 지원 안함.
if (currency.isEmpty())
Expand Down Expand Up @@ -932,22 +955,32 @@ else if (!currency.equalsIgnoreCase(ShopUtil.GetCurrency(data)))
if (ShopUtil.getShopBalance(entry.getKey()) != -1 &&
ShopUtil.getShopBalance(entry.getKey()) < Calc.calcTotalCost(entry.getKey(), String.valueOf(sameItemIdx), itemStack.getAmount())[0])
{
if (DynamicShop.DEBUG_LOG_ENABLED)
failReason.add("shopName:" + entry.getKey() + "-no money in shop");
continue;
}

// 최대 재고를 넘겨서 매입 거절
int maxStock = data.get().getInt(sameItemIdx + ".maxStock", -1);
int stock = data.get().getInt(sameItemIdx + ".stock");
if (maxStock != -1 && maxStock <= stock)
{
if (DynamicShop.DEBUG_LOG_ENABLED)
failReason.add("shopName:" + entry.getKey() + "-shop reaches max stock");
continue;
}

// 플레이어 당 거래량 제한 확인
int sellLimit = ShopUtil.GetSellLimitPerPlayer(entry.getKey(), sameItemIdx);
if (player != null && sellLimit != 0)
{
int tradeAmount = UserUtil.CheckTradeLimitPerPlayer(player, entry.getKey(), sameItemIdx, HashUtil.GetItemHash(itemStack), itemStack.getAmount(), true);
if (tradeAmount == 0)
{
if (DynamicShop.DEBUG_LOG_ENABLED)
failReason.add("shopName:" + entry.getKey() + "-Reached trading volume limit");
continue;
}
}

double value = Calc.getCurrentPrice(entry.getKey(), String.valueOf(sameItemIdx), false);
Expand All @@ -963,6 +996,15 @@ else if (!currency.equalsIgnoreCase(ShopUtil.GetCurrency(data)))
}
}

if (DynamicShop.DEBUG_LOG_ENABLED && topShopName.equals("") && failReason.size() > 0)
{
DynamicShop.PrintConsoleDbgLog("No shops available for sell. player:" + player + " itemType:" + itemStack.getType() + " Details:");
for (String s : failReason)
{
DynamicShop.PrintConsoleDbgLog(" - " + s);
}
}

return new String[]{topShopName, Integer.toString(tradeIdx)};
}

Expand All @@ -974,6 +1016,8 @@ public static String[] FindTheBestShopToBuy(Player player, ItemStack itemStack)

int currencyInt = -1;

ArrayList<String> failReason = new ArrayList<>();

// 접근가능한 상점중 최저가 찾기
for(Map.Entry<String, CustomConfig> entry : shopConfigFiles.entrySet())
{
Expand All @@ -983,30 +1027,50 @@ public static String[] FindTheBestShopToBuy(Player player, ItemStack itemStack)
String permission = data.get().getString("Options.permission");
if (permission != null && permission.length() > 0 && !player.hasPermission(permission) && !player.hasPermission(permission + ".buy"))
{
if (DynamicShop.DEBUG_LOG_ENABLED)
failReason.add("shopName:" + entry.getKey() + "-no permission");
continue;
}

// 비활성화된 상점
boolean enable = data.get().getBoolean("Options.enable", true);
if (!enable)
{
if (DynamicShop.DEBUG_LOG_ENABLED)
failReason.add("shopName:" + entry.getKey() + "-shop is disabled");
continue;
}

// 표지판 전용 상점, 지역상점, 잡포인트 상점
boolean outside = !CheckShopLocation(entry.getKey(), player);
if (outside && data.get().contains("Options.flag.localshop") && !data.get().contains("Options.flag.deliverycharge")) {
if (DynamicShop.DEBUG_LOG_ENABLED)
failReason.add("shopName:" + entry.getKey() + "-local shop");
continue;
}

if (data.get().contains("Options.flag.signshop"))
{
if (DynamicShop.DEBUG_LOG_ENABLED)
failReason.add("shopName:" + entry.getKey() + "-sign shop");
continue;
}

// 영업시간 확인
if (!CheckShopHour(entry.getKey(), player))
{
if (DynamicShop.DEBUG_LOG_ENABLED)
failReason.add("shopName:" + entry.getKey() + "-not open hours");
continue;
}

double deliveryCosts = CalcShipping(entry.getKey(), player);
if (deliveryCosts == -1)
{
if (DynamicShop.DEBUG_LOG_ENABLED)
failReason.add("shopName:" + entry.getKey() + "-Infinite Delivery Fee (Other World)");
continue;
}

int sameItemIdx = ShopUtil.findItemFromShop(entry.getKey(), itemStack);

Expand All @@ -1015,12 +1079,20 @@ public static String[] FindTheBestShopToBuy(Player player, ItemStack itemStack)
String tradeType = data.get().getString(sameItemIdx + ".tradeType");

if (tradeType != null && tradeType.equalsIgnoreCase("SellOnly"))
{
if (DynamicShop.DEBUG_LOG_ENABLED)
failReason.add("shopName:" + entry.getKey() + "-sell only");
continue;
}

// 재고가 없음
int stock = data.get().getInt(sameItemIdx + ".stock");
if (stock != -1 && stock < 2)
{
if (DynamicShop.DEBUG_LOG_ENABLED)
failReason.add("shopName:" + entry.getKey() + "-Out of stock");
continue;
}

// 여러 재화로 취급중인 경우 지원 안함.
int tempCurrencyIndex = 0;
Expand Down Expand Up @@ -1066,7 +1138,11 @@ else if (currencyInt != tempCurrencyIndex)
{
int tradeAmount = UserUtil.CheckTradeLimitPerPlayer(player, entry.getKey(), sameItemIdx, HashUtil.GetItemHash(itemStack), itemStack.getAmount(), false);
if (tradeAmount == 0)
{
if (DynamicShop.DEBUG_LOG_ENABLED)
failReason.add("shopName:" + entry.getKey() + "-Trading volume limit reached");
continue;
}
}

double value = Calc.getCurrentPrice(entry.getKey(), String.valueOf(sameItemIdx), true);
Expand All @@ -1082,6 +1158,15 @@ else if (currencyInt != tempCurrencyIndex)
}
}

if (DynamicShop.DEBUG_LOG_ENABLED && topShopName.equals("") && failReason.size() > 0)
{
DynamicShop.PrintConsoleDbgLog("No shops available for purchase. player:" + player + " itemType:" + itemStack.getType() + " Details:");
for (String s : failReason)
{
DynamicShop.PrintConsoleDbgLog(" - " + s);
}
}

return new String[]{topShopName, Integer.toString(tradeIdx)};
}

Expand Down

0 comments on commit ff6588a

Please sign in to comment.