package com.kallendorf.fshook;

import java.util.Collection;

import de.espirit.common.bootstrap.Bootstrap;

import de.espirit.firstspirit.access.BaseContext;
import de.espirit.firstspirit.client.plugin.JavaClientEditorialToolbarItemsPlugin;
import de.espirit.firstspirit.client.plugin.Plugins;
import de.espirit.firstspirit.io.ServerConnection;
import de.espirit.firstspirit.client.plugin.Plugin;

public aspect PluginLoadAspect {
	
	pointcut main(): execution(void Bootstrap.main(String[]));
	
	before(): main(){
		System.out.println("Hooked It!");
	}
		
	Collection around(ServerConnection con, Class cls, BaseContext context): 
		call(* Plugins.getPlugins(ServerConnection, Class, BaseContext))
		&& args(con,cls,context)
		{
		System.out.println("Hooking Plugins: "+cls);
		Collection col=proceed(con,cls,context);
		
		for(Plugin p: CustomLoader.pluginsToLoad){
			if(cls.isInstance(p)) {
				System.out.println("Loaded "+p);	
				col.add(p);
			}
		}
		return col;
	}
}
