summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorementalo <ementalo@e251c2fe-e539-e718-e476-b85c1f46cddb>2011-06-01 15:10:59 +0000
committerementalo <ementalo@e251c2fe-e539-e718-e476-b85c1f46cddb>2011-06-01 15:10:59 +0000
commitd313d0dc87d3e42c7ec3a40be146f4631b5534ee (patch)
tree5079e2937c74636f332926e4504bf982cc779996
parent8e151357ce4f1bb4c5edb6d41e66e4d1a23798d8 (diff)
downloadEssentials-d313d0dc87d3e42c7ec3a40be146f4631b5534ee.tar
Essentials-d313d0dc87d3e42c7ec3a40be146f4631b5534ee.tar.gz
Essentials-d313d0dc87d3e42c7ec3a40be146f4631b5534ee.tar.lz
Essentials-d313d0dc87d3e42c7ec3a40be146f4631b5534ee.tar.xz
Essentials-d313d0dc87d3e42c7ec3a40be146f4631b5534ee.zip
[trunk] quickfix for concurrent issues
git-svn-id: https://svn.java.net/svn/essentials~svn/trunk@1556 e251c2fe-e539-e718-e476-b85c1f46cddb
-rw-r--r--Essentials/src/com/earth2me/essentials/register/payment/Methods.java248
1 files changed, 141 insertions, 107 deletions
diff --git a/Essentials/src/com/earth2me/essentials/register/payment/Methods.java b/Essentials/src/com/earth2me/essentials/register/payment/Methods.java
index 69625db6e..8b71e95be 100644
--- a/Essentials/src/com/earth2me/essentials/register/payment/Methods.java
+++ b/Essentials/src/com/earth2me/essentials/register/payment/Methods.java
@@ -5,7 +5,8 @@ import java.util.Set;
import org.bukkit.plugin.Plugin;
import org.bukkit.plugin.PluginManager;
-
+
+
/***
* Methods.java
* Controls the getting / setting of methods & the method of payment used.
@@ -14,113 +15,146 @@ import org.bukkit.plugin.PluginManager;
* @copyright: Copyright (C) 2011
* @license: GNUv3 Affero License <http://www.gnu.org/licenses/agpl-3.0.html>
*/
-public class Methods {
- private boolean self = false;
- private Method Method = null;
+public class Methods
+{
+ private boolean self = false;
+ private Method Method = null;
private String preferred = "";
- private Set<Method> Methods = new HashSet<Method>();
- private Set<String> Dependencies = new HashSet<String>();
+ private Set<Method> Methods = new HashSet<Method>();
+ private Set<String> Dependencies = new HashSet<String>();
private Set<Method> Attachables = new HashSet<Method>();
- 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) {
- if(hasMethod()) return true;
- if(self) { self = false; return false; }
-
- int count = 0;
- boolean match = false;
- Plugin plugin = null;
- PluginManager manager = method.getServer().getPluginManager();
-
- 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()) {
- this.self = true;
- manager.enablePlugin(plugin);
- }
-
- if(plugin == null) continue;
-
- Method current = this.createMethod(plugin);
- if(current == null) continue;
-
- if(this.preferred.isEmpty())
- this.Method = current;
- else {
- this.Attachables.add(current);
- }
- }
-
- if(!this.preferred.isEmpty()) {
- do {
- if(hasMethod()) {
- match = true;
- } else {
- for(Method attached: this.Attachables) {
- if(attached == null) continue;
-
- if(hasMethod()) {
- match = true;
- break;
- }
-
- if(this.preferred.isEmpty()) this.Method = attached;
-
- if(count == 0) {
- if(this.preferred.equalsIgnoreCase(attached.getName()))
- this.Method = attached;
- } else {
- this.Method = attached;
- }
- }
-
- count++;
- }
- } while(!match);
- }
-
- 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 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)
+ {
+ if (hasMethod()) return true;
+ if (self)
+ {
+ self = false;
+ return false;
+ }
+
+ int count = 0;
+ boolean match = false;
+ Plugin plugin = null;
+ PluginManager manager = method.getServer().getPluginManager();
+
+ 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())
+ {
+ this.self = true;
+ if (!plugin.getDescription().getName().toLowerCase().equals("essentials"))
+ {
+ manager.enablePlugin(plugin);
+ }
+ }
+
+ if (plugin == null) continue;
+
+ Method current = this.createMethod(plugin);
+ if (current == null) continue;
+
+ if (this.preferred.isEmpty())
+ this.Method = current;
+ else
+ {
+ this.Attachables.add(current);
+ }
+ }
+
+ if (!this.preferred.isEmpty())
+ {
+ do
+ {
+ if (hasMethod())
+ {
+ match = true;
+ }
+ else
+ {
+ for (Method attached : this.Attachables)
+ {
+ if (attached == null) continue;
+
+ if (hasMethod())
+ {
+ match = true;
+ break;
+ }
+
+ if (this.preferred.isEmpty()) this.Method = attached;
+
+ if (count == 0)
+ {
+ if (this.preferred.equalsIgnoreCase(attached.getName()))
+ this.Method = attached;
+ }
+ else
+ {
+ this.Method = attached;
+ }
+ }
+
+ count++;
+ }
+ }
+ while (!match);
+ }
+
+ 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);
+ }
}