62 lines
1.6 KiB
Java

package net.knarcraft.paidsigns.manager;
import net.milkbowl.vault.economy.Economy;
import org.bukkit.OfflinePlayer;
/**
* A manager that performs all Economy tasks
*/
public final class EconomyManager {
private static Economy economy;
private EconomyManager() {
}
/**
* Initializes the economy manager
*
* @param economy <p>The economy object to use for everything economy-related</p>
*/
public static void initialize(Economy economy) {
EconomyManager.economy = economy;
}
/**
* Checks whether the given player can afford the given cost
*
* @param player <p>The player to pay the cost</p>
* @param cost <p>The cost the player needs to pay</p>
* @return <p>True if the player is able to afford the cost</p>
*/
public static boolean canAfford(OfflinePlayer player, double cost) {
return economy.has(player, cost);
}
/**
* Gets the name of the used currency
*
* @param plural <p>Whether to get the plural name or the singular name</p>
* @return <p>The name of the used currency</p>
*/
public static String getCurrency(boolean plural) {
if (plural) {
return economy.currencyNamePlural();
} else {
return economy.currencyNameSingular();
}
}
/**
* Withdraws the given cost from the given player's account
*
* @param player <p>The player to withdraw money from</p>
* @param cost <p>The amount of money to withdraw</p>
*/
public static void withdraw(OfflinePlayer player, double cost) {
economy.withdrawPlayer(player, cost);
}
}