Skip to content

Commit

Permalink
Fix potential error when there is zero stock
Browse files Browse the repository at this point in the history
  • Loading branch information
Phoenix616 committed Jan 5, 2025
1 parent 266e65f commit 66c3bfe
Showing 1 changed file with 12 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,14 @@ public static void onPreBuyTransaction(PreTransactionEvent event) {
return;
}

int itemCount = InventoryUtil.countItems(event.getStock());
if (itemCount <= 0) {
return;
}

Player client = event.getClient();

BigDecimal pricePerItem = event.getExactPrice().divide(BigDecimal.valueOf(InventoryUtil.countItems(event.getStock())), MathContext.DECIMAL128);
BigDecimal pricePerItem = event.getExactPrice().divide(BigDecimal.valueOf(itemCount), MathContext.DECIMAL128);

CurrencyAmountEvent currencyAmountEvent = new CurrencyAmountEvent(client);
ChestShop.callEvent(currencyAmountEvent);
Expand Down Expand Up @@ -122,10 +127,15 @@ public static void onPreSellTransaction(PreTransactionEvent event) {
return;
}

int itemCount = InventoryUtil.countItems(event.getStock());
if (itemCount <= 0) {
return;
}

Player client = event.getClient();
UUID owner = event.getOwnerAccount().getUuid();

BigDecimal pricePerItem = event.getExactPrice().divide(BigDecimal.valueOf(InventoryUtil.countItems(event.getStock())), MathContext.DECIMAL128);
BigDecimal pricePerItem = event.getExactPrice().divide(BigDecimal.valueOf(itemCount), MathContext.DECIMAL128);


if (Economy.isOwnerEconomicallyActive(event.getOwnerInventory())) {
Expand Down

0 comments on commit 66c3bfe

Please sign in to comment.