70 lines
1.7 KiB
Java
70 lines
1.7 KiB
Java
package de.mrbesen.cppplugins;
|
|
|
|
import lombok.Getter;
|
|
import org.bukkit.Bukkit;
|
|
import org.bukkit.plugin.Plugin;
|
|
import org.bukkit.plugin.java.JavaPlugin;
|
|
|
|
import java.io.File;
|
|
import java.util.function.Consumer;
|
|
import java.util.logging.Level;
|
|
|
|
public class CppPlugins extends JavaPlugin {
|
|
|
|
@Getter
|
|
private static CppPlugins instance;
|
|
|
|
public CppPlugins() {
|
|
instance = this;
|
|
}
|
|
|
|
@Override
|
|
public void onLoad() {
|
|
Bukkit.getPluginManager().registerInterface(CppLoader.class);
|
|
getLogger().info("registered");
|
|
|
|
File pluginsFolder = new File("plugins/");
|
|
File[] pluginFiles = pluginsFolder.listFiles((dir, name) -> name.endsWith(".so"));
|
|
for(File pluginFile : pluginFiles) {
|
|
try {
|
|
Bukkit.getPluginManager().loadPlugin(pluginFile);
|
|
System.out.println("loaded " + pluginFile.getName());
|
|
} catch (Throwable e) {
|
|
getLogger().log(Level.SEVERE, "Error occurred during loading in plugin: " + pluginFile.getName(), e);
|
|
}
|
|
}
|
|
|
|
//trigger on Load
|
|
forEach(pl -> {
|
|
try {
|
|
pl.onLoad();
|
|
} catch (Throwable t) {
|
|
getLogger().log(Level.WARNING, "Error in onLoad() of Plugin: " + pl.getName(), t);
|
|
}
|
|
});
|
|
}
|
|
|
|
@Override
|
|
public void onDisable() {
|
|
Plugin[] pls = Bukkit.getPluginManager().getPlugins();
|
|
for (int i = 0; i < pls.length; i++) {
|
|
Plugin p = pls[i];
|
|
if(p.isEnabled()) {
|
|
if(p.getPluginLoader().getClass().equals(CppLoader.class)) {
|
|
p.getPluginLoader().disablePlugin(p);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
//iteratoe over all CppPlugins
|
|
public void forEach(Consumer<CppPlugin> cons) {
|
|
Plugin[] pls = Bukkit.getPluginManager().getPlugins();
|
|
for (int i = 0; i < pls.length; i++) {
|
|
if(pls[i] instanceof CppPlugin) {
|
|
cons.accept((CppPlugin) pls[i]);
|
|
}
|
|
}
|
|
}
|
|
}
|