Adds the EconomyManager class for handling Vault payments Adds the unfinished PermissionManager class for granting permissions through Vault Adds the GPLv3 license Fixes dependencies Adds some code for withdrawing money and granting permissions when a sign is clicked Changes cost to a double to be compliant with Vault
59 lines
1.6 KiB
Java
59 lines
1.6 KiB
Java
package net.knarcraft.permissionsigns.manager;
|
|
|
|
import net.milkbowl.vault.economy.Economy;
|
|
import org.bukkit.OfflinePlayer;
|
|
import org.bukkit.entity.Player;
|
|
|
|
/**
|
|
* A manager that performs all Economy tasks
|
|
*/
|
|
public class EconomyManager {
|
|
|
|
private static Economy economy;
|
|
|
|
/**
|
|
* 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(Player player, double cost) {
|
|
economy.withdrawPlayer(player, cost);
|
|
}
|
|
|
|
}
|