Skip to content

Commit 4d7373e

Browse files
authored
Fix owner payment calculation with benefits (#2238)
1 parent aefa82e commit 4d7373e

File tree

2 files changed

+22
-7
lines changed

2 files changed

+22
-7
lines changed

quickshop-bukkit/src/main/java/com/ghostchu/quickshop/economy/transaction/QSEconomyTransaction.java

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,8 @@ public class QSEconomyTransaction implements EconomyTransaction {
6868
private @Nullable QUser to;
6969
private @Nullable QUser taxer;
7070

71+
private @NotNull BigDecimal ownerPayment;
72+
7173
private String lastError = "No transaction error logged";
7274

7375
public QSEconomyTransaction(final BenefitProvider benefitManager, @NotNull final String world,
@@ -274,6 +276,16 @@ public String lastError() {
274276
return lastError;
275277
}
276278

279+
/**
280+
* Retrieves the amount the owner actually receives after benefits and tax deductions.
281+
*
282+
* @return a BigDecimal value representing the owner payment amount
283+
*/
284+
public @NotNull BigDecimal ownerPayment() {
285+
286+
return ownerPayment;
287+
}
288+
277289
/**
278290
* Indicates whether the transaction is completable.
279291
*
@@ -354,6 +366,7 @@ public boolean commit(@NotNull final TransactionCallback callback) {
354366
//if there's no benefits
355367
if(benefitProvider.none()) {
356368

369+
this.ownerPayment = amountAfterTax;
357370
if(to != null && !this.executeOperation(new EconomyDepositOperation(to, amountAfterTax, world, currency))) {
358371

359372
this.lastError = "Failed to deposit " + amountAfterTax.toPlainString() + " to account " + to + "LastError: " + provider.lastError();
@@ -386,9 +399,9 @@ public boolean commit(@NotNull final TransactionCallback callback) {
386399
}
387400

388401

389-
final BigDecimal ownerPayment = CalculateUtil.multiply(amountAfterTax, fullAmount.subtract(payout));
402+
this.ownerPayment = CalculateUtil.multiply(amountAfterTax, fullAmount.subtract(payout));
390403
Log.transaction("Benefit for owner remaining: " + ownerPayment.toPlainString());
391-
if(ownerPayment.compareTo(BigDecimal.ZERO) > 0 && !this.executeOperation(new EconomyWithdrawOperation(to, ownerPayment, world, currency))) {
404+
if(ownerPayment.compareTo(BigDecimal.ZERO) > 0 && !this.executeOperation(new EconomyDepositOperation(to, ownerPayment, world, currency))) {
392405

393406
this.lastError = "Failed to deposit " + ownerPayment.toPlainString() + " to account " + to + "LastError: " + provider.lastError();
394407
callback.onFailed(this);
@@ -496,4 +509,4 @@ private boolean executeOperation(@NotNull final Operation operation) {
496509
return false;
497510
}
498511
}
499-
}
512+
}

quickshop-bukkit/src/main/java/com/ghostchu/quickshop/shop/SimpleShopManager.java

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -591,7 +591,7 @@ public boolean actionSelling(@NotNull final Player seller, @NotNull final Invent
591591
}
592592
sendPurchaseSuccess(sellerQUser, shop, amount, total, transaction.tax().doubleValue());
593593
new ShopSuccessPurchaseEvent(shop, sellerQUser, sellerInventory, amount, total, transaction.tax().doubleValue()).callEvent();
594-
notifyBought(sellerQUser, shop, amount, stock, transaction.tax().doubleValue(), total);
594+
notifyBought(sellerQUser, shop, amount, stock, transaction);
595595
return true;
596596
}
597597

@@ -1124,16 +1124,18 @@ public void sendShopInfo(@NotNull final Player p, @NotNull final Shop shop) {
11241124
}
11251125

11261126

1127-
private void notifyBought(@NotNull final QUser seller, @NotNull final Shop shop, final int amount, final int stock, final double tax, final double total) {
1127+
private void notifyBought(@NotNull final QUser seller, @NotNull final Shop shop, final int amount, final int stock, @NotNull final QSEconomyTransaction transaction) {
11281128

11291129
Util.asyncThreadRun(()->{
11301130
final String langCode = plugin.text().findRelativeLanguages(shop.getOwner(), true).getLocale();
11311131
final List<Component> sendList = new ArrayList<>();
11321132
Component notify;
1133+
final double ownerPayment = transaction.ownerPayment().doubleValue();
1134+
final double tax = transaction.tax().doubleValue();
11331135
if(plugin.getConfig().getBoolean("show-tax")) {
1134-
notify = plugin.text().of("player-bought-from-your-store-tax", seller, amount * shop.getItem().getAmount(), Util.getItemStackName(shop.getItem()), this.formatter.format(total - tax, shop), this.formatter.format(tax, shop)).forLocale(langCode);
1136+
notify = plugin.text().of("player-bought-from-your-store-tax", seller, amount * shop.getItem().getAmount(), Util.getItemStackName(shop.getItem()), this.formatter.format(ownerPayment, shop), this.formatter.format(tax, shop)).forLocale(langCode);
11351137
} else {
1136-
notify = plugin.text().of("player-bought-from-your-store", seller, amount * shop.getItem().getAmount(), Util.getItemStackName(shop.getItem()), this.formatter.format(total - tax, shop)).forLocale(langCode);
1138+
notify = plugin.text().of("player-bought-from-your-store", seller, amount * shop.getItem().getAmount(), Util.getItemStackName(shop.getItem()), this.formatter.format(ownerPayment, shop)).forLocale(langCode);
11371139
}
11381140
notify = plugin.platform().setItemStackHoverEvent(notify, shop.getItem());
11391141
sendList.add(notify);

0 commit comments

Comments
 (0)