mirror of
https://github.com/DanilaFe/abacus
synced 2024-12-23 16:00:09 -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<>();
|
cachedOperators = new HashMap<>();
|
||||||
allFunctions = new HashSet<>();
|
allFunctions = new HashSet<>();
|
||||||
allOperators = new HashSet<>();
|
allOperators = new HashSet<>();
|
||||||
|
listeners = new HashSet<>();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -129,6 +130,7 @@ public class PluginManager {
|
||||||
allFunctions.addAll(plugin.providedFunctions());
|
allFunctions.addAll(plugin.providedFunctions());
|
||||||
allOperators.addAll(plugin.providedOperators());
|
allOperators.addAll(plugin.providedOperators());
|
||||||
}
|
}
|
||||||
|
listeners.forEach(e -> e.onLoad(this));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -138,6 +140,7 @@ public class PluginManager {
|
||||||
for(Plugin plugin : plugins) plugin.disable();
|
for(Plugin plugin : plugins) plugin.disable();
|
||||||
allFunctions.clear();
|
allFunctions.clear();
|
||||||
allOperators.clear();
|
allOperators.clear();
|
||||||
|
listeners.forEach(e -> e.onUnload(this));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -163,4 +166,21 @@ public class PluginManager {
|
||||||
public HashSet<String> getAllOperators() {
|
public HashSet<String> getAllOperators() {
|
||||||
return allOperators;
|
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