2012-01-25 16:32:34 +01:00
|
|
|
package com.Acrobot.ChestShop.Economy;
|
|
|
|
|
|
|
|
import com.Acrobot.ChestShop.Config.Config;
|
|
|
|
import com.Acrobot.ChestShop.Config.Property;
|
2012-05-10 16:32:25 +02:00
|
|
|
import com.Acrobot.ChestShop.Utils.uName;
|
2012-01-25 16:32:34 +01:00
|
|
|
|
2012-06-08 15:28:36 +02:00
|
|
|
import static com.Acrobot.Breeze.Utils.NumberUtil.roundUp;
|
|
|
|
|
2012-01-25 16:32:34 +01:00
|
|
|
/**
|
|
|
|
* @author Acrobot
|
|
|
|
* Economy management
|
|
|
|
*/
|
|
|
|
public class Economy {
|
2012-06-25 17:16:24 +02:00
|
|
|
private static EcoPlugin economy;
|
2012-01-25 16:32:34 +01:00
|
|
|
|
|
|
|
public static boolean hasAccount(String p) {
|
2012-05-10 16:32:25 +02:00
|
|
|
return !p.isEmpty() && economy.hasAccount(uName.getName(p));
|
2012-01-25 16:32:34 +01:00
|
|
|
}
|
|
|
|
|
2012-08-24 17:36:35 +02:00
|
|
|
public static String getServerAccountName() {
|
2012-08-18 21:53:01 +02:00
|
|
|
return Config.getString(Property.SERVER_ECONOMY_ACCOUNT);
|
|
|
|
}
|
|
|
|
|
|
|
|
public static boolean isServerAccount(String acc) {
|
2012-08-24 17:36:35 +02:00
|
|
|
return getServerAccountName().equals(acc);
|
2012-08-18 21:53:01 +02:00
|
|
|
}
|
2012-01-25 16:32:34 +01:00
|
|
|
|
2012-08-18 21:53:01 +02:00
|
|
|
public static void add(String name, double amount) {
|
|
|
|
Property taxAmount = isServerAccount(name) ? Property.SERVER_TAX_AMOUNT : Property.TAX_AMOUNT;
|
2012-01-25 16:32:34 +01:00
|
|
|
|
2012-08-18 21:53:01 +02:00
|
|
|
double tax = getTax(taxAmount, amount);
|
2012-08-24 17:36:35 +02:00
|
|
|
if (tax != 0) {
|
2012-08-18 21:53:01 +02:00
|
|
|
if (!serverAccount().isEmpty()) {
|
2012-08-24 17:36:35 +02:00
|
|
|
economy.add(getServerAccountName(), tax);
|
2012-05-10 16:32:25 +02:00
|
|
|
}
|
|
|
|
amount -= tax;
|
2012-01-25 16:32:34 +01:00
|
|
|
}
|
2012-08-18 21:53:01 +02:00
|
|
|
|
2012-08-24 17:36:35 +02:00
|
|
|
if (name.isEmpty()) return;
|
2012-08-18 21:53:01 +02:00
|
|
|
economy.add(uName.getName(name), amount);
|
2012-01-25 16:32:34 +01:00
|
|
|
}
|
|
|
|
|
2012-04-19 15:49:48 +02:00
|
|
|
public static double getTax(Property tax, double price) {
|
2012-08-18 21:53:01 +02:00
|
|
|
return roundDown((Config.getFloat(tax) / 100F) * price);
|
2012-01-25 16:32:34 +01:00
|
|
|
}
|
|
|
|
|
2012-04-19 15:49:48 +02:00
|
|
|
public static void subtract(String name, double amount) {
|
2012-08-24 17:36:35 +02:00
|
|
|
if (name.isEmpty()) return;
|
2012-06-08 15:28:36 +02:00
|
|
|
economy.subtract(uName.getName(name), roundUp(amount));
|
2012-01-25 16:32:34 +01:00
|
|
|
}
|
|
|
|
|
2012-04-19 15:49:48 +02:00
|
|
|
public static boolean hasEnough(String name, double amount) {
|
2012-08-24 17:36:35 +02:00
|
|
|
if (isServerAccount(name)) {
|
2012-05-10 16:32:25 +02:00
|
|
|
return true;
|
|
|
|
}
|
2012-06-08 15:28:36 +02:00
|
|
|
return economy.hasEnough(uName.getName(name), roundUp(amount));
|
2012-01-25 16:32:34 +01:00
|
|
|
}
|
|
|
|
|
2012-08-10 19:01:04 +02:00
|
|
|
public static double getBalance(String name) {
|
2012-05-10 16:32:25 +02:00
|
|
|
return economy.balance(uName.getName(name));
|
2012-01-25 16:32:34 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
public static String formatBalance(double amount) {
|
2012-06-08 15:28:36 +02:00
|
|
|
return economy.format(roundUp(amount));
|
2012-01-25 16:32:34 +01:00
|
|
|
}
|
2012-06-25 17:16:24 +02:00
|
|
|
|
|
|
|
public static void setPlugin(EcoPlugin plugin) {
|
|
|
|
economy = plugin;
|
|
|
|
}
|
|
|
|
|
|
|
|
public static EcoPlugin getPlugin() {
|
|
|
|
return economy;
|
|
|
|
}
|
|
|
|
|
|
|
|
public static boolean isLoaded() {
|
|
|
|
return economy != null;
|
|
|
|
}
|
2012-01-25 16:32:34 +01:00
|
|
|
}
|