Added log messages to tax and discount module (#478)

This commit is contained in:
Phoenix616 2021-10-15 15:17:09 +01:00
parent 03317c2c78
commit 6962ae2590
No known key found for this signature in database
GPG Key ID: 40E2321E71738EB0
2 changed files with 19 additions and 6 deletions

View File

@ -4,8 +4,6 @@ import com.Acrobot.ChestShop.ChestShop;
import com.Acrobot.ChestShop.Configuration.Properties; import com.Acrobot.ChestShop.Configuration.Properties;
import com.Acrobot.ChestShop.Events.Economy.CurrencyAddEvent; import com.Acrobot.ChestShop.Events.Economy.CurrencyAddEvent;
import com.Acrobot.ChestShop.Events.Economy.CurrencyTransferEvent; 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.Permission;
import com.Acrobot.ChestShop.UUIDs.NameManager; import com.Acrobot.ChestShop.UUIDs.NameManager;
import org.bukkit.event.EventHandler; import org.bukkit.event.EventHandler;
@ -19,6 +17,8 @@ import java.util.UUID;
* @author Acrobot * @author Acrobot
*/ */
public class TaxModule implements Listener { 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) { private static float getTax(UUID partner) {
float taxAmount = NameManager.isAdminShop(partner) || NameManager.isServerEconomyAccount(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 (!Permission.has(event.getInitiator(), event.getDirection() == CurrencyTransferEvent.Direction.PARTNER ? Permission.NO_BUY_TAX : Permission.NO_SELL_TAX)) {
if (!NameManager.isServerEconomyAccount(event.getReceiver())) { if (!NameManager.isServerEconomyAccount(event.getReceiver())) {
BigDecimal tax = getTaxAmount(event.getAmountReceived(), taxAmount); 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) { if (NameManager.getServerEconomyAccount() != null) {
ChestShop.callEvent(new CurrencyAddEvent( ChestShop.callEvent(new CurrencyAddEvent(
tax, tax,
NameManager.getServerEconomyAccount().getUuid(), NameManager.getServerEconomyAccount().getUuid(),
event.getWorld())); 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)) { } else if (event.getDirection() == CurrencyTransferEvent.Direction.PARTNER && Permission.has(event.getInitiator(), Permission.NO_BUY_TAX)) {
event.setAmountSent(event.getAmountSent().subtract(getTaxAmount(event.getAmountSent(), taxAmount))); BigDecimal taxSent = getTaxAmount(event.getAmountSent(), taxAmount);
event.setAmountReceived(event.getAmountReceived().subtract(getTaxAmount(event.getAmountReceived(), 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));
} }
} }
} }

View File

@ -24,6 +24,7 @@ import static com.Acrobot.ChestShop.Signs.ChestShopSign.PRICE_LINE;
* @author Acrobot * @author Acrobot
*/ */
public class DiscountModule implements Listener { 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 YamlConfiguration config;
private Set<String> groupList = new HashSet<String>(); private Set<String> groupList = new HashSet<String>();
@ -68,7 +69,10 @@ public class DiscountModule implements Listener {
for (String group : groupList) { for (String group : groupList) {
if (Permission.has(client, Permission.DISCOUNT + group)) { 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; return;
} }
} }