Dateien nach "src/main/java/net/viper/status/module" hochladen
This commit is contained in:
24
src/main/java/net/viper/status/module/Module.java
Normal file
24
src/main/java/net/viper/status/module/Module.java
Normal file
@@ -0,0 +1,24 @@
|
|||||||
|
package net.viper.status.module;
|
||||||
|
|
||||||
|
import net.md_5.bungee.api.plugin.Plugin;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Interface für alle zukünftigen Erweiterungen.
|
||||||
|
*/
|
||||||
|
public interface Module {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Wird aufgerufen, wenn die API startet.
|
||||||
|
*/
|
||||||
|
void onEnable(Plugin plugin);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Wird aufgerufen, wenn die API stoppt.
|
||||||
|
*/
|
||||||
|
void onDisable(Plugin plugin);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Eindeutiger Name des Moduls (z.B. "StatsModule").
|
||||||
|
*/
|
||||||
|
String getName();
|
||||||
|
}
|
||||||
60
src/main/java/net/viper/status/module/ModuleManager.java
Normal file
60
src/main/java/net/viper/status/module/ModuleManager.java
Normal file
@@ -0,0 +1,60 @@
|
|||||||
|
package net.viper.status.module;
|
||||||
|
|
||||||
|
import net.md_5.bungee.api.plugin.Plugin;
|
||||||
|
|
||||||
|
import java.util.Collection;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Verwaltet alle geladenen Module.
|
||||||
|
*/
|
||||||
|
public class ModuleManager {
|
||||||
|
|
||||||
|
private final Map<String, Module> modules = new HashMap<>();
|
||||||
|
|
||||||
|
public void registerModule(Module module) {
|
||||||
|
modules.put(module.getName().toLowerCase(), module);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void enableAll(Plugin plugin) {
|
||||||
|
for (Module module : modules.values()) {
|
||||||
|
try {
|
||||||
|
plugin.getLogger().info("Aktiviere Modul: " + module.getName() + "...");
|
||||||
|
module.onEnable(plugin);
|
||||||
|
} catch (Exception e) {
|
||||||
|
plugin.getLogger().severe("Fehler beim Aktivieren von Modul " + module.getName() + ": " + e.getMessage());
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void disableAll(Plugin plugin) {
|
||||||
|
for (Module module : modules.values()) {
|
||||||
|
try {
|
||||||
|
plugin.getLogger().info("Deaktiviere Modul: " + module.getName() + "...");
|
||||||
|
module.onDisable(plugin);
|
||||||
|
} catch (Exception e) {
|
||||||
|
plugin.getLogger().warning("Fehler beim Deaktivieren von Modul " + module.getName());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
modules.clear();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Ermöglicht anderen Komponenten (wie dem WebServer) Zugriff auf spezifische Module.
|
||||||
|
*/
|
||||||
|
public Module getModule(String name) {
|
||||||
|
return modules.get(name.toLowerCase());
|
||||||
|
}
|
||||||
|
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
|
public <T extends Module> T getModule(Class<T> clazz) {
|
||||||
|
for (Module m : modules.values()) {
|
||||||
|
if (clazz.isInstance(m)) {
|
||||||
|
return (T) m;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user