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-04-19 15:49:48 +02:00
|
|
|
public static void add(String name, double amount) {
|
2012-05-10 16:32:25 +02:00
|
|
|
if (!hasAccount(name)) {
|
|
|
|
return;
|
2012-01-25 16:32:34 +01:00
|
|
|
}
|
|
|
|
|
2012-05-10 16:32:25 +02:00
|
|
|
String serverAccount = Config.getString(Property.SERVER_ECONOMY_ACCOUNT);
|
|
|
|
Property taxAmount = name.equals(serverAccount) ? Property.SERVER_TAX_AMOUNT : Property.TAX_AMOUNT;
|
2012-01-25 16:32:34 +01:00
|
|
|
|
2012-05-10 16:32:25 +02:00
|
|
|
if (Config.getFloat(taxAmount) != 0) {
|
|
|
|
double tax = getTax(taxAmount, amount);
|
|
|
|
if (!serverAccount.isEmpty()) {
|
|
|
|
economy.add(serverAccount, tax);
|
|
|
|
}
|
|
|
|
amount -= tax;
|
2012-01-25 16:32:34 +01:00
|
|
|
}
|
2012-05-10 16:32:25 +02:00
|
|
|
|
2012-06-08 15:28:36 +02:00
|
|
|
economy.add(uName.getName(name), roundUp(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-01-25 16:32:34 +01:00
|
|
|
return (Config.getFloat(tax) / 100F) * price;
|
|
|
|
}
|
|
|
|
|
2012-04-19 15:49:48 +02:00
|
|
|
public static void subtract(String name, double amount) {
|
2012-05-10 16:32:25 +02:00
|
|
|
if (!hasAccount(name)) {
|
|
|
|
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-05-10 16:32:25 +02:00
|
|
|
if (!hasAccount(name)) {
|
|
|
|
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
|
|
|
}
|