mirror of
https://github.com/songoda/SongodaCore.git
synced 2024-11-23 18:45:34 +01:00
Added Economy option.
This commit is contained in:
parent
288eae8f47
commit
2ea41e962d
@ -61,6 +61,19 @@ public class EconomyManager {
|
||||
return manager.isEnabled() ? manager.getCurrentHook().formatEconomy(amt) : String.valueOf(amt);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the players available balance
|
||||
*
|
||||
* @param player player
|
||||
* @return the amount of available balance
|
||||
*/
|
||||
public static double getBalance(OfflinePlayer player) {
|
||||
if (!manager.isEnabled())
|
||||
return 0;
|
||||
return manager.getCurrentHook().getBalance(player);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Check to see if a player has at least some balance available. <br />
|
||||
* NOTE: using a default economy assumes that this library is shaded
|
||||
|
@ -6,6 +6,14 @@ import org.bukkit.OfflinePlayer;
|
||||
|
||||
public abstract class Economy implements Hook {
|
||||
|
||||
/**
|
||||
* Get the players available balance
|
||||
*
|
||||
* @param player player
|
||||
* @return the amount of available balance
|
||||
*/
|
||||
public abstract double getBalance(OfflinePlayer player);
|
||||
|
||||
/**
|
||||
* Check to see if a player has at least some balance available
|
||||
*
|
||||
|
@ -26,6 +26,11 @@ public class PlayerPointsEconomy extends Economy {
|
||||
return "PlayerPoints";
|
||||
}
|
||||
|
||||
@Override
|
||||
public double getBalance(OfflinePlayer player) {
|
||||
return playerPoints.getAPI().look(player.getUniqueId());
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasBalance(OfflinePlayer player, double cost) {
|
||||
int amount = convertAmount(cost);
|
||||
|
@ -30,6 +30,11 @@ public class ReserveEconomy extends Economy {
|
||||
return economyAPI.format(BigDecimal.valueOf(amt));
|
||||
}
|
||||
|
||||
@Override
|
||||
public double getBalance(OfflinePlayer player) {
|
||||
return economyAPI.getBankHoldings(player.getUniqueId()).doubleValue();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasBalance(OfflinePlayer player, double cost) {
|
||||
return economyAPI.hasHoldings(player.getUniqueId(), new BigDecimal(cost));
|
||||
|
@ -9,7 +9,7 @@ public class VaultEconomy extends Economy {
|
||||
private final net.milkbowl.vault.economy.Economy vault;
|
||||
|
||||
public VaultEconomy() {
|
||||
// this returns null if we have Vault with no compatibe eco plugin
|
||||
// this returns null if we have Vault with no compatible eco plugin
|
||||
RegisteredServiceProvider<net.milkbowl.vault.economy.Economy> v = Bukkit.getServicesManager().getRegistration(net.milkbowl.vault.economy.Economy.class);
|
||||
if(v != null) {
|
||||
this.vault = v.getProvider();
|
||||
@ -34,6 +34,13 @@ public class VaultEconomy extends Economy {
|
||||
return vault != null ? vault.format(amt) : super.formatEconomy(amt);
|
||||
}
|
||||
|
||||
@Override
|
||||
public double getBalance(OfflinePlayer player) {
|
||||
if (vault == null)
|
||||
return 0;
|
||||
return vault.getBalance(player);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasBalance(OfflinePlayer player, double cost) {
|
||||
return vault != null && vault.has(player, cost);
|
||||
|
Loading…
Reference in New Issue
Block a user