ChestShop-3/src/main/java/com/Acrobot/ChestShop/Listeners/Economy/TaxModule.java

59 lines
1.7 KiB
Java
Raw Normal View History

2013-07-13 23:12:02 +02:00
package com.Acrobot.ChestShop.Listeners.Economy;
import com.Acrobot.ChestShop.ChestShop;
import com.Acrobot.ChestShop.Configuration.Properties;
import com.Acrobot.ChestShop.Economy.Economy;
import com.Acrobot.ChestShop.Events.Economy.CurrencyAddEvent;
2014-06-14 20:46:59 +02:00
import com.Acrobot.ChestShop.UUIDs.NameManager;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener;
import java.math.BigDecimal;
2014-06-14 20:46:59 +02:00
import java.util.UUID;
2013-07-13 23:12:02 +02:00
/**
* @author Acrobot
*/
public class TaxModule implements Listener {
private static BigDecimal getTax(BigDecimal price, float taxAmount) {
2015-01-08 20:12:53 +01:00
return price.multiply(BigDecimal.valueOf(taxAmount).divide(BigDecimal.valueOf(100), BigDecimal.ROUND_DOWN));
}
2014-06-14 20:46:59 +02:00
private static boolean isServerAccount(UUID name) {
return NameManager.isAdminShop(name);
}
@EventHandler(priority = EventPriority.LOW)
public static void onCurrencyAdd(CurrencyAddEvent event) {
if (event.isAdded()) {
return;
}
2014-06-14 20:46:59 +02:00
UUID target = event.getTarget();
if (NameManager.isServerEconomyAccount(target)) {
return;
}
float taxAmount = isServerAccount(target) ? Properties.SERVER_TAX_AMOUNT : Properties.TAX_AMOUNT;
if (taxAmount == 0) {
return;
}
BigDecimal tax = getTax(event.getAmount(), taxAmount);
if (NameManager.getServerEconomyAccount() != null) {
CurrencyAddEvent currencyAddEvent = new CurrencyAddEvent(
tax,
NameManager.getServerEconomyAccount().getUuid(),
event.getWorld());
ChestShop.callEvent(currencyAddEvent);
}
event.setAmount(event.getAmount().subtract(tax));
}
2013-07-13 23:12:02 +02:00
}