Add a PluginListener type for use in the PluginManager.

This commit is contained in:
Danila Fedorin 2017-07-27 14:06:04 -07:00
parent e6559015b3
commit f2c280766d
2 changed files with 40 additions and 0 deletions

View File

@ -0,0 +1,20 @@
package org.nwapw.abacus.plugin;
/**
* A listener that responds to changes in the PluginManager.
*/
public interface PluginListener {
/**
* Called when the PluginManager loads plugins.
* @param manager the manager that fired the event.
*/
public void onLoad(PluginManager manager);
/**
* Called when the PluginManager unloads all its plugins.
* @param manager the manager that fired the event.
*/
public void onUnload(PluginManager manager);
}

View File

@ -48,6 +48,7 @@ public class PluginManager {
cachedOperators = new HashMap<>();
allFunctions = new HashSet<>();
allOperators = new HashSet<>();
listeners = new HashSet<>();
}
/**
@ -129,6 +130,7 @@ public class PluginManager {
allFunctions.addAll(plugin.providedFunctions());
allOperators.addAll(plugin.providedOperators());
}
listeners.forEach(e -> e.onLoad(this));
}
/**
@ -138,6 +140,7 @@ public class PluginManager {
for(Plugin plugin : plugins) plugin.disable();
allFunctions.clear();
allOperators.clear();
listeners.forEach(e -> e.onUnload(this));
}
/**
@ -163,4 +166,21 @@ public class PluginManager {
public HashSet<String> getAllOperators() {
return allOperators;
}
/**
* Adds a plugin change listener to this plugin manager.
* @param listener the listener to add.
*/
public void addListener(PluginListener listener){
listeners.add(listener);
}
/**
* Remove the plugin change listener from this plugin manager.
* @param listener the listener to remove.
*/
public void removeListener(PluginListener listener){
listeners.remove(listener);
}
}