epsilonScript.Plugins = {};
epsilonScript.Plugins.Stored = {};

-- Function to register a plugin.
function epsilonScript.Plugins.RegisterPlugin( plugin )
	epsilonScript.Plugins.Stored[ plugin.Name ] = plugin;
end;

if ( SERVER ) then
	-- Function to return the given plugin.
	function epsilonScript.Plugins.GetPlugin( plugin, nottable )
		if ( epsilonScript.Plugins.Stored[ plugin ] != nil ) then
			if ( nottable ) then
				return plugin;
			else
				return epsilonScript.Plugins.Stored[ plugin ];
			end;
		else
			Error( "Plugin: " .. plugin .. " does not exist!" );
		end;
	end;
end;

-- Include plugins.
for k, v in pairs( file.FindInLua( "epsilonScript/gamemode/core/schemes/" .. epsilonScript.Config:Get( "ActiveScheme" ) .. "/plugins/*" ) ) do
	if ( v != "." and v != ".." ) then
		if ( SERVER ) then
			if ( file.Exists( "../gamemodes/epsilonScript/gamemode/core/schemes/" .. epsilonScript.Config:Get( "ActiveScheme" ) .. "/plugins/" .. v .. "/init.lua" ) ) then
				include( "epsilonScript/gamemode/core/schemes/" .. epsilonScript.Config:Get( "ActiveScheme" ) .. "/plugins/" .. v .. "/init.lua" );
			end;
			
			if ( file.Exists("../gamemodes/epsilonScript/core/gamemode/schemes/" .. epsilonScript.Config:Get( "ActiveScheme" ) .. "/plugins/" .. v .. "/cl_init.lua" ) ) then
				AddCSLuaFile( "epsilonScript/gamemode/core/schemes/" .. epsilonScript.Config:Get( "ActiveScheme" ) .. "/plugins/" .. v .. "/cl_init.lua" );
			end;
		else
			if ( file.Exists( "../lua_temp/epsilonScript/gamemode/core/schemes/" .. epsilonScript.Config:Get( "ActiveScheme" ) .. "/plugins/" .. v .. "/cl_init.lua" ) or file.Exists( "../gamemodes/epsilonScript/gamemode/core/schemes/" .. epsilonScript.Config:Get( "ActiveScheme" ) .. "/plugins/" .. v .. "/cl_init.lua" ) ) then
				include( "epsilonScript/gamemode/core/schemes/" .. epsilonScript.Config:Get( "ActiveScheme" ) .. "/plugins/" .. v .. "/cl_init.lua" );
			end;
		end;
	end;
end;