diff --git a/lib/GoldIsMoney.jar b/lib/GoldIsMoney.jar index b0468c8..6a0dc9e 100644 Binary files a/lib/GoldIsMoney.jar and b/lib/GoldIsMoney.jar differ diff --git a/lib/GoldIsMoney2.jar b/lib/GoldIsMoney2.jar new file mode 100644 index 0000000..2bce9c7 Binary files /dev/null and b/lib/GoldIsMoney2.jar differ diff --git a/pom.xml b/pom.xml index 280b0e8..e2a3287 100644 --- a/pom.xml +++ b/pom.xml @@ -51,10 +51,17 @@ com.flobi.GoldIsMoney GoldIsMoney - 1.0.0 + 1.2.1 system ${project.basedir}/lib/GoldIsMoney.jar + + com.flobi.GoldIsMoney2 + GoldIsMoney + 2.0.0 + system + ${project.basedir}/lib/GoldIsMoney2.jar + cosine.boseconomy.BOSEconomy BOSEconomy diff --git a/src/net/milkbowl/vault/Vault.java b/src/net/milkbowl/vault/Vault.java index de43f8c..e6b711a 100644 --- a/src/net/milkbowl/vault/Vault.java +++ b/src/net/milkbowl/vault/Vault.java @@ -45,6 +45,7 @@ import net.milkbowl.vault.economy.plugins.Economy_CurrencyCore; import net.milkbowl.vault.economy.plugins.Economy_EconXP; import net.milkbowl.vault.economy.plugins.Economy_Essentials; import net.milkbowl.vault.economy.plugins.Economy_GoldIsMoney; +import net.milkbowl.vault.economy.plugins.Economy_GoldIsMoney2; import net.milkbowl.vault.economy.plugins.Economy_Gringotts; import net.milkbowl.vault.economy.plugins.Economy_McMoney; import net.milkbowl.vault.economy.plugins.Economy_MineConomy; @@ -243,6 +244,9 @@ public class Vault extends JavaPlugin { // Try to load GoldIsMoney hookEconomy("GoldIsMoney", Economy_GoldIsMoney.class, ServicePriority.Normal, "com.flobi.GoldIsMoney.GoldIsMoney"); + + // Try to load GoldIsMoney2 + hookEconomy("GoldIsMoney2", Economy_GoldIsMoney2.class, ServicePriority.Normal, "com.flobi.GoldIsMoney2.GoldIsMoney"); } diff --git a/src/net/milkbowl/vault/economy/plugins/Economy_GoldIsMoney.java b/src/net/milkbowl/vault/economy/plugins/Economy_GoldIsMoney.java index 189c334..ca9da53 100644 --- a/src/net/milkbowl/vault/economy/plugins/Economy_GoldIsMoney.java +++ b/src/net/milkbowl/vault/economy/plugins/Economy_GoldIsMoney.java @@ -112,7 +112,7 @@ public class Economy_GoldIsMoney implements Economy { if (economy.economy == null) { Plugin ec = plugin.getServer().getPluginManager().getPlugin("GoldIsMoney"); - if (ec != null && ec.isEnabled() && ec.getClass().getName().equals("com.GoldIsMoney.GoldIsMoney")) { + if (ec != null && ec.isEnabled() && ec.getClass().getName().equals("com.flobi.GoldIsMoney.GoldIsMoney")) { economy.economy = (GoldIsMoney) ec; log.info(String.format("[%s][Economy] %s hooked.", plugin.getDescription().getName(), economy.name)); } diff --git a/src/net/milkbowl/vault/economy/plugins/Economy_GoldIsMoney2.java b/src/net/milkbowl/vault/economy/plugins/Economy_GoldIsMoney2.java new file mode 100644 index 0000000..58fd9b2 --- /dev/null +++ b/src/net/milkbowl/vault/economy/plugins/Economy_GoldIsMoney2.java @@ -0,0 +1,286 @@ +/* This file is part of Vault. + +Vault is free software: you can redistribute it and/or modify +it under the terms of the GNU Lesser General Public License as published by +the Free Software Foundation, either version 3 of the License, or +(at your option) any later version. + +Vault is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU Lesser General Public License for more details. + +You should have received a copy of the GNU Lesser General Public License +along with Vault. If not, see . +*/ +package net.milkbowl.vault.economy.plugins; + +import java.util.List; +import java.util.logging.Logger; + +import net.milkbowl.vault.economy.Economy; +import net.milkbowl.vault.economy.EconomyResponse; +import net.milkbowl.vault.economy.EconomyResponse.ResponseType; + +import org.bukkit.Bukkit; +import org.bukkit.event.EventHandler; +import org.bukkit.event.EventPriority; +import org.bukkit.event.Listener; +import org.bukkit.event.server.PluginDisableEvent; +import org.bukkit.event.server.PluginEnableEvent; +import org.bukkit.plugin.Plugin; + +import com.flobi.GoldIsMoney2.GoldIsMoney; + +public class Economy_GoldIsMoney2 implements Economy { + private static final Logger log = Logger.getLogger("Minecraft"); + + private final String name = "GoldIsMoney"; + private Plugin plugin = null; + protected GoldIsMoney economy = null; + + public Economy_GoldIsMoney2(Plugin plugin) { + this.plugin = plugin; + Bukkit.getServer().getPluginManager().registerEvents(new EconomyServerListener(this), plugin); + // Load Plugin in case it was loaded before + if (economy == null) { + Plugin ec = plugin.getServer().getPluginManager().getPlugin("GoldIsMoney"); + + if (ec != null && ec.isEnabled() && ec.getClass().getName().equals("com.flobi.GoldIsMoney2.GoldIsMoney")) { + economy = (GoldIsMoney) ec; + log.info(String.format("[%s][Economy] %s hooked.", plugin.getDescription().getName(), name)); + } + } + } + + @Override + public boolean isEnabled() { + if (economy == null) { + return false; + } else { + return economy.isEnabled(); + } + } + + @Override + public String getName() { + return name; + } + + @Override + public boolean hasBankSupport() { + return GoldIsMoney.hasBankSupport(); + } + + @Override + public int fractionalDigits() { + return GoldIsMoney.fractionalDigits(); + } + + @Override + public String format(double amount) { + return GoldIsMoney.format(amount); + } + + @Override + public String currencyNamePlural() { + return GoldIsMoney.currencyNamePlural(); + } + + @Override + public String currencyNameSingular() { + return GoldIsMoney.currencyNameSingular(); + } + + @Override + public boolean hasAccount(String playerName) { + return GoldIsMoney.hasAccount(playerName); + } + + @Override + public double getBalance(String playerName) { + return GoldIsMoney.getBalance(playerName); + } + + @Override + public boolean has(String playerName, double amount) { + return GoldIsMoney.has(playerName, amount); + } + + @Override + public EconomyResponse withdrawPlayer(String playerName, double amount) { + if (amount < 0) { + return new EconomyResponse(0, 0, ResponseType.FAILURE, "Cannot withdraw negative funds!"); + } + if (!GoldIsMoney.hasAccount(playerName)) { + return new EconomyResponse(0, 0, ResponseType.FAILURE, "That player does not have an account!"); + } + if (!GoldIsMoney.has(playerName, amount)) { + return new EconomyResponse(0, GoldIsMoney.getBalance(playerName), ResponseType.FAILURE, "Insufficient funds"); + } + if (!GoldIsMoney.withdrawPlayer(playerName, amount)) { + return new EconomyResponse(0, GoldIsMoney.getBalance(playerName), ResponseType.FAILURE, "Unable to withdraw funds!"); + } + return new EconomyResponse(amount, GoldIsMoney.getBalance(playerName), ResponseType.SUCCESS, null); + } + + @Override + public EconomyResponse depositPlayer(String playerName, double amount) { + if (amount < 0) { + return new EconomyResponse(0, 0, ResponseType.FAILURE, "Cannot desposit negative funds!"); + } + if (!GoldIsMoney.hasAccount(playerName)) { + return new EconomyResponse(0, 0, ResponseType.FAILURE, "That player does not have an account!"); + } + if (!GoldIsMoney.depositPlayer(playerName, amount)) { + return new EconomyResponse(0, GoldIsMoney.getBalance(playerName), ResponseType.FAILURE, "Unable to deposit funds!"); + } + return new EconomyResponse(amount, GoldIsMoney.getBalance(playerName), ResponseType.SUCCESS, null); + } + + @Override + public EconomyResponse createBank(String name, String player) { + if (!GoldIsMoney.hasBankSupport()) { + return new EconomyResponse(0, 0, ResponseType.NOT_IMPLEMENTED, "GoldIsMoney bank support is disabled!"); + } + if (!GoldIsMoney.createBank(name, player)) { + return new EconomyResponse(0, 0, ResponseType.FAILURE, "Unable to create bank account."); + } + return new EconomyResponse(0, GoldIsMoney.bankBalance(name), ResponseType.SUCCESS, ""); + } + + @Override + public EconomyResponse deleteBank(String name) { + if (!GoldIsMoney.hasBankSupport()) { + return new EconomyResponse(0, 0, ResponseType.NOT_IMPLEMENTED, "GoldIsMoney bank support is disabled!"); + } + if (!GoldIsMoney.deleteBank(name)) { + return new EconomyResponse(0, 0, ResponseType.FAILURE, "Unable to remove bank account."); + } + return new EconomyResponse(0, 0, ResponseType.SUCCESS, ""); + } + + @Override + public EconomyResponse bankBalance(String name) { + if (!GoldIsMoney.hasBankSupport()) { + return new EconomyResponse(0, 0, ResponseType.NOT_IMPLEMENTED, "GoldIsMoney bank support is disabled!"); + } + if (!GoldIsMoney.bankExists(name)) { + return new EconomyResponse(0, 0, ResponseType.FAILURE, "That bank does not exist!"); + } + return new EconomyResponse(0, GoldIsMoney.bankBalance(name), ResponseType.SUCCESS, ""); + } + + @Override + public EconomyResponse bankHas(String name, double amount) { + if (!GoldIsMoney.hasBankSupport()) { + return new EconomyResponse(0, 0, ResponseType.NOT_IMPLEMENTED, "GoldIsMoney bank support is disabled!"); + } + if (!GoldIsMoney.bankExists(name)) { + return new EconomyResponse(0, 0, ResponseType.FAILURE, "That bank does not exist!"); + } + if (GoldIsMoney.bankHas(name, amount)) { + return new EconomyResponse(0, GoldIsMoney.bankBalance(name), ResponseType.FAILURE, "The bank does not have enough money!"); + } + return new EconomyResponse(0, GoldIsMoney.bankBalance(name), ResponseType.SUCCESS, ""); + } + + @Override + public EconomyResponse bankWithdraw(String name, double amount) { + if (!GoldIsMoney.hasBankSupport()) { + return new EconomyResponse(0, 0, ResponseType.NOT_IMPLEMENTED, "GoldIsMoney bank support is disabled!"); + } + if (!GoldIsMoney.bankExists(name)) { + return new EconomyResponse(0, 0, ResponseType.FAILURE, "That bank does not exist!"); + } + if (!GoldIsMoney.bankHas(name, amount)) { + return new EconomyResponse(0, GoldIsMoney.bankBalance(name), ResponseType.FAILURE, "The bank does not have enough money!"); + } + if (!GoldIsMoney.bankWithdraw(name, amount)) { + return new EconomyResponse(0, GoldIsMoney.bankBalance(name), ResponseType.FAILURE, "Unable to withdraw from that bank account!"); + } + return new EconomyResponse(amount, GoldIsMoney.bankBalance(name), ResponseType.SUCCESS, ""); + } + + @Override + public EconomyResponse bankDeposit(String name, double amount) { + if (!GoldIsMoney.hasBankSupport()) { + return new EconomyResponse(0, 0, ResponseType.NOT_IMPLEMENTED, "GoldIsMoney bank support is disabled!"); + } + if (!GoldIsMoney.bankExists(name)) { + return new EconomyResponse(0, 0, ResponseType.FAILURE, "That bank does not exist!"); + } + if (!GoldIsMoney.bankDeposit(name, amount)) { + return new EconomyResponse(0, GoldIsMoney.bankBalance(name), ResponseType.FAILURE, "Unable to deposit to that bank account!"); + } + return new EconomyResponse(amount, GoldIsMoney.bankBalance(name), ResponseType.SUCCESS, ""); + } + + @Override + public EconomyResponse isBankOwner(String name, String playerName) { + if (!GoldIsMoney.hasBankSupport()) { + return new EconomyResponse(0, 0, ResponseType.NOT_IMPLEMENTED, "GoldIsMoney bank support is disabled!"); + } + if (!GoldIsMoney.bankExists(name)) { + return new EconomyResponse(0, 0, ResponseType.FAILURE, "That bank does not exist!"); + } + if (!GoldIsMoney.isBankOwner(name, playerName)) { + return new EconomyResponse(0, 0, ResponseType.FAILURE, "That player does not own that bank!"); + } + return new EconomyResponse(0, GoldIsMoney.bankBalance(name), ResponseType.SUCCESS, ""); + } + + @Override + public EconomyResponse isBankMember(String name, String playerName) { + if (!GoldIsMoney.hasBankSupport()) { + return new EconomyResponse(0, 0, ResponseType.NOT_IMPLEMENTED, "GoldIsMoney bank support is disabled!"); + } + if (!GoldIsMoney.bankExists(name)) { + return new EconomyResponse(0, 0, ResponseType.FAILURE, "That bank does not exist!"); + } + if (!GoldIsMoney.isBankMember(name, playerName)) { + return new EconomyResponse(0, 0, ResponseType.FAILURE, "That player is not a member of that bank!"); + } + return new EconomyResponse(0, GoldIsMoney.bankBalance(name), ResponseType.SUCCESS, ""); + } + + @Override + public List getBanks() { + return GoldIsMoney.getBanks(); + } + + @Override + public boolean createPlayerAccount(String playerName) { + return GoldIsMoney.createPlayerAccount(playerName); + } + + public class EconomyServerListener implements Listener { + Economy_GoldIsMoney2 economy = null; + + public EconomyServerListener(Economy_GoldIsMoney2 economy_GoldIsMoney2) { + this.economy = economy_GoldIsMoney2; + } + + @EventHandler(priority = EventPriority.MONITOR) + public void onPluginEnable(PluginEnableEvent event) { + if (economy.economy == null) { + Plugin ec = plugin.getServer().getPluginManager().getPlugin("GoldIsMoney"); + + if (ec != null && ec.isEnabled() && ec.getClass().getName().equals("com.flobi.GoldIsMoney2.GoldIsMoney")) { + economy.economy = (GoldIsMoney) ec; + log.info(String.format("[%s][Economy] %s hooked.", plugin.getDescription().getName(), economy.name)); + } + } + } + + @EventHandler(priority = EventPriority.MONITOR) + public void onPluginDisable(PluginDisableEvent event) { + if (economy.economy != null) { + if (event.getPlugin().getDescription().getName().equals("GoldIsMoney")) { + economy.economy = null; + log.info(String.format("[%s][Economy] %s unhooked.", plugin.getDescription().getName(), economy.name)); + } + } + } + } +} \ No newline at end of file