From 7be648f5527e1d52ff3cab5dde3feb0f12202fea Mon Sep 17 00:00:00 2001 From: Jascha Starke Date: Fri, 29 Mar 2013 11:14:10 +0100 Subject: [PATCH] Late loading/unloading of conflicting/depended plugins now disables the related modules The opposite (if dependency are fixed again) is not implemented. A full server reload is required to re-enable the modules. (A reload with PluginManager works to, but is not recommended) --- .../limitedcreative/DependencyListener.java | 51 +++++++++++++++++++ .../limitedcreative/LimitedCreative.java | 2 + 2 files changed, 53 insertions(+) create mode 100644 src/main/java/de/jaschastarke/minecraft/limitedcreative/DependencyListener.java diff --git a/src/main/java/de/jaschastarke/minecraft/limitedcreative/DependencyListener.java b/src/main/java/de/jaschastarke/minecraft/limitedcreative/DependencyListener.java new file mode 100644 index 0000000..3ab35e9 --- /dev/null +++ b/src/main/java/de/jaschastarke/minecraft/limitedcreative/DependencyListener.java @@ -0,0 +1,51 @@ +package de.jaschastarke.minecraft.limitedcreative; + +import org.bukkit.event.EventHandler; +import org.bukkit.event.Listener; +import org.bukkit.event.server.PluginDisableEvent; +import org.bukkit.event.server.PluginEnableEvent; + +import de.jaschastarke.modularize.ModuleEntry.ModuleState; + +/** + * @Todo may be abstract to some per-module-definitions that are checked onEnabled and here automaticly + */ +public class DependencyListener implements Listener { + private LimitedCreative plugin; + + public DependencyListener(LimitedCreative plugin) { + this.plugin = plugin; + } + + @EventHandler + public void onPluginLoaded(PluginEnableEvent event) { + ModInventories mod = plugin.getModule(ModInventories.class); + if (mod != null && mod.getModuleEntry().getState() == ModuleState.ENABLED) { + String incomp = Hooks.InventoryIncompatible.test(); + if (incomp != null) { + mod.getLog().warn(plugin.getLocale().trans("inventory.warning.conflict", incomp, mod.getName())); + mod.getModuleEntry().initialState = ModuleState.NOT_INITIALIZED; + mod.getModuleEntry().disable(); + } + } + } + + @EventHandler + public void onPluginUnloaded(PluginDisableEvent event) { + if (event.getPlugin().getName().equals("Vault")) { + ModGameModePerm mod = plugin.getModule(ModGameModePerm.class); + if (mod != null && mod.getModuleEntry().getState() == ModuleState.ENABLED) { + mod.getLog().warn(plugin.getLocale().trans("gmperm.warning.vault_not_found", mod.getName())); + mod.getModuleEntry().initialState = ModuleState.NOT_INITIALIZED; + mod.getModuleEntry().disable(); + } + } else if (event.getPlugin().getName().equals("WorldGuard")) { + ModRegions mod = plugin.getModule(ModRegions.class); + if (mod != null && mod.getModuleEntry().getState() == ModuleState.ENABLED) { + mod.getLog().warn(plugin.getLocale().trans("region.warning.worldguard_not_found", mod.getName())); + mod.getModuleEntry().initialState = ModuleState.NOT_INITIALIZED; + mod.getModuleEntry().disable(); + } + } + } +} diff --git a/src/main/java/de/jaschastarke/minecraft/limitedcreative/LimitedCreative.java b/src/main/java/de/jaschastarke/minecraft/limitedcreative/LimitedCreative.java index bdcf525..cb8345c 100644 --- a/src/main/java/de/jaschastarke/minecraft/limitedcreative/LimitedCreative.java +++ b/src/main/java/de/jaschastarke/minecraft/limitedcreative/LimitedCreative.java @@ -32,6 +32,8 @@ public class LimitedCreative extends Core { addModule(new ModGameModePerm(this)); addModule(new FeatureMetrics(this)); + listeners.addListener(new DependencyListener(this)); + config.setModuleStates(); config.saveDefault(); }