From 6962ae2590ab0ec479becb35e8d68830a5ec5b50 Mon Sep 17 00:00:00 2001 From: Phoenix616 Date: Fri, 15 Oct 2021 15:17:09 +0100 Subject: [PATCH] Added log messages to tax and discount module (#478) --- .../Listeners/Economy/TaxModule.java | 19 ++++++++++++++----- .../Listeners/Modules/DiscountModule.java | 6 +++++- 2 files changed, 19 insertions(+), 6 deletions(-) diff --git a/src/main/java/com/Acrobot/ChestShop/Listeners/Economy/TaxModule.java b/src/main/java/com/Acrobot/ChestShop/Listeners/Economy/TaxModule.java index d3b0480..8e3f411 100644 --- a/src/main/java/com/Acrobot/ChestShop/Listeners/Economy/TaxModule.java +++ b/src/main/java/com/Acrobot/ChestShop/Listeners/Economy/TaxModule.java @@ -4,8 +4,6 @@ import com.Acrobot.ChestShop.ChestShop; import com.Acrobot.ChestShop.Configuration.Properties; import com.Acrobot.ChestShop.Events.Economy.CurrencyAddEvent; import com.Acrobot.ChestShop.Events.Economy.CurrencyTransferEvent; -import com.Acrobot.ChestShop.Events.PreTransactionEvent; -import com.Acrobot.ChestShop.Events.TransactionEvent; import com.Acrobot.ChestShop.Permission; import com.Acrobot.ChestShop.UUIDs.NameManager; import org.bukkit.event.EventHandler; @@ -19,6 +17,8 @@ import java.util.UUID; * @author Acrobot */ public class TaxModule implements Listener { + private static final String TAX_RECEIVED_MESSAGE = "Applied a tax of %1$f percent (%2$.2f) to the received amount for a resulting price of %3$.2f"; + private static final String TAX_SENT_MESSAGE = "Applied a tax of %1$f percent (%2$.2f) to the sent amount for a resulting price of %3$.2f"; private static float getTax(UUID partner) { float taxAmount = NameManager.isAdminShop(partner) || NameManager.isServerEconomyAccount(partner) @@ -49,17 +49,26 @@ public class TaxModule implements Listener { if (!Permission.has(event.getInitiator(), event.getDirection() == CurrencyTransferEvent.Direction.PARTNER ? Permission.NO_BUY_TAX : Permission.NO_SELL_TAX)) { if (!NameManager.isServerEconomyAccount(event.getReceiver())) { BigDecimal tax = getTaxAmount(event.getAmountReceived(), taxAmount); - event.setAmountReceived(event.getAmountReceived().subtract(tax)); + BigDecimal taxedAmount = event.getAmountReceived().subtract(tax); + event.setAmountReceived(taxedAmount); if (NameManager.getServerEconomyAccount() != null) { ChestShop.callEvent(new CurrencyAddEvent( tax, NameManager.getServerEconomyAccount().getUuid(), event.getWorld())); } + ChestShop.getBukkitLogger().info(String.format(TAX_RECEIVED_MESSAGE, taxAmount, tax, taxedAmount)); } } else if (event.getDirection() == CurrencyTransferEvent.Direction.PARTNER && Permission.has(event.getInitiator(), Permission.NO_BUY_TAX)) { - event.setAmountSent(event.getAmountSent().subtract(getTaxAmount(event.getAmountSent(), taxAmount))); - event.setAmountReceived(event.getAmountReceived().subtract(getTaxAmount(event.getAmountReceived(), taxAmount))); + BigDecimal taxSent = getTaxAmount(event.getAmountSent(), taxAmount); + BigDecimal taxedSentAmount = event.getAmountSent().subtract(taxSent); + event.setAmountSent(taxedSentAmount); + ChestShop.getBukkitLogger().info(String.format(TAX_SENT_MESSAGE, taxAmount, taxSent, taxedSentAmount)); + + BigDecimal taxReceived = getTaxAmount(event.getAmountReceived(), taxAmount); + BigDecimal taxedReceivedAmount = event.getAmountReceived().subtract(taxSent); + event.setAmountReceived(taxedReceivedAmount); + ChestShop.getBukkitLogger().info(String.format(TAX_RECEIVED_MESSAGE, taxAmount, taxReceived, taxedReceivedAmount)); } } } diff --git a/src/main/java/com/Acrobot/ChestShop/Listeners/Modules/DiscountModule.java b/src/main/java/com/Acrobot/ChestShop/Listeners/Modules/DiscountModule.java index 2b1cbd9..cff4430 100644 --- a/src/main/java/com/Acrobot/ChestShop/Listeners/Modules/DiscountModule.java +++ b/src/main/java/com/Acrobot/ChestShop/Listeners/Modules/DiscountModule.java @@ -24,6 +24,7 @@ import static com.Acrobot.ChestShop.Signs.ChestShopSign.PRICE_LINE; * @author Acrobot */ public class DiscountModule implements Listener { + private static final String DISCOUNT_MESSAGE = "Applied a discount of %1$f percent for a resulting price of %2$.2f"; private YamlConfiguration config; private Set groupList = new HashSet(); @@ -68,7 +69,10 @@ public class DiscountModule implements Listener { for (String group : groupList) { if (Permission.has(client, Permission.DISCOUNT + group)) { - event.setExactPrice(event.getExactPrice().multiply(BigDecimal.valueOf(config.getDouble(group) / 100))); + double discount = config.getDouble(group); + BigDecimal discountedPrice = event.getExactPrice().multiply(BigDecimal.valueOf(discount / 100)); + event.setExactPrice(discountedPrice); + ChestShop.getBukkitLogger().info(String.format(DISCOUNT_MESSAGE, discount, discountedPrice)); return; } }