2011-06-14 15:07:44 +02:00
|
|
|
package com.nijikokun.register.payment.forChestShop;
|
2011-05-15 18:16:25 +02:00
|
|
|
|
2011-07-15 21:45:26 +02:00
|
|
|
import com.nijikokun.register.payment.forChestShop.methods.BOSE6;
|
|
|
|
import com.nijikokun.register.payment.forChestShop.methods.BOSE7;
|
2011-07-01 14:12:26 +02:00
|
|
|
import org.bukkit.plugin.Plugin;
|
|
|
|
import org.bukkit.plugin.PluginManager;
|
|
|
|
|
2011-07-15 21:45:26 +02:00
|
|
|
import java.util.HashSet;
|
|
|
|
import java.util.Set;
|
|
|
|
|
2011-05-16 17:35:12 +02:00
|
|
|
/**
|
|
|
|
* 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>
|
|
|
|
*/
|
2011-05-15 18:16:25 +02:00
|
|
|
public class Methods {
|
2011-05-29 13:25:25 +02:00
|
|
|
private boolean self = false;
|
2011-05-15 18:16:25 +02:00
|
|
|
private Method Method = null;
|
2011-05-29 13:25:25 +02:00
|
|
|
private String preferred = "";
|
2011-05-16 17:35:12 +02:00
|
|
|
private Set<Method> Methods = new HashSet<Method>();
|
|
|
|
private Set<String> Dependencies = new HashSet<String>();
|
2011-05-29 13:25:25 +02:00
|
|
|
private Set<Method> Attachables = new HashSet<Method>();
|
2011-05-15 18:16:25 +02:00
|
|
|
|
2011-05-16 17:35:12 +02:00
|
|
|
public Methods() {
|
2011-05-29 13:25:25 +02:00
|
|
|
this._init();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Allows you to set which economy plugin is most preferred.
|
2011-07-01 14:12:26 +02:00
|
|
|
*
|
2011-07-15 21:45:26 +02:00
|
|
|
* @param preferred - preferred economy plugin
|
2011-05-29 13:25:25 +02:00
|
|
|
*/
|
|
|
|
public Methods(String preferred) {
|
|
|
|
this._init();
|
|
|
|
|
2011-07-01 14:12:26 +02:00
|
|
|
if(this.Dependencies.contains(preferred)) {
|
2011-05-29 13:25:25 +02:00
|
|
|
this.preferred = preferred;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private void _init() {
|
2011-06-14 15:07:44 +02:00
|
|
|
this.addMethod("iConomy", new com.nijikokun.register.payment.forChestShop.methods.iCo4());
|
|
|
|
this.addMethod("iConomy", new com.nijikokun.register.payment.forChestShop.methods.iCo5());
|
2011-07-15 21:45:26 +02:00
|
|
|
this.addMethod("BOSEconomy", new BOSE6());
|
|
|
|
this.addMethod("BOSEconomy", new BOSE7());
|
2011-06-14 15:07:44 +02:00
|
|
|
this.addMethod("Essentials", new com.nijikokun.register.payment.forChestShop.methods.EE17());
|
2011-05-16 17:35:12 +02:00
|
|
|
}
|
2011-05-15 18:16:25 +02:00
|
|
|
|
2011-05-16 17:35:12 +02:00
|
|
|
public Set<String> getDependencies() {
|
|
|
|
return Dependencies;
|
|
|
|
}
|
2011-05-15 18:16:25 +02:00
|
|
|
|
2011-07-23 21:00:47 +02:00
|
|
|
Method createMethod(Plugin plugin) {
|
2011-07-01 14:12:26 +02:00
|
|
|
for (Method method: Methods) {
|
2011-05-16 17:35:12 +02:00
|
|
|
if (method.isCompatible(plugin)) {
|
|
|
|
method.setPlugin(plugin);
|
|
|
|
return method;
|
2011-05-15 18:16:25 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-05-16 17:35:12 +02:00
|
|
|
return null;
|
2011-05-15 18:16:25 +02:00
|
|
|
}
|
|
|
|
|
2011-05-16 17:35:12 +02:00
|
|
|
private void addMethod(String name, Method method) {
|
|
|
|
Dependencies.add(name);
|
|
|
|
Methods.add(method);
|
2011-05-15 18:16:25 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public boolean hasMethod() {
|
2011-05-29 13:25:25 +02:00
|
|
|
return (Method != null);
|
2011-05-16 17:35:12 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public boolean setMethod(Plugin method) {
|
2011-07-01 14:12:26 +02:00
|
|
|
if(hasMethod()) return true;
|
|
|
|
if(self) { self = false; return false; }
|
2011-05-16 17:35:12 +02:00
|
|
|
|
2011-05-29 13:25:25 +02:00
|
|
|
int count = 0;
|
|
|
|
boolean match = false;
|
2011-07-15 21:45:26 +02:00
|
|
|
Plugin plugin;
|
2011-05-29 13:25:25 +02:00
|
|
|
PluginManager manager = method.getServer().getPluginManager();
|
2011-05-16 17:35:12 +02:00
|
|
|
|
2011-07-23 21:00:47 +02:00
|
|
|
for(String name: this.Dependencies) {
|
2011-07-01 14:12:26 +02:00
|
|
|
if(hasMethod()) break;
|
|
|
|
if(method.getDescription().getName().equals(name)) plugin = method; else plugin = manager.getPlugin(name);
|
|
|
|
if(plugin == null) continue;
|
2011-05-16 17:35:12 +02:00
|
|
|
|
|
|
|
Method current = this.createMethod(plugin);
|
2011-07-01 14:12:26 +02:00
|
|
|
if(current == null) continue;
|
2011-05-29 13:25:25 +02:00
|
|
|
|
2011-07-01 14:12:26 +02:00
|
|
|
if(this.preferred.isEmpty())
|
2011-05-29 13:25:25 +02:00
|
|
|
this.Method = current;
|
|
|
|
else {
|
|
|
|
this.Attachables.add(current);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-07-01 14:12:26 +02:00
|
|
|
if(!this.preferred.isEmpty()) {
|
2011-05-29 13:25:25 +02:00
|
|
|
do {
|
2011-07-01 14:12:26 +02:00
|
|
|
if(hasMethod()) {
|
2011-05-29 13:25:25 +02:00
|
|
|
match = true;
|
|
|
|
} else {
|
2011-07-01 14:12:26 +02:00
|
|
|
for(Method attached: this.Attachables) {
|
|
|
|
if(attached == null) continue;
|
2011-05-29 13:25:25 +02:00
|
|
|
|
2011-07-01 14:12:26 +02:00
|
|
|
if(hasMethod()) {
|
2011-05-29 13:25:25 +02:00
|
|
|
match = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2011-07-01 14:12:26 +02:00
|
|
|
if(this.preferred.isEmpty()) this.Method = attached;
|
2011-05-29 13:25:25 +02:00
|
|
|
|
2011-07-01 14:12:26 +02:00
|
|
|
if(count == 0) {
|
|
|
|
if(this.preferred.equalsIgnoreCase(attached.getName()))
|
2011-05-29 13:25:25 +02:00
|
|
|
this.Method = attached;
|
|
|
|
} else {
|
|
|
|
this.Method = attached;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
count++;
|
|
|
|
}
|
2011-07-01 14:12:26 +02:00
|
|
|
} while(!match);
|
2011-05-16 17:35:12 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return hasMethod();
|
2011-05-15 18:16:25 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public Method getMethod() {
|
|
|
|
return Method;
|
|
|
|
}
|
2011-05-16 17:35:12 +02:00
|
|
|
|
|
|
|
public boolean checkDisabled(Plugin method) {
|
2011-07-01 14:12:26 +02:00
|
|
|
if(!hasMethod()) return true;
|
2011-05-16 17:35:12 +02:00
|
|
|
if (Method.isCompatible(method)) Method = null;
|
|
|
|
return (Method == null);
|
|
|
|
}
|
2011-05-15 18:16:25 +02:00
|
|
|
}
|