mirror of
https://github.com/DanilaFe/abacus
synced 2024-11-17 16:09:32 -08:00
Add a PluginListener type for use in the PluginManager.
This commit is contained in:
parent
f29fea6106
commit
4f9c8dee9a
20
src/org/nwapw/abacus/plugin/PluginListener.java
Normal file
20
src/org/nwapw/abacus/plugin/PluginListener.java
Normal 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);
|
||||
|
||||
}
|
|
@ -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);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user