2011-12-03 19:35:49 +01:00
|
|
|
package net.milkbowl.vault.economy.plugins;
|
|
|
|
|
2011-12-22 22:32:38 +01:00
|
|
|
import java.util.ArrayList;
|
|
|
|
import java.util.List;
|
2011-12-03 19:35:49 +01:00
|
|
|
import java.util.logging.Logger;
|
|
|
|
|
2012-01-26 01:06:29 +01:00
|
|
|
import net.milkbowl.vault.economy.Economy;
|
|
|
|
import net.milkbowl.vault.economy.EconomyResponse;
|
|
|
|
import net.milkbowl.vault.economy.EconomyResponse.ResponseType;
|
|
|
|
|
|
|
|
import org.bukkit.Bukkit;
|
2011-12-03 19:35:49 +01:00
|
|
|
import org.bukkit.OfflinePlayer;
|
2012-01-26 01:06:29 +01:00
|
|
|
import org.bukkit.event.EventHandler;
|
|
|
|
import org.bukkit.event.EventPriority;
|
|
|
|
import org.bukkit.event.Listener;
|
2011-12-03 19:35:49 +01:00
|
|
|
import org.bukkit.event.server.PluginDisableEvent;
|
|
|
|
import org.bukkit.event.server.PluginEnableEvent;
|
|
|
|
import org.bukkit.plugin.Plugin;
|
|
|
|
|
|
|
|
import ca.agnate.EconXP.EconXP;
|
|
|
|
|
|
|
|
public class Economy_EconXP implements Economy {
|
2012-01-28 20:15:41 +01:00
|
|
|
private static final Logger log = Logger.getLogger("Minecraft");
|
|
|
|
|
|
|
|
private String name = "EconXP";
|
|
|
|
private Plugin plugin = null;
|
|
|
|
private EconXP econ = null;
|
|
|
|
|
|
|
|
public Economy_EconXP(Plugin plugin) {
|
|
|
|
this.plugin = plugin;
|
|
|
|
Bukkit.getServer().getPluginManager().registerEvents(new EconomyServerListener(this), plugin);
|
|
|
|
|
|
|
|
// Load Plugin in case it was loaded before
|
|
|
|
if (econ == null) {
|
|
|
|
Plugin econ = plugin.getServer().getPluginManager().getPlugin("EconXP");
|
|
|
|
if (econ != null && econ.isEnabled()) {
|
|
|
|
this.econ = (EconXP) econ;
|
|
|
|
log.info(String.format("[%s][Economy] %s hooked.", plugin.getDescription().getName(), name));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public class EconomyServerListener implements Listener {
|
|
|
|
Economy_EconXP economy = null;
|
|
|
|
|
|
|
|
public EconomyServerListener(Economy_EconXP economy) {
|
|
|
|
this.economy = economy;
|
|
|
|
}
|
|
|
|
|
|
|
|
@EventHandler(priority = EventPriority.MONITOR)
|
|
|
|
public void onPluginEnable(PluginEnableEvent event) {
|
|
|
|
if (economy.econ == null) {
|
|
|
|
Plugin eco = plugin.getServer().getPluginManager().getPlugin("EconXP");
|
|
|
|
|
|
|
|
if (eco != null && eco.isEnabled()) {
|
|
|
|
economy.econ = (EconXP) eco;
|
|
|
|
log.info(String.format("[%s][Economy] %s hooked.", plugin.getDescription().getName(), economy.name));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@EventHandler(priority = EventPriority.MONITOR)
|
|
|
|
public void onPluginDisable(PluginDisableEvent event) {
|
|
|
|
if (economy.econ != null) {
|
|
|
|
if (event.getPlugin().getDescription().getName().equals("EconXP")) {
|
|
|
|
economy.econ = null;
|
|
|
|
log.info(String.format("[%s][Economy] %s unhooked.", plugin.getDescription().getName(), economy.name));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean isEnabled() {
|
|
|
|
return this.econ != null;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public String getName() {
|
|
|
|
return name;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public String format(double amount) {
|
|
|
|
amount = Math.ceil(amount);
|
|
|
|
|
|
|
|
return String.format("%d %s", (int)amount, "experience");
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public double getBalance(String playerName) {
|
|
|
|
OfflinePlayer player = econ.getPlayer(playerName);
|
|
|
|
|
|
|
|
if ( player == null ) { return 0; }
|
|
|
|
|
|
|
|
return econ.getExp(player);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean has(String playerName, double amount) {
|
|
|
|
OfflinePlayer player = econ.getPlayer(playerName);
|
|
|
|
|
2011-12-03 19:35:49 +01:00
|
|
|
if ( player == null ) { return false; }
|
2012-01-28 20:15:41 +01:00
|
|
|
|
|
|
|
return econ.hasExp(player, (int) Math.ceil(amount) );
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public EconomyResponse withdrawPlayer(String playerName, double amount) {
|
|
|
|
OfflinePlayer player = econ.getPlayer(playerName);
|
|
|
|
|
2011-12-03 19:35:49 +01:00
|
|
|
if ( player == null ) {
|
|
|
|
return new EconomyResponse(0, 0, ResponseType.FAILURE, "Player does not exist");
|
|
|
|
}
|
2012-01-28 20:15:41 +01:00
|
|
|
|
|
|
|
double balance = econ.getExp(player);
|
|
|
|
amount = Math.ceil(amount);
|
|
|
|
|
|
|
|
if (amount < 0) {
|
2011-12-03 19:35:49 +01:00
|
|
|
return new EconomyResponse(0, balance, ResponseType.FAILURE, "Cannot withdraw negative funds");
|
|
|
|
}
|
2012-01-28 20:15:41 +01:00
|
|
|
|
|
|
|
if ( econ.hasExp(player, (int) amount) == false ) {
|
|
|
|
return new EconomyResponse(0, balance, ResponseType.FAILURE, "Insufficient funds");
|
|
|
|
}
|
|
|
|
|
|
|
|
econ.removeExp(player, (int) amount);
|
|
|
|
|
|
|
|
double finalBalance = econ.getExp(player);
|
|
|
|
|
2011-12-03 19:35:49 +01:00
|
|
|
return new EconomyResponse(amount, finalBalance, ResponseType.SUCCESS, null);
|
2012-01-28 20:15:41 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public EconomyResponse depositPlayer(String playerName, double amount) {
|
|
|
|
OfflinePlayer player = econ.getPlayer(playerName);
|
2011-12-03 19:35:49 +01:00
|
|
|
|
|
|
|
if ( player == null ) {
|
|
|
|
return new EconomyResponse(0, 0, ResponseType.FAILURE, "Player does not exist");
|
|
|
|
}
|
2012-01-28 20:15:41 +01:00
|
|
|
|
2011-12-03 19:35:49 +01:00
|
|
|
double balance = econ.getExp(player);
|
|
|
|
amount = Math.ceil(amount);
|
2012-01-28 20:15:41 +01:00
|
|
|
|
2011-12-03 19:35:49 +01:00
|
|
|
if (amount < 0) {
|
|
|
|
return new EconomyResponse(0, balance, ResponseType.FAILURE, "Cannot withdraw negative funds");
|
|
|
|
}
|
2012-01-28 20:15:41 +01:00
|
|
|
|
2011-12-03 19:35:49 +01:00
|
|
|
econ.addExp(player, (int) amount );
|
2012-01-28 20:15:41 +01:00
|
|
|
balance = econ.getExp(player);
|
|
|
|
|
|
|
|
return new EconomyResponse(amount, balance, ResponseType.SUCCESS, null);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public EconomyResponse createBank(String name, String player) {
|
|
|
|
return new EconomyResponse(0, 0, ResponseType.NOT_IMPLEMENTED, "EconXP does not support bank accounts!");
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public EconomyResponse deleteBank(String name) {
|
|
|
|
return new EconomyResponse(0, 0, ResponseType.NOT_IMPLEMENTED, "EconXP does not support bank accounts!");
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public EconomyResponse bankHas(String name, double amount) {
|
|
|
|
return new EconomyResponse(0, 0, ResponseType.NOT_IMPLEMENTED, "EconXP does not support bank accounts!");
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public EconomyResponse bankWithdraw(String name, double amount) {
|
|
|
|
return new EconomyResponse(0, 0, ResponseType.NOT_IMPLEMENTED, "EconXP does not support bank accounts!");
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public EconomyResponse bankDeposit(String name, double amount) {
|
|
|
|
return new EconomyResponse(0, 0, ResponseType.NOT_IMPLEMENTED, "EconXP does not support bank accounts!");
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public EconomyResponse isBankOwner(String name, String playerName) {
|
|
|
|
return new EconomyResponse(0, 0, ResponseType.NOT_IMPLEMENTED, "EconXP does not support bank accounts!");
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public EconomyResponse isBankMember(String name, String playerName) {
|
|
|
|
return new EconomyResponse(0, 0, ResponseType.NOT_IMPLEMENTED, "EconXP does not support bank accounts!");
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public EconomyResponse bankBalance(String name) {
|
|
|
|
return new EconomyResponse(0, 0, ResponseType.NOT_IMPLEMENTED, "EconXP does not support bank accounts!");
|
|
|
|
}
|
|
|
|
|
2011-12-22 22:32:38 +01:00
|
|
|
@Override
|
|
|
|
public List<String> getBanks() {
|
|
|
|
return new ArrayList<String>();
|
|
|
|
}
|
2012-01-28 20:15:41 +01:00
|
|
|
|
2012-01-02 19:19:29 +01:00
|
|
|
@Override
|
|
|
|
public boolean hasBankSupport() {
|
|
|
|
return false;
|
|
|
|
}
|
2012-01-02 19:50:16 +01:00
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean hasAccount(String playerName) {
|
|
|
|
return econ.getPlayer(playerName) != null;
|
|
|
|
}
|
2012-01-15 20:55:14 +01:00
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean createPlayerAccount(String playerName) {
|
|
|
|
return false;
|
|
|
|
}
|
2011-12-03 19:35:49 +01:00
|
|
|
}
|