2012-01-25 16:32:34 +01:00
|
|
|
package com.Acrobot.ChestShop.Economy;
|
|
|
|
|
2012-09-02 22:41:24 +02:00
|
|
|
import com.Acrobot.Breeze.Utils.NumberUtil;
|
2012-01-25 16:32:34 +01:00
|
|
|
import com.Acrobot.ChestShop.Config.Config;
|
|
|
|
import com.Acrobot.ChestShop.Config.Property;
|
2012-09-02 22:41:24 +02:00
|
|
|
import com.Acrobot.ChestShop.Signs.ChestShopSign;
|
2012-05-10 16:32:25 +02:00
|
|
|
import com.Acrobot.ChestShop.Utils.uName;
|
2012-09-15 20:32:22 +02:00
|
|
|
import org.bukkit.inventory.Inventory;
|
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
|
|
|
|
2012-09-15 20:32:22 +02:00
|
|
|
public static boolean isOwnerEconomicallyActive(Inventory inventory) {
|
2012-09-20 22:38:11 +02:00
|
|
|
return !ChestShopSign.isAdminShop(inventory) || !getServerAccountName().isEmpty();
|
2012-09-15 20:32:22 +02:00
|
|
|
}
|
|
|
|
|
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);
|
|
|
|
}
|
2012-09-02 22:41:24 +02:00
|
|
|
|
2012-08-18 21:53:01 +02:00
|
|
|
public static boolean isServerAccount(String acc) {
|
2012-09-02 22:41:24 +02:00
|
|
|
return ChestShopSign.isAdminShop(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-09-02 22:41:24 +02:00
|
|
|
if (!getServerAccountName().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-09-02 22:41:24 +02:00
|
|
|
|
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-09-02 22:41:24 +02:00
|
|
|
return NumberUtil.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-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-09-12 12:35:48 +02:00
|
|
|
if (amount <= 0) {
|
|
|
|
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
|
|
|
}
|