mirror of
https://github.com/TotalFreedomMC/TF-EssentialsX.git
synced 2025-05-28 18:17:33 +00:00
Register v1.2
git-svn-id: https://svn.java.net/svn/essentials~svn/trunk@1488 e251c2fe-e539-e718-e476-b85c1f46cddb
This commit is contained in:
parent
403963cf96
commit
fb818a611d
6 changed files with 64 additions and 60 deletions
|
@ -2,6 +2,14 @@ package com.earth2me.essentials.register.payment;
|
||||||
|
|
||||||
import org.bukkit.plugin.Plugin;
|
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 interface Method {
|
||||||
public Object getPlugin();
|
public Object getPlugin();
|
||||||
public String getName();
|
public String getName();
|
||||||
|
|
|
@ -1,31 +0,0 @@
|
||||||
package com.earth2me.essentials.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;
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,20 +1,63 @@
|
||||||
package com.earth2me.essentials.register.payment;
|
package com.earth2me.essentials.register.payment;
|
||||||
|
|
||||||
|
import java.util.HashSet;
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
import org.bukkit.plugin.Plugin;
|
import org.bukkit.plugin.Plugin;
|
||||||
import org.bukkit.plugin.PluginManager;
|
import org.bukkit.plugin.PluginManager;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 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 {
|
public class Methods {
|
||||||
|
|
||||||
private Method Method = null;
|
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.earth2me.essentials.register.payment.methods.iCo4());
|
||||||
|
this.addMethod("iConomy", new com.earth2me.essentials.register.payment.methods.iCo5());
|
||||||
|
this.addMethod("BOSEconomy", new com.earth2me.essentials.register.payment.methods.BOSE());
|
||||||
|
}
|
||||||
|
|
||||||
|
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 (Method != null);
|
||||||
|
}
|
||||||
|
|
||||||
public boolean setMethod(Plugin method) {
|
public boolean setMethod(Plugin method) {
|
||||||
PluginManager manager = method.getServer().getPluginManager();
|
PluginManager manager = method.getServer().getPluginManager();
|
||||||
|
|
||||||
if (method != null && method.isEnabled()) {
|
if (method != null && method.isEnabled()) {
|
||||||
Method plugin = MethodFactory.createMethod(method);
|
Method plugin = this.createMethod(method);
|
||||||
if (plugin != null) Method = plugin;
|
if (plugin != null) Method = plugin;
|
||||||
} else {
|
} else {
|
||||||
for(String name: MethodFactory.getDependencies()) {
|
for(String name: this.getDependencies()) {
|
||||||
if(hasMethod()) break;
|
if(hasMethod()) break;
|
||||||
|
|
||||||
method = manager.getPlugin(name);
|
method = manager.getPlugin(name);
|
||||||
|
@ -22,7 +65,7 @@ public class Methods {
|
||||||
if(!method.isEnabled()) manager.enablePlugin(method);
|
if(!method.isEnabled()) manager.enablePlugin(method);
|
||||||
if(!method.isEnabled()) continue;
|
if(!method.isEnabled()) continue;
|
||||||
|
|
||||||
Method plugin = MethodFactory.createMethod(method);
|
Method plugin = this.createMethod(method);
|
||||||
if (plugin != null) Method = plugin;
|
if (plugin != null) Method = plugin;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -30,17 +73,13 @@ public class Methods {
|
||||||
return hasMethod();
|
return hasMethod();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Method getMethod() {
|
||||||
|
return Method;
|
||||||
|
}
|
||||||
|
|
||||||
public boolean checkDisabled(Plugin method) {
|
public boolean checkDisabled(Plugin method) {
|
||||||
if(!hasMethod()) return true;
|
if(!hasMethod()) return true;
|
||||||
if (Method.isCompatible(method)) Method = null;
|
if (Method.isCompatible(method)) Method = null;
|
||||||
return (Method == null);
|
return (Method == null);
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean hasMethod() {
|
|
||||||
return (Method != null);
|
|
||||||
}
|
|
||||||
|
|
||||||
public Method getMethod() {
|
|
||||||
return Method;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,18 +1,12 @@
|
||||||
package com.earth2me.essentials.register.payment.methods;
|
package com.earth2me.essentials.register.payment.methods;
|
||||||
|
|
||||||
import com.earth2me.essentials.register.payment.Method;
|
import com.earth2me.essentials.register.payment.Method;
|
||||||
import com.earth2me.essentials.register.payment.MethodFactory;
|
|
||||||
import cosine.boseconomy.BOSEconomy;
|
import cosine.boseconomy.BOSEconomy;
|
||||||
import org.bukkit.plugin.Plugin;
|
import org.bukkit.plugin.Plugin;
|
||||||
|
|
||||||
public class BOSE implements Method {
|
public class BOSE implements Method {
|
||||||
private BOSEconomy BOSEconomy;
|
private BOSEconomy BOSEconomy;
|
||||||
|
|
||||||
static {
|
|
||||||
MethodFactory.addMethod("BOSEconomy", new BOSE());
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
public BOSEconomy getPlugin() {
|
public BOSEconomy getPlugin() {
|
||||||
return this.BOSEconomy;
|
return this.BOSEconomy;
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,17 +2,14 @@ package com.earth2me.essentials.register.payment.methods;
|
||||||
|
|
||||||
import com.nijiko.coelho.iConomy.iConomy;
|
import com.nijiko.coelho.iConomy.iConomy;
|
||||||
import com.nijiko.coelho.iConomy.system.Account;
|
import com.nijiko.coelho.iConomy.system.Account;
|
||||||
|
|
||||||
import com.earth2me.essentials.register.payment.Method;
|
import com.earth2me.essentials.register.payment.Method;
|
||||||
import com.earth2me.essentials.register.payment.MethodFactory;
|
|
||||||
import org.bukkit.plugin.Plugin;
|
import org.bukkit.plugin.Plugin;
|
||||||
|
|
||||||
public class iCo4 implements Method {
|
public class iCo4 implements Method {
|
||||||
private iConomy iConomy;
|
private iConomy iConomy;
|
||||||
|
|
||||||
static {
|
|
||||||
MethodFactory.addMethod("iConomy", new iCo4());
|
|
||||||
}
|
|
||||||
|
|
||||||
public iConomy getPlugin() {
|
public iConomy getPlugin() {
|
||||||
return this.iConomy;
|
return this.iConomy;
|
||||||
}
|
}
|
||||||
|
@ -54,7 +51,7 @@ public class iCo4 implements Method {
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isCompatible(Plugin plugin) {
|
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) {
|
public void setPlugin(Plugin plugin) {
|
||||||
|
|
|
@ -5,17 +5,14 @@ import com.iConomy.system.Account;
|
||||||
import com.iConomy.system.BankAccount;
|
import com.iConomy.system.BankAccount;
|
||||||
import com.iConomy.system.Holdings;
|
import com.iConomy.system.Holdings;
|
||||||
import com.iConomy.util.Constants;
|
import com.iConomy.util.Constants;
|
||||||
|
|
||||||
import com.earth2me.essentials.register.payment.Method;
|
import com.earth2me.essentials.register.payment.Method;
|
||||||
import com.earth2me.essentials.register.payment.MethodFactory;
|
|
||||||
import org.bukkit.plugin.Plugin;
|
import org.bukkit.plugin.Plugin;
|
||||||
|
|
||||||
public class iCo5 implements Method {
|
public class iCo5 implements Method {
|
||||||
private iConomy iConomy;
|
private iConomy iConomy;
|
||||||
|
|
||||||
static {
|
|
||||||
MethodFactory.addMethod("iConomy", new iCo5());
|
|
||||||
}
|
|
||||||
|
|
||||||
public iConomy getPlugin() {
|
public iConomy getPlugin() {
|
||||||
return this.iConomy;
|
return this.iConomy;
|
||||||
}
|
}
|
||||||
|
@ -57,7 +54,7 @@ public class iCo5 implements Method {
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isCompatible(Plugin plugin) {
|
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) {
|
public void setPlugin(Plugin plugin) {
|
||||||
|
|
Loading…
Reference in a new issue