ChestShop-3/com/Acrobot/ChestShop/Economy/Economy.java

100 lines
2.9 KiB
Java
Raw Normal View History

package com.Acrobot.ChestShop.Economy;
2012-09-02 22:41:24 +02:00
import com.Acrobot.Breeze.Utils.NumberUtil;
import com.Acrobot.ChestShop.Configuration.Properties;
2012-09-02 22:41:24 +02:00
import com.Acrobot.ChestShop.Signs.ChestShopSign;
import com.Acrobot.ChestShop.Utils.uName;
2012-09-15 20:32:22 +02:00
import org.bukkit.inventory.Inventory;
import static com.Acrobot.Breeze.Utils.NumberUtil.roundUp;
/**
* @author Acrobot
* Economy management
*/
public class Economy {
private static EconomyManager manager = new EconomyManager();
2012-09-15 20:32:22 +02:00
public static boolean isOwnerEconomicallyActive(Inventory inventory) {
return !ChestShopSign.isAdminShop(inventory) || !getServerAccountName().isEmpty();
2012-09-15 20:32:22 +02:00
}
public static boolean hasAccount(String player) {
return !player.isEmpty() && manager.hasAccount(uName.getName(player));
}
public static String getServerAccountName() {
return Properties.SERVER_ECONOMY_ACCOUNT;
}
2012-09-02 22:41:24 +02:00
public static boolean isServerAccount(String acc) {
2012-09-02 22:41:24 +02:00
return ChestShopSign.isAdminShop(acc);
}
public static boolean add(String name, double amount) {
2012-11-03 20:40:30 +01:00
if (isServerAccount(name) && !getServerAccountName().isEmpty()) {
name = getServerAccountName();
}
float taxAmount = isServerAccount(name) ? Properties.SERVER_TAX_AMOUNT : Properties.TAX_AMOUNT;
double tax = getTax(taxAmount, amount);
if (tax != 0) {
2012-09-02 22:41:24 +02:00
if (!getServerAccountName().isEmpty()) {
manager.add(getServerAccountName(), tax);
}
amount -= tax;
}
2012-09-02 22:41:24 +02:00
return manager.add(uName.getName(name), amount);
}
public static double getTax(float tax, double price) {
return NumberUtil.roundDown((tax / 100F) * price);
}
public static boolean subtract(String name, double amount) {
2012-11-03 20:40:30 +01:00
if (isServerAccount(name) && !getServerAccountName().isEmpty()) {
name = getServerAccountName();
}
return manager.subtract(uName.getName(name), roundUp(amount));
}
public static boolean hasEnough(String name, double amount) {
2012-09-12 12:35:48 +02:00
if (amount <= 0) {
return true;
}
2012-11-03 20:40:30 +01:00
if (isServerAccount(name) && !getServerAccountName().isEmpty()) {
name = getServerAccountName();
}
2012-09-12 12:35:48 +02:00
return manager.hasEnough(uName.getName(name), roundUp(amount));
}
public static double getBalance(String name) {
2012-11-03 20:40:30 +01:00
if (isServerAccount(name) && !getServerAccountName().isEmpty()) {
name = getServerAccountName();
}
return manager.balance(uName.getName(name));
}
public static String formatBalance(double amount) {
return manager.format(roundUp(amount));
}
2012-06-25 17:16:24 +02:00
public static void setPlugin(EconomyManager plugin) {
manager = plugin;
2012-06-25 17:16:24 +02:00
}
public static EconomyManager getManager() {
return manager;
2012-06-25 17:16:24 +02:00
}
public static boolean isLoaded() {
return manager.getClass() != EconomyManager.class;
2012-06-25 17:16:24 +02:00
}
}