1
0
mirror of https://github.com/Zrips/Jobs.git synced 2024-12-11 03:44:18 +01:00
Jobs/com/gamingmesh/jobs/economy/IConomyAdapter.java

76 lines
1.8 KiB
Java
Raw Normal View History

package com.gamingmesh.jobs.economy;
import org.bukkit.OfflinePlayer;
import com.iCo6.iConomy;
import com.iCo6.system.Accounts;
2016-11-20 10:53:19 +01:00
public class IConomyAdapter implements Economy {
iConomy icon;
2016-11-20 10:53:19 +01:00
public IConomyAdapter(iConomy iconomy) {
icon = iconomy;
}
public double getBalance(String playerName) {
checkExist(playerName);
return new Accounts().get(playerName).getHoldings().getBalance();
}
@Override
public boolean hasMoney(OfflinePlayer offlinePlayer, double amount) {
return hasMoney(offlinePlayer.getName(), amount);
}
@Override
public boolean hasMoney(String PlayerName, double amount) {
checkExist(PlayerName);
double holdings = this.getBalance(PlayerName);
if (holdings >= amount) {
return true;
}
return false;
}
@Override
public boolean depositPlayer(String PlayerName, double amount) {
checkExist(PlayerName);
new Accounts().get(PlayerName).getHoldings().add(amount);
return true;
}
@Override
public boolean depositPlayer(OfflinePlayer offlinePlayer, double amount) {
return depositPlayer(offlinePlayer.getName(), amount);
}
@Override
public boolean withdrawPlayer(String playerName, double amount) {
checkExist(playerName);
if (this.hasMoney(playerName, amount)) {
new Accounts().get(playerName).getHoldings().subtract(amount);
return true;
}
return false;
}
@Override
public boolean withdrawPlayer(OfflinePlayer offlinePlayer, double amount) {
return withdrawPlayer(offlinePlayer.getName(), amount);
}
@Override
public String format(double money) {
return iConomy.format(money);
}
private static void checkExist(String playerName) {
Accounts acc = new Accounts();
if (!acc.exists(playerName)) {
acc.create(playerName);
}
}
}