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)
This commit is contained in:
Jascha Starke 2013-03-29 11:14:10 +01:00
parent 467653891f
commit 7be648f552
2 changed files with 53 additions and 0 deletions

View file

@ -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();
}
}
}
}

View file

@ -32,6 +32,8 @@ public class LimitedCreative extends Core {
addModule(new ModGameModePerm(this)); addModule(new ModGameModePerm(this));
addModule(new FeatureMetrics(this)); addModule(new FeatureMetrics(this));
listeners.addListener(new DependencyListener(this));
config.setModuleStates(); config.setModuleStates();
config.saveDefault(); config.saveDefault();
} }