2013-07-13 23:12:02 +02:00
|
|
|
package com.Acrobot.ChestShop.Listeners.Economy;
|
|
|
|
|
2013-07-13 23:14:10 +02:00
|
|
|
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;
|
2013-07-13 23:14:10 +02:00
|
|
|
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:14:10 +02:00
|
|
|
|
2013-07-13 23:12:02 +02:00
|
|
|
/**
|
|
|
|
* @author Acrobot
|
|
|
|
*/
|
2013-07-13 23:14:10 +02:00
|
|
|
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));
|
2013-07-13 23:14:10 +02:00
|
|
|
}
|
|
|
|
|
2014-06-14 20:46:59 +02:00
|
|
|
private static boolean isServerAccount(UUID name) {
|
|
|
|
return NameManager.isAdminShop(name);
|
2013-07-13 23:14:10 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@EventHandler(priority = EventPriority.LOW)
|
|
|
|
public static void onCurrencyAdd(CurrencyAddEvent event) {
|
2014-02-10 12:27:52 +01:00
|
|
|
if (event.isAdded()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2014-06-14 20:46:59 +02:00
|
|
|
UUID target = event.getTarget();
|
2013-07-13 23:14:10 +02:00
|
|
|
|
2017-11-15 21:13:07 +01:00
|
|
|
if (NameManager.isServerEconomyAccount(target)) {
|
2013-07-13 23:14:10 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
float taxAmount = isServerAccount(target) ? Properties.SERVER_TAX_AMOUNT : Properties.TAX_AMOUNT;
|
|
|
|
|
|
|
|
if (taxAmount == 0) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
BigDecimal tax = getTax(event.getAmount(), taxAmount);
|
|
|
|
|
2017-11-15 21:13:07 +01:00
|
|
|
if (NameManager.getServerEconomyAccount() != null) {
|
|
|
|
CurrencyAddEvent currencyAddEvent = new CurrencyAddEvent(
|
|
|
|
tax,
|
|
|
|
NameManager.getServerEconomyAccount().getUuid(),
|
|
|
|
event.getWorld());
|
2013-07-13 23:14:10 +02:00
|
|
|
ChestShop.callEvent(currencyAddEvent);
|
|
|
|
}
|
|
|
|
|
|
|
|
event.setAmount(event.getAmount().subtract(tax));
|
|
|
|
}
|
2013-07-13 23:12:02 +02:00
|
|
|
}
|