diff --git a/lib/Craftconomy.jar b/lib/Craftconomy.jar
new file mode 100644
index 0000000..4e6b8fc
Binary files /dev/null and b/lib/Craftconomy.jar differ
diff --git a/plugin.yml b/plugin.yml
index 25fe65d..0276c8a 100644
--- a/plugin.yml
+++ b/plugin.yml
@@ -1,6 +1,6 @@
name: Vault
main: net.milkbowl.vault.Vault
-version: 1.2.4-b${BUILD_NUMBER}
+version: 1.2.5-b${BUILD_NUMBER}
authors: [cereal, Sleaker, mung3r]
website: http://dev.bukkit.org/server-mods/vault
load: startup
diff --git a/pom.xml b/pom.xml
index 676fd8e..145783a 100644
--- a/pom.xml
+++ b/pom.xml
@@ -179,6 +179,13 @@
${project.basedir}/lib/Register.jar
1.5
+
+ me.greatman.Craftconomy
+ Craftconomy
+ 1.0.0
+ system
+ ${project.basedir}/lib/Craftconomy.jar
+
diff --git a/src/net/milkbowl/vault/Vault.java b/src/net/milkbowl/vault/Vault.java
index 6fd561f..c04a1d3 100644
--- a/src/net/milkbowl/vault/Vault.java
+++ b/src/net/milkbowl/vault/Vault.java
@@ -40,6 +40,7 @@ import net.milkbowl.vault.economy.Economy;
import net.milkbowl.vault.economy.plugins.Economy_3co;
import net.milkbowl.vault.economy.plugins.Economy_BOSE6;
import net.milkbowl.vault.economy.plugins.Economy_BOSE7;
+import net.milkbowl.vault.economy.plugins.Economy_Craftconomy;
import net.milkbowl.vault.economy.plugins.Economy_CurrencyCore;
import net.milkbowl.vault.economy.plugins.Economy_EconXP;
import net.milkbowl.vault.economy.plugins.Economy_Essentials;
@@ -214,6 +215,13 @@ public class Vault extends JavaPlugin {
}
+ //Try Loading Craftconomy
+ if (packageExists(new String[] {"me.greatman.Craftconomy.Craftconomy"})) {
+ Economy econ = new Economy_Craftconomy(this);
+ sm.register(Economy.class, econ, this, ServicePriority.Normal);
+ log.info(String.format("[%s][Economy] CraftConomy found: %s", getDescription().getName(), econ.isEnabled() ? "Loaded" : "Waiting"));
+ }
+
//Try loading eWallet
if (packageExists(new String[] { "me.ethan.eWallet.ECO" })) {
Economy econ = new Economy_eWallet(this);
diff --git a/src/net/milkbowl/vault/economy/plugins/Economy_Craftconomy.java b/src/net/milkbowl/vault/economy/plugins/Economy_Craftconomy.java
new file mode 100644
index 0000000..feb4688
--- /dev/null
+++ b/src/net/milkbowl/vault/economy/plugins/Economy_Craftconomy.java
@@ -0,0 +1,223 @@
+package net.milkbowl.vault.economy.plugins;
+
+import java.util.List;
+import java.util.logging.Logger;
+
+import org.bukkit.event.Event.Priority;
+import org.bukkit.event.Event.Type;
+import org.bukkit.event.server.PluginDisableEvent;
+import org.bukkit.event.server.PluginEnableEvent;
+import org.bukkit.event.server.ServerListener;
+import org.bukkit.plugin.Plugin;
+import org.bukkit.plugin.PluginManager;
+import org.bukkit.plugin.java.JavaPlugin;
+
+import me.greatman.Craftconomy.Account;
+import me.greatman.Craftconomy.AccountHandler;
+import me.greatman.Craftconomy.Craftconomy;
+
+import net.milkbowl.vault.economy.Economy;
+import net.milkbowl.vault.economy.EconomyResponse;
+import net.milkbowl.vault.economy.EconomyResponse.ResponseType;
+
+public class Economy_Craftconomy implements Economy {
+ private static final Logger log = Logger.getLogger("Minecraft");
+
+ private String name = "Craftconomy";
+ private JavaPlugin plugin = null;
+ private PluginManager pluginManager = null;
+ protected Craftconomy economy = null;
+ private EconomyServerListener economyServerListener = null;
+
+ public Economy_Craftconomy(JavaPlugin plugin) {
+ this.plugin = plugin;
+ this.pluginManager = this.plugin.getServer().getPluginManager();
+
+ economyServerListener = new EconomyServerListener(this);
+
+ this.pluginManager.registerEvent(Type.PLUGIN_ENABLE, economyServerListener, Priority.Monitor, plugin);
+ this.pluginManager.registerEvent(Type.PLUGIN_DISABLE, economyServerListener, Priority.Monitor, plugin);
+
+ // Load Plugin in case it was loaded before
+ if (economy == null) {
+ Plugin ec = plugin.getServer().getPluginManager().getPlugin("Craftconomy");
+ if (ec != null && ec.isEnabled() && ec.getClass().getName().equals("me.greatman.Craftconomy.Craftconomy")) {
+ economy = (Craftconomy) ec;
+ log.info(String.format("[%s][Economy] %s hooked.", plugin.getDescription().getName(), name));
+ }
+ }
+ }
+
+ private class EconomyServerListener extends ServerListener {
+ Economy_Craftconomy economy = null;
+
+ public EconomyServerListener(Economy_Craftconomy economy) {
+ this.economy = economy;
+ }
+
+ public void onPluginEnable(PluginEnableEvent event) {
+ if (economy.economy == null) {
+ Plugin ec = plugin.getServer().getPluginManager().getPlugin("Craftconomy");
+
+ if (ec != null && ec.isEnabled() && ec.getClass().getName().equals("me.greatman.Craftconomy.Craftconomy")) {
+ economy.economy = (Craftconomy) ec;
+ log.info(String.format("[%s][Economy] %s hooked.", plugin.getDescription().getName(), economy.name));
+ }
+ }
+ }
+
+ public void onPluginDisable(PluginDisableEvent event) {
+ if (economy.economy != null) {
+ if (event.getPlugin().getDescription().getName().equals("Craftconomy")) {
+ economy.economy = null;
+ log.info(String.format("[%s][Economy] %s unhooked.", plugin.getDescription().getName(), economy.name));
+ }
+ }
+ }
+ }
+
+ @Override
+ public boolean isEnabled() {
+ if (economy == null) {
+ return false;
+ } else {
+ return economy.isEnabled();
+ }
+ }
+
+ @Override
+ public String getName() {
+ return name;
+ }
+
+ @Override
+ public String format(double amount) {
+ return Craftconomy.format(amount);
+ }
+
+ @Override
+ public double getBalance(String playerName) {
+ if (AccountHandler.exists(playerName)) {
+ return AccountHandler.getAccount(playerName).getBalance();
+ } else {
+ return 0;
+ }
+ }
+
+ @Override
+ public EconomyResponse withdrawPlayer(String playerName, double amount) {
+ double balance;
+ Account account = AccountHandler.getAccount(playerName);
+ if (account.hasEnough(amount)) {
+ balance = account.substractMoney(amount);
+ return new EconomyResponse(amount, balance, ResponseType.SUCCESS, "");
+ } else {
+ return new EconomyResponse(0, account.getBalance(), ResponseType.FAILURE, "Insufficient funds");
+ }
+ }
+
+ @Override
+ public EconomyResponse depositPlayer(String playerName, double amount) {
+ Account account = AccountHandler.getAccount(playerName);
+ account.addMoney(amount);
+ return new EconomyResponse(amount, account.getBalance(), ResponseType.SUCCESS, null);
+ }
+
+ @Override
+ public boolean has(String playerName, double amount) {
+ return getBalance(playerName) >= amount;
+ }
+
+ @Override
+ public EconomyResponse createBank(String name, String player) {
+ if (AccountHandler.exists(name)) {
+ return new EconomyResponse(0, AccountHandler.getAccount(player).getBalance(), ResponseType.FAILURE, "That account already exists.");
+ }
+ AccountHandler.getAccount(name);
+ return new EconomyResponse(0, 0, ResponseType.SUCCESS, "");
+
+ }
+
+ @Override
+ public EconomyResponse bankHas(String name, double amount) {
+ if (!AccountHandler.exists(name)) {
+ return new EconomyResponse(0, 0, ResponseType.FAILURE, "Account does not exists!");
+ }
+
+ double balance = AccountHandler.getAccount(name).getBank().getBalance();
+ if ( balance >= amount) {
+ return new EconomyResponse(0, balance, ResponseType.SUCCESS, "");
+ } else {
+ return new EconomyResponse(0, balance, ResponseType.FAILURE, "The account does not have enough!");
+ }
+ }
+
+ @Override
+ public EconomyResponse bankWithdraw(String name, double amount) {
+ double balance;
+ if (!AccountHandler.exists(name)) {
+ return new EconomyResponse(0, 0, ResponseType.FAILURE, "Account does not exists!");
+ }
+
+ Account account = AccountHandler.getAccount(name);
+ if (account.getBank().hasEnough(amount)) {
+ balance = account.getBank().substractMoney(amount);
+ return new EconomyResponse(amount, balance, ResponseType.SUCCESS, "");
+ } else {
+ balance = account.getBank().getBalance();
+ return new EconomyResponse(0, balance, ResponseType.FAILURE, "Insufficient funds");
+ }
+ }
+
+ @Override
+ public EconomyResponse bankDeposit(String name, double amount) {
+ if (!AccountHandler.exists(name)) {
+ return new EconomyResponse(0, 0, ResponseType.FAILURE, "Account does not exists!");
+ }
+ Account account = AccountHandler.getAccount(name);
+ return new EconomyResponse(amount, account.getBank().addMoney(amount), EconomyResponse.ResponseType.SUCCESS, "");
+ }
+
+ @Override
+ public EconomyResponse isBankOwner(String name, String playerName) {
+ return new EconomyResponse(0, 0, ResponseType.NOT_IMPLEMENTED, "Craftconomy does not support Bank owners.");
+ }
+
+ @Override
+ public EconomyResponse isBankMember(String name, String playerName) {
+ return new EconomyResponse(0, 0, ResponseType.NOT_IMPLEMENTED, "Craftconomy does not support Bank members.");
+ }
+
+ @Override
+ public EconomyResponse bankBalance(String name) {
+ if (!AccountHandler.exists(name)) {
+ return new EconomyResponse(0, 0, ResponseType.FAILURE, "There is no bank account with that name");
+ } else {
+ return new EconomyResponse(0, AccountHandler.getAccount(name).getBank().getBalance(), ResponseType.SUCCESS, null);
+ }
+ }
+
+ @Override
+ public List getBanks() {
+ throw new UnsupportedOperationException("Craftconomy does not support listing of bank accounts");
+ }
+
+ @Override
+ public boolean hasBankSupport() {
+ return true;
+ }
+
+ @Override
+ public boolean hasAccount(String playerName) {
+ return AccountHandler.exists(playerName);
+ }
+
+ @Override
+ public boolean createPlayerAccount(String playerName) {
+ if (AccountHandler.exists(playerName)) {
+ return false;
+ }
+ AccountHandler.getAccount(playerName);
+ return true;
+ }
+}
\ No newline at end of file