diff options
author | snowleo <snowleo@e251c2fe-e539-e718-e476-b85c1f46cddb> | 2011-05-14 10:14:58 +0000 |
---|---|---|
committer | snowleo <snowleo@e251c2fe-e539-e718-e476-b85c1f46cddb> | 2011-05-14 10:14:58 +0000 |
commit | 78ce69528fc346f670f28086496241714f98f8a3 (patch) | |
tree | fd99508fc119f8e7a224c3df8d0e98ba3a587275 | |
parent | 2b4724dae2ac6adc06e21647d26d9282eb378e20 (diff) | |
download | Essentials-78ce69528fc346f670f28086496241714f98f8a3.tar Essentials-78ce69528fc346f670f28086496241714f98f8a3.tar.gz Essentials-78ce69528fc346f670f28086496241714f98f8a3.tar.lz Essentials-78ce69528fc346f670f28086496241714f98f8a3.tar.xz Essentials-78ce69528fc346f670f28086496241714f98f8a3.zip |
Update to Register v1.0
Removed softDepend because of a bukkit bug.
git-svn-id: https://svn.java.net/svn/essentials~svn/trunk@1459 e251c2fe-e539-e718-e476-b85c1f46cddb
8 files changed, 80 insertions, 15 deletions
diff --git a/Essentials/src/com/earth2me/essentials/Essentials.java b/Essentials/src/com/earth2me/essentials/Essentials.java index 9895be834..fc73aaa82 100644 --- a/Essentials/src/com/earth2me/essentials/Essentials.java +++ b/Essentials/src/com/earth2me/essentials/Essentials.java @@ -35,6 +35,7 @@ import org.bukkit.craftbukkit.scheduler.CraftScheduler; import org.bukkit.entity.Player; import org.bukkit.event.Event.Priority; import org.bukkit.event.Event.Type; +import org.bukkit.event.server.ServerListener; import org.bukkit.plugin.*; import org.bukkit.plugin.java.*; @@ -121,12 +122,6 @@ public class Essentials extends JavaPlugin logger.log(Level.WARNING, Util.format("versionMismatch", plugin.getDescription().getName())); } } - if (!paymentMethod.hasMethod() && plugin != this) - { - if (getPaymentMethod().setMethod(plugin)) { - logger.log(Level.INFO, "Payment method found (" + getPaymentMethod().getMethod().getName() + " version: " + getPaymentMethod().getMethod().getVersion() + ")"); - } - } } Matcher versionMatch = Pattern.compile("git-Bukkit-([0-9]+).([0-9]+).([0-9]+)-[0-9]+-[0-9a-z]+-b([0-9]+)jnks.*").matcher(getServer().getVersion()); if (versionMatch.matches()) @@ -143,6 +138,10 @@ public class Essentials extends JavaPlugin } + ServerListener serverListener = new EssentialsPluginListener(paymentMethod); + pm.registerEvent(Type.PLUGIN_ENABLE, serverListener, Priority.Low, this); + pm.registerEvent(Type.PLUGIN_DISABLE, serverListener, Priority.Low, this); + playerListener = new EssentialsPlayerListener(this); pm.registerEvent(Type.PLAYER_JOIN, playerListener, Priority.Monitor, this); pm.registerEvent(Type.PLAYER_QUIT, playerListener, Priority.Monitor, this); @@ -176,7 +175,7 @@ public class Essentials extends JavaPlugin pm.registerEvent(Type.BLOCK_PLACE, jail, Priority.High, this); pm.registerEvent(Type.PLAYER_INTERACT, jailPlayerListener, Priority.High, this); attachEcoListeners(); - + if (settings.isNetherEnabled() && getServer().getWorlds().size() < 2) { getServer().createWorld(settings.getNetherName(), World.Environment.NETHER); @@ -336,10 +335,10 @@ public class Essentials extends JavaPlugin if ("msg".equals(commandLabel.toLowerCase()) || "mail".equals(commandLabel.toLowerCase()) & sender instanceof CraftPlayer) { StringBuilder str = new StringBuilder(); - str.append(commandLabel + " "); + str.append(commandLabel).append(" "); for (String a : args) { - str.append(a + " "); + str.append(a).append(" "); } for (Player player : getServer().getOnlinePlayers()) { diff --git a/Essentials/src/com/earth2me/essentials/EssentialsPluginListener.java b/Essentials/src/com/earth2me/essentials/EssentialsPluginListener.java new file mode 100644 index 000000000..b8c246dab --- /dev/null +++ b/Essentials/src/com/earth2me/essentials/EssentialsPluginListener.java @@ -0,0 +1,45 @@ +package com.earth2me.essentials; + +import com.earth2me.essentials.register.payment.Methods; +import java.util.logging.Level; +import java.util.logging.Logger; +import org.bukkit.event.server.PluginDisableEvent; +import org.bukkit.event.server.PluginEnableEvent; +import org.bukkit.event.server.ServerListener; + + +public class EssentialsPluginListener extends ServerListener +{ + Methods methods; + private final Logger logger = Logger.getLogger("Minecraft"); + + public EssentialsPluginListener(Methods methods) + { + this.methods = methods; + } + + @Override + public void onPluginEnable(PluginEnableEvent event) + { + if (!methods.hasMethod()) + { + if (methods.setMethod(event.getPlugin())) + { + logger.log(Level.INFO, "Payment method found (" + methods.getMethod().getName() + " version: " + methods.getMethod().getVersion() + ")"); + } + } + } + + @Override + public void onPluginDisable(PluginDisableEvent event) + { + // Check to see if the plugin thats being disabled is the one we are using + if (methods != null && methods.hasMethod()) + { + if (methods.checkDisabled(event.getPlugin())) + { + logger.log(Level.INFO, "Payment method was disabled. No longer accepting payments."); + } + } + } +} diff --git a/Essentials/src/com/earth2me/essentials/register/payment/MethodFactory.java b/Essentials/src/com/earth2me/essentials/register/payment/MethodFactory.java index 13049d5fb..655d392e8 100644 --- a/Essentials/src/com/earth2me/essentials/register/payment/MethodFactory.java +++ b/Essentials/src/com/earth2me/essentials/register/payment/MethodFactory.java @@ -7,6 +7,7 @@ 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) { @@ -19,7 +20,12 @@ public class MethodFactory { return null; } - public static void addMethod(Method method) { + public static void addMethod(String name, Method method) { + Dependencies.add(name); Methods.add(method); } + + public static Set<String> getDependencies() { + return Dependencies; + } } diff --git a/Essentials/src/com/earth2me/essentials/register/payment/Methods.java b/Essentials/src/com/earth2me/essentials/register/payment/Methods.java index 4ee228f88..f93b29a6e 100644 --- a/Essentials/src/com/earth2me/essentials/register/payment/Methods.java +++ b/Essentials/src/com/earth2me/essentials/register/payment/Methods.java @@ -1,15 +1,30 @@ package com.earth2me.essentials.register.payment; import org.bukkit.plugin.Plugin; +import org.bukkit.plugin.PluginManager; public class Methods { private Method Method = null; public boolean setMethod(Plugin method) { - if (method.isEnabled()) { + PluginManager manager = method.getServer().getPluginManager(); + + if (method != null && method.isEnabled()) { Method plugin = MethodFactory.createMethod(method); if (plugin != null) Method = plugin; + } else { + for(String name: MethodFactory.getDependencies()) { + if(hasMethod()) break; + + 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; + } } return hasMethod(); diff --git a/Essentials/src/com/earth2me/essentials/register/payment/methods/BOSE.java b/Essentials/src/com/earth2me/essentials/register/payment/methods/BOSE.java index ebe839453..ba7b727b7 100644 --- a/Essentials/src/com/earth2me/essentials/register/payment/methods/BOSE.java +++ b/Essentials/src/com/earth2me/essentials/register/payment/methods/BOSE.java @@ -9,7 +9,8 @@ public class BOSE implements Method { private BOSEconomy BOSEconomy; static { - MethodFactory.addMethod(new BOSE()); + MethodFactory.addMethod("BOSEconomy", new BOSE()); + } public BOSEconomy getPlugin() { diff --git a/Essentials/src/com/earth2me/essentials/register/payment/methods/iCo4.java b/Essentials/src/com/earth2me/essentials/register/payment/methods/iCo4.java index 5f982af23..5eb3ae9a9 100644 --- a/Essentials/src/com/earth2me/essentials/register/payment/methods/iCo4.java +++ b/Essentials/src/com/earth2me/essentials/register/payment/methods/iCo4.java @@ -10,7 +10,7 @@ public class iCo4 implements Method { private iConomy iConomy; static { - MethodFactory.addMethod(new iCo4()); + MethodFactory.addMethod("iConomy", new iCo4()); } public iConomy getPlugin() { diff --git a/Essentials/src/com/earth2me/essentials/register/payment/methods/iCo5.java b/Essentials/src/com/earth2me/essentials/register/payment/methods/iCo5.java index 7d326f6e0..0956e0556 100644 --- a/Essentials/src/com/earth2me/essentials/register/payment/methods/iCo5.java +++ b/Essentials/src/com/earth2me/essentials/register/payment/methods/iCo5.java @@ -13,7 +13,7 @@ public class iCo5 implements Method { private iConomy iConomy; static { - MethodFactory.addMethod(new iCo5()); + MethodFactory.addMethod("iConomy", new iCo5()); } public iConomy getPlugin() { diff --git a/Essentials/src/plugin.yml b/Essentials/src/plugin.yml index a57a94548..468540769 100644 --- a/Essentials/src/plugin.yml +++ b/Essentials/src/plugin.yml @@ -6,7 +6,6 @@ version: TeamCity website: http://www.earth2me.net:8001/
description: Provides an essential, core set of commands for Bukkit.
authors: [Zenexer, ementalo, Aelux, Brettflan, KimKandor, snowleo, ceulemans, Xeology]
-softdepend: [Permissions, iConomy, BOSEconomy]
commands:
afk:
description: Marks you as away-from-keyboard.
|