Skip to content

Commit

Permalink
Add fix for old essentials econ
Browse files Browse the repository at this point in the history
  • Loading branch information
fernferret committed Jul 13, 2011
1 parent a1624c1 commit 48f6246
Showing 1 changed file with 103 additions and 98 deletions.
201 changes: 103 additions & 98 deletions src/com/fernferret/allpay/AllPay.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,102 +18,107 @@
*
*/
public class AllPay {
private static final String version = ".5";
protected static final String logPrefix = "[AllPay] - Version " + version;

protected static final Logger log = Logger.getLogger("Minecraft");
protected static String prefix;
private Plugin plugin;
private GenericBank bank;
public final static String[] validEconPlugins = {"Essentials", "RealShop", "BOSEconomy", "iConomy"};
public AllPay(Plugin plugin, String prefix) {
this.plugin = plugin;
AllPay.prefix = prefix;
}

/**
* Load an econ plugin. Plugins are loaded in this order: iConomy, BOSEconomy, RealShop, Essentials and simple items
*
* @return The GenericBank object to process payments.
*/
public GenericBank loadEconPlugin() {
loadiConomy(); // Supports both 4.x and 5.x
loadBOSEconomy();
loadRealShopEconomy();
loadEssentialsEconomoy();
loadDefaultItemEconomy();
return this.bank;
}

/**
* Returns the AllPay GenericBank object that you can issue calls to and from
*
* @return The GenericBank object to process payments.
*/
public GenericBank getEconPlugin() {
return this.bank;
}

private void loadEssentialsEconomoy() {
if (this.bank == null) {
Essentials essentialsPlugin = (Essentials) this.plugin.getServer().getPluginManager().getPlugin("Essentials");
if (essentialsPlugin != null) {
this.bank = new EssentialsBank();
log.info(logPrefix + " - hooked into Essentials Economy for " + this.plugin.getDescription().getFullName());
}
}
}

private void loadRealShopEconomy() {
if (this.bank == null && !(this.bank instanceof EssentialsBank)) {
Plugin realShopPlugin = this.plugin.getServer().getPluginManager().getPlugin("RealShop");
if (realShopPlugin != null) {
RealEconomy realEconPlugin = new RealEconomy((RealPlugin) realShopPlugin);
log.info(logPrefix + " - hooked into RealEconomy for " + this.plugin.getDescription().getFullName());
this.bank = new RealEconomyBank(realEconPlugin);
}
}
}

private void loadBOSEconomy() {
if (this.bank == null && !(this.bank instanceof EssentialsBank)) {
BOSEconomy boseconPlugin = (BOSEconomy) this.plugin.getServer().getPluginManager().getPlugin("BOSEconomy");
if (boseconPlugin != null) {
this.bank = new BOSEconomyBank(boseconPlugin);
log.info(logPrefix + " - hooked into BOSEconomy " + this.plugin.getDescription().getFullName());
}
}
}

private void loadDefaultItemEconomy() {
if (this.bank == null) {
this.bank = new ItemBank();
log.info(logPrefix + " - using only an item based economy for " + this.plugin.getDescription().getFullName());
}
}

private void loadiConomy() {
if (this.bank == null && !(this.bank instanceof EssentialsBank)) {
Plugin iConomyTest = this.plugin.getServer().getPluginManager().getPlugin("iConomy");
try {
if (iConomyTest != null && iConomyTest instanceof com.iConomy.iConomy) {
this.bank = new iConomyBank((iConomy) iConomyTest);
log.info(logPrefix + " - hooked into iConomy for " + this.plugin.getDescription().getFullName());
}
} catch (NoClassDefFoundError e) {
if (iConomyTest != null) {
loadiConomy4X();
}
}
}
}

private void loadiConomy4X() {
com.nijiko.coelho.iConomy.iConomy iConomyPlugin = (com.nijiko.coelho.iConomy.iConomy) this.plugin.getServer().getPluginManager().getPlugin("iConomy");
if (iConomyPlugin != null) {
this.bank = new iConomyBank4X(iConomyPlugin);
log.info(logPrefix + " - hooked into iConomy(4.X) for " + this.plugin.getDescription().getFullName());
}
}

private static final String version = ".5.1";
protected static final String logPrefix = "[AllPay] - Version " + version;

protected static final Logger log = Logger.getLogger("Minecraft");
protected static String prefix;
private Plugin plugin;
private GenericBank bank;
public final static String[] validEconPlugins = { "Essentials", "RealShop", "BOSEconomy", "iConomy" };

public AllPay(Plugin plugin, String prefix) {
this.plugin = plugin;
AllPay.prefix = prefix;
}

/**
* Load an econ plugin. Plugins are loaded in this order: iConomy, BOSEconomy, RealShop, Essentials and simple items
*
* @return The GenericBank object to process payments.
*/
public GenericBank loadEconPlugin() {
loadiConomy(); // Supports both 4.x and 5.x
loadBOSEconomy();
loadRealShopEconomy();
loadEssentialsEconomoy();
loadDefaultItemEconomy();
return this.bank;
}

/**
* Returns the AllPay GenericBank object that you can issue calls to and from
*
* @return The GenericBank object to process payments.
*/
public GenericBank getEconPlugin() {
return this.bank;
}

private void loadEssentialsEconomoy() {
if (this.bank == null) {
try {
Essentials essentialsPlugin = (Essentials) this.plugin.getServer().getPluginManager().getPlugin("Essentials");
if (essentialsPlugin != null) {
this.bank = new EssentialsBank();
log.info(logPrefix + " - hooked into Essentials Economy for " + this.plugin.getDescription().getFullName());
}
} catch (Exception e) {
log.warning(logPrefix + "You are using a VERY old version of Essentials. Please upgrade it.");
}
}
}

private void loadRealShopEconomy() {
if (this.bank == null && !(this.bank instanceof EssentialsBank)) {
Plugin realShopPlugin = this.plugin.getServer().getPluginManager().getPlugin("RealShop");
if (realShopPlugin != null) {
RealEconomy realEconPlugin = new RealEconomy((RealPlugin) realShopPlugin);
log.info(logPrefix + " - hooked into RealEconomy for " + this.plugin.getDescription().getFullName());
this.bank = new RealEconomyBank(realEconPlugin);
}
}
}

private void loadBOSEconomy() {
if (this.bank == null && !(this.bank instanceof EssentialsBank)) {
BOSEconomy boseconPlugin = (BOSEconomy) this.plugin.getServer().getPluginManager().getPlugin("BOSEconomy");
if (boseconPlugin != null) {
this.bank = new BOSEconomyBank(boseconPlugin);
log.info(logPrefix + " - hooked into BOSEconomy " + this.plugin.getDescription().getFullName());
}
}
}

private void loadDefaultItemEconomy() {
if (this.bank == null) {
this.bank = new ItemBank();
log.info(logPrefix + " - using only an item based economy for " + this.plugin.getDescription().getFullName());
}
}

private void loadiConomy() {
if (this.bank == null && !(this.bank instanceof EssentialsBank)) {
Plugin iConomyTest = this.plugin.getServer().getPluginManager().getPlugin("iConomy");
try {
if (iConomyTest != null && iConomyTest instanceof com.iConomy.iConomy) {
this.bank = new iConomyBank((iConomy) iConomyTest);
log.info(logPrefix + " - hooked into iConomy for " + this.plugin.getDescription().getFullName());
}
} catch (NoClassDefFoundError e) {
if (iConomyTest != null) {
loadiConomy4X();
}
}
}
}

private void loadiConomy4X() {
com.nijiko.coelho.iConomy.iConomy iConomyPlugin = (com.nijiko.coelho.iConomy.iConomy) this.plugin.getServer().getPluginManager().getPlugin("iConomy");
if (iConomyPlugin != null) {
this.bank = new iConomyBank4X(iConomyPlugin);
log.info(logPrefix + " - hooked into iConomy(4.X) for " + this.plugin.getDescription().getFullName());
}
}

}

0 comments on commit 48f6246

Please sign in to comment.