From 97331d95be79eb1b1ea0500c002957ecbe6a5b82 Mon Sep 17 00:00:00 2001 From: Omwah Date: Sat, 22 Dec 2012 14:40:59 -0800 Subject: [PATCH] Add changes necessary for supporting SDFEconomy --- pom.xml | 11 +- src/net/milkbowl/vault/Vault.java | 6 +- .../economy/plugins/Economy_SDFEconomy.java | 200 ++++++++++++++++++ 3 files changed, 215 insertions(+), 2 deletions(-) create mode 100644 src/net/milkbowl/vault/economy/plugins/Economy_SDFEconomy.java diff --git a/pom.xml b/pom.xml index 57d3905..277a1df 100644 --- a/pom.xml +++ b/pom.xml @@ -265,6 +265,11 @@ system ${project.basedir}/lib/CommandsEX.jar + + com.github.omwah + SDFEconomy + 0.1.0-SNAPSHOT + src/ @@ -346,7 +351,7 @@ Vault currently Supports: Permissions 3, PEX, GroupManager, bPerms, bPerms2, SimplyPerms, DroxPerms, zPermissions, Starburst -iConomy 4,5,6 BOSEconomy 6/7, EssentialsEcon, 3Co, MultiConomy, MineConomy, EconXP, eWallet, CurrencyCore, XPBank, CraftConomy, AEco +iConomy 4,5,6 BOSEconomy 6/7, EssentialsEcon, 3Co, MultiConomy, MineConomy, EconXP, eWallet, CurrencyCore, XPBank, CraftConomy, AEco, SDFEconomy https://github.com/MilkBowl/Vault @@ -366,5 +371,9 @@ iConomy 4,5,6 BOSEconomy 6/7, EssentialsEcon, 3Co, MultiConomy, MineConomy, Econ bukkit-repo http://repo.bukkit.org/content/groups/public/ + + sdfeconomy-repo + http://omwah.sdf.org/maven/repo/snapshots/ + diff --git a/src/net/milkbowl/vault/Vault.java b/src/net/milkbowl/vault/Vault.java index c5b2149..7d43695 100644 --- a/src/net/milkbowl/vault/Vault.java +++ b/src/net/milkbowl/vault/Vault.java @@ -57,6 +57,7 @@ import net.milkbowl.vault.economy.plugins.Economy_eWallet; import net.milkbowl.vault.economy.plugins.Economy_iConomy4; import net.milkbowl.vault.economy.plugins.Economy_iConomy5; import net.milkbowl.vault.economy.plugins.Economy_iConomy6; +import net.milkbowl.vault.economy.plugins.Economy_SDFEconomy; import net.milkbowl.vault.permission.Permission; import net.milkbowl.vault.permission.plugins.Permission_DroxPerms; import net.milkbowl.vault.permission.plugins.Permission_GroupManager; @@ -256,6 +257,9 @@ public class Vault extends JavaPlugin { // Try to load CommandsEX Economy hookEconomy("CommandsEX", Economy_CommandsEX.class, ServicePriority.Normal, "com.github.zathrus_writer.commandsex.api.EconomyAPI"); + + // Try to load SDFEconomy Economy + hookEconomy("SDFEconomy", Economy_SDFEconomy.class, ServicePriority.Normal, "com.github.omwah.SDFEconomy.SDFEconomy"); // Try to load XPBank hookEconomy("XPBank", Economy_XPBank.class, ServicePriority.Normal, "com.gmail.mirelatrue.xpbank.XPBank"); @@ -553,4 +557,4 @@ public class Vault extends JavaPlugin { } } } -} \ No newline at end of file +} diff --git a/src/net/milkbowl/vault/economy/plugins/Economy_SDFEconomy.java b/src/net/milkbowl/vault/economy/plugins/Economy_SDFEconomy.java new file mode 100644 index 0000000..2f12ae4 --- /dev/null +++ b/src/net/milkbowl/vault/economy/plugins/Economy_SDFEconomy.java @@ -0,0 +1,200 @@ +/* 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 org.bukkit.plugin.Plugin; +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 com.github.omwah.SDFEconomy.SDFEconomy; +import com.github.omwah.SDFEconomy.SDFEconomyAPI; + +import net.milkbowl.vault.economy.Economy; +import net.milkbowl.vault.economy.EconomyResponse; + +public class Economy_SDFEconomy implements Economy { + private static final Logger log = Logger.getLogger("Minecraft"); + private Plugin plugin = null; + + private final String name = "SDFEconomy"; + private SDFEconomyAPI api = null; + + public Economy_SDFEconomy(Plugin _plugin) { + plugin = _plugin; + + // Register a listener to wait for plugin being loaded + plugin.getServer().getPluginManager().registerEvents(new EconomyServerListener(this), plugin); + + // Try and Load API in case plugin was loaded before Vault + load_api(); + } + + public void load_api() { + SDFEconomy pluginSDF = (SDFEconomy) plugin.getServer().getPluginManager().getPlugin("SDFEconomy"); + if(!isEnabled() && pluginSDF != null) { + api = pluginSDF.getAPI(); + log.info(String.format("[%s][Economy] %s hooked.", plugin.getDescription().getName(), name)); + } + } + + public void unload_api() { + SDFEconomy pluginSDF = (SDFEconomy) plugin.getServer().getPluginManager().getPlugin("SDFEconomy"); + if(isEnabled() && pluginSDF != null) { + api = null; + log.info(String.format("[%s][Economy] %s unhooked.", plugin.getDescription().getName(), name)); + } + } + + public class EconomyServerListener implements Listener { + Economy_SDFEconomy economy = null; + + public EconomyServerListener(Economy_SDFEconomy economy) { + this.economy = economy; + } + + @EventHandler(priority = EventPriority.MONITOR) + public void onPluginEnable(PluginEnableEvent event) { + if (event.getPlugin().getDescription().getName().equals("SDFEconomy")) { + economy.load_api(); + } + } + + @EventHandler(priority = EventPriority.MONITOR) + public void onPluginDisable(PluginDisableEvent event) { + if (event.getPlugin().getDescription().getName().equals("SDFEconomy")) { + economy.unload_api(); + } + } + } + + + @Override + public boolean isEnabled() { + return api != null; + } + + @Override + public String getName() { + return "SDFEconomy"; + } + + @Override + public boolean hasBankSupport() { + return api.hasBankSupport(); + } + + @Override + public int fractionalDigits() { + return api.fractionalDigits(); + } + + @Override + public String format(double amount) { + return api.format(amount); + } + + @Override + public String currencyNamePlural() { + return api.currencyNamePlural(); + } + + @Override + public String currencyNameSingular() { + return api.currencyNameSingular(); + } + + @Override + public boolean hasAccount(String playerName) { + return api.hasAccount(playerName); + } + + @Override + public double getBalance(String playerName) { + return api.getBalance(playerName); + } + + @Override + public boolean has(String playerName, double amount) { + return api.has(playerName, amount); + } + + @Override + public EconomyResponse withdrawPlayer(String playerName, double amount) { + return api.withdrawPlayer(playerName, amount); + } + + @Override + public EconomyResponse depositPlayer(String playerName, double amount) { + return api.depositPlayer(playerName, amount); + } + + @Override + public EconomyResponse createBank(String name, String player) { + return api.createBank(name, player); + } + + @Override + public EconomyResponse deleteBank(String name) { + return api.deleteBank(name); + } + + @Override + public EconomyResponse bankBalance(String name) { + return api.bankBalance(name); + } + + @Override + public EconomyResponse bankHas(String name, double amount) { + return api.bankHas(name, amount); + } + + @Override + public EconomyResponse bankWithdraw(String name, double amount) { + return api.bankWithdraw(name, amount); + } + + @Override + public EconomyResponse bankDeposit(String name, double amount) { + return api.bankDeposit(name, amount); + } + + @Override + public EconomyResponse isBankOwner(String name, String playerName) { + return api.isBankOwner(name, playerName); + } + + @Override + public EconomyResponse isBankMember(String name, String playerName) { + return api.isBankMember(name, playerName); + } + + @Override + public List getBanks() { + return api.getBankNames(); + } + + @Override + public boolean createPlayerAccount(String playerName) { + return api.createPlayerAccount(playerName); + } + +}