Files
PaidSigns/src/main/java/net/knarcraft/paidsigns/manager/EconomyManager.java

72 lines
1.9 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);
}
/**
* Deposits a given sum into the given player's account
*
* @param player <p>The player to deposit money to</p>
* @param sum <p>The amount of money to deposit</p>
*/
public static void deposit(OfflinePlayer player, double sum) {
economy.depositPlayer(player, sum);
}
}