Fixed economy issues - thanks niji!

This commit is contained in:
Acrobot 2011-05-16 17:35:12 +02:00
parent d5b791f8c8
commit 7e093d0b5e
9 changed files with 91 additions and 89 deletions

View File

@ -45,7 +45,6 @@ public class playerInteract extends PlayerListener{
Action buy = (Config.getBoolean("reverse_buttons") ? Action.LEFT_CLICK_BLOCK : Action.RIGHT_CLICK_BLOCK);
if(action == buy){
player.sendMessage("You are buying!");
} else{

View File

@ -1,12 +1,12 @@
package com.Acrobot.ChestShop.Listeners;
import com.Acrobot.ChestShop.ChestShop;
import com.Acrobot.ChestShop.Economy;
import com.Acrobot.ChestShop.Items.Odd;
import com.Acrobot.ChestShop.Permission;
import com.Acrobot.ChestShop.Protection.LWCplugin;
import com.Acrobot.ChestShop.Protection.LockettePlugin;
import com.Acrobot.ChestShop.Protection.Security;
import com.Acrobot.ChestShop.ChestShop;
import com.griefcraft.lwc.LWCPlugin;
import com.nijikokun.bukkit.Permissions.Permissions;
import com.nijikokun.register.payment.Methods;
@ -22,12 +22,15 @@ import org.yi.acru.bukkit.Lockette.Lockette;
*/
public class pluginEnable extends ServerListener{
private Methods Methods = new Methods();
private Methods methods = new Methods();
public void onPluginEnable(PluginEnableEvent event){
if(!this.Methods.hasMethod()){
if(this.Methods.setMethod(event.getPlugin())){
Economy.economy = this.Methods.getMethod();
//Economy plugins
if(!this.methods.hasMethod()){
if(methods.setMethod(event.getPlugin())){
Economy.economy = methods.getMethod();
System.out.println("[ChestShop] " + Economy.economy.getName() + " " + Economy.economy.getVersion() + " loaded.");
}
}

View File

@ -2,6 +2,14 @@ package com.nijikokun.register.payment;
import org.bukkit.plugin.Plugin;
/**
* Method.java
* Interface for all sub-methods for payment.
*
* @author: Nijikokun<nijikokun@gmail.com> (@nijikokun)
* @copyright: Copyright (C) 2011
* @license: GNUv3 Affero License <http://www.gnu.org/licenses/agpl-3.0.html>
*/
public interface Method {
public Object getPlugin();
public String getName();

View File

@ -1,31 +0,0 @@
package com.nijikokun.register.payment;
import java.util.HashSet;
import java.util.Set;
import org.bukkit.plugin.Plugin;
public class MethodFactory {
private static Set<Method> Methods = new HashSet<Method>();
private static Set<String> Dependencies = new HashSet<String>();
public static Method createMethod(Plugin plugin) {
for (Method method: Methods) {
if (method.isCompatible(plugin)) {
method.setPlugin(plugin);
return method;
}
}
return null;
}
public static void addMethod(String name, Method method) {
Dependencies.add(name);
Methods.add(method);
}
public static Set<String> getDependencies() {
return Dependencies;
}
}

View File

@ -3,44 +3,80 @@ package com.nijikokun.register.payment;
import org.bukkit.plugin.Plugin;
import org.bukkit.plugin.PluginManager;
import java.util.HashSet;
import java.util.Set;
/**
* Methods.java
* Controls the getting / setting of methods & the method of payment used.
*
* @author: Nijikokun<nijikokun@gmail.com> (@nijikokun)
* @copyright: Copyright (C) 2011
* @license: GNUv3 Affero License <http://www.gnu.org/licenses/agpl-3.0.html>
*/
public class Methods {
private Method Method = null;
private Set<Method> Methods = new HashSet<Method>();
private Set<String> Dependencies = new HashSet<String>();
public Methods() {
this.addMethod("iConomy", new com.nijikokun.register.payment.methods.iCo4());
this.addMethod("iConomy", new com.nijikokun.register.payment.methods.iCo5());
this.addMethod("BOSEconomy", new com.nijikokun.register.payment.methods.BOSE());
this.addMethod("Essentials", new com.nijikokun.register.payment.methods.EE17());
}
public Set<String> getDependencies() {
return Dependencies;
}
public Method createMethod(Plugin plugin) {
for (Method method: Methods) {
if (method.isCompatible(plugin)) {
method.setPlugin(plugin);
return method;
}
}
return null;
}
private void addMethod(String name, Method method) {
Dependencies.add(name);
Methods.add(method);
}
public boolean hasMethod() {
return (this.Method != null);
}
public boolean setMethod(Plugin method) {
if(hasMethod()) return true;
PluginManager manager = method.getServer().getPluginManager();
Plugin plugin = null;
if (method != null && method.isEnabled()) {
Method plugin = MethodFactory.createMethod(method);
if (plugin != null) Method = plugin;
} else {
for(String name: MethodFactory.getDependencies()) {
for(String name: this.getDependencies()) {
if(hasMethod()) break;
if(method.getDescription().getName().equals(name)) plugin = method; else plugin = manager.getPlugin(name);
if(plugin == null) continue;
if(!plugin.isEnabled()) continue;
method = manager.getPlugin(name);
if(method == null) continue;
if(!method.isEnabled()) manager.enablePlugin(method);
if(!method.isEnabled()) continue;
Method plugin = MethodFactory.createMethod(method);
if (plugin != null) Method = plugin;
}
Method current = this.createMethod(plugin);
if (current != null) this.Method = current;
}
return hasMethod();
}
public Method getMethod() {
return Method;
}
public boolean checkDisabled(Plugin method) {
if(!hasMethod()) return true;
if (Method.isCompatible(method)) Method = null;
return (Method == null);
}
public boolean hasMethod() {
return (Method != null);
}
public Method getMethod() {
return Method;
}
}

View File

@ -1,18 +1,12 @@
package com.nijikokun.register.payment.methods;
import com.nijikokun.register.payment.Method;
import com.nijikokun.register.payment.MethodFactory;
import cosine.boseconomy.BOSEconomy;
import org.bukkit.plugin.Plugin;
public class BOSE implements Method {
private BOSEconomy BOSEconomy;
static {
MethodFactory.addMethod("BOSEconomy", new BOSE());
}
public BOSEconomy getPlugin() {
return this.BOSEconomy;
}
@ -74,7 +68,7 @@ public class BOSE implements Method {
}
public double balance() {
return (double) this.BOSEconomy.getPlayerMoney(this.name);
return Double.valueOf(this.BOSEconomy.getPlayerMoney(this.name));
}
public boolean set(double amount) {
@ -84,7 +78,7 @@ public class BOSE implements Method {
public boolean add(double amount) {
int IntAmount = (int)Math.ceil(amount);
//int balance = (int)this.balance();
int balance = (int)this.balance();
return this.BOSEconomy.addPlayerMoney(this.name, IntAmount, false);
}
@ -147,7 +141,7 @@ public class BOSE implements Method {
}
public double balance() {
return (double) this.BOSEconomy.getBankMoney(name);
return Double.valueOf(this.BOSEconomy.getBankMoney(name));
}
public boolean set(double amount) {

View File

@ -4,17 +4,14 @@ import com.earth2me.essentials.Essentials;
import com.earth2me.essentials.api.Economy;
import com.earth2me.essentials.api.NoLoanPermittedException;
import com.earth2me.essentials.api.UserDoesNotExistException;
import com.nijikokun.register.payment.Method;
import com.nijikokun.register.payment.MethodFactory;
import org.bukkit.plugin.Plugin;
public class EE17 implements Method {
private Essentials Essentials;
static {
MethodFactory.addMethod("Essentials", new EE17());
}
public Essentials getPlugin() {
return this.Essentials;
}
@ -57,6 +54,8 @@ public class EE17 implements Method {
}
public boolean isCompatible(Plugin plugin) {
try { Class.forName("com.earth2me.essentials.api.Economy"); }
catch(Exception e) { return false; }
return plugin.getDescription().getName().equalsIgnoreCase("essentials") && plugin instanceof Essentials;
}

View File

@ -2,17 +2,14 @@ package com.nijikokun.register.payment.methods;
import com.nijiko.coelho.iConomy.iConomy;
import com.nijiko.coelho.iConomy.system.Account;
import com.nijikokun.register.payment.Method;
import com.nijikokun.register.payment.MethodFactory;
import org.bukkit.plugin.Plugin;
public class iCo4 implements Method {
private iConomy iConomy;
static {
MethodFactory.addMethod("iConomy", new iCo4());
}
public iConomy getPlugin() {
return this.iConomy;
}
@ -54,7 +51,7 @@ public class iCo4 implements Method {
}
public boolean isCompatible(Plugin plugin) {
return plugin.getDescription().getName().equalsIgnoreCase("iconomy") && plugin instanceof iConomy;
return plugin.getDescription().getName().equalsIgnoreCase("iconomy") && !plugin.getClass().getName().equals("com.iConomy.iConomy") && plugin instanceof iConomy;
}
public void setPlugin(Plugin plugin) {

View File

@ -5,17 +5,14 @@ import com.iConomy.system.Account;
import com.iConomy.system.BankAccount;
import com.iConomy.system.Holdings;
import com.iConomy.util.Constants;
import com.nijikokun.register.payment.Method;
import com.nijikokun.register.payment.MethodFactory;
import org.bukkit.plugin.Plugin;
public class iCo5 implements Method {
private iConomy iConomy;
static {
MethodFactory.addMethod("iConomy", new iCo5());
}
public iConomy getPlugin() {
return this.iConomy;
}
@ -37,7 +34,7 @@ public class iCo5 implements Method {
}
public boolean hasBank(String bank) {
return (hasBanks()) && this.iConomy.Banks.exists(bank);
return (!hasBanks()) ? false : this.iConomy.Banks.exists(bank);
}
public boolean hasAccount(String name) {
@ -45,7 +42,7 @@ public class iCo5 implements Method {
}
public boolean hasBankAccount(String bank, String name) {
return (!hasBank(bank)) && this.iConomy.getBank(name).hasAccount(name);
return (hasBank(bank)) ? false : this.iConomy.getBank(name).hasAccount(name);
}
public MethodAccount getAccount(String name) {
@ -57,7 +54,7 @@ public class iCo5 implements Method {
}
public boolean isCompatible(Plugin plugin) {
return plugin.getDescription().getName().equalsIgnoreCase("iconomy") && plugin instanceof iConomy;
return plugin.getDescription().getName().equalsIgnoreCase("iconomy") && plugin.getClass().getName().equals("com.iConomy.iConomy") && plugin instanceof iConomy;
}
public void setPlugin(Plugin plugin) {