/// <summary>
        /// Move a player, to another entity (which can be of Grid, Voxel).
        /// </summary>
        /// <param name="sourcePlayer"></param>
        /// <param name="target"></param>
        /// <param name="safely"></param>
        /// <param name="updatedPosition"></param>
        /// <param name="emptySourceMessage"></param>
        /// <param name="emptyTargetMessage"></param>
        /// <param name="noSafeLocationMessage"></param>
        /// <returns></returns>
        public static bool MoveTo(IMyPlayer sourcePlayer, IMyEntity target, bool safely,
            Action<Vector3D> updatedPosition, Action emptySourceMessage, Action emptyTargetMessage, Action noSafeLocationMessage)
        {
            if (sourcePlayer == null)
            {
                if (emptySourceMessage != null)
                    emptySourceMessage.Invoke();
                return false;
            }

            if (target == null || target.Closed)
            {
                if (emptyTargetMessage != null)
                    emptyTargetMessage.Invoke();
                return false;
            }

            if (sourcePlayer.Controller.ControlledEntity is IMyCubeBlock)
            {
                // player is piloting a ship. Move ship to entity.
                return MoveTo(sourcePlayer.Controller.ControlledEntity.Entity.GetTopMostParent(), target, safely, updatedPosition, emptySourceMessage, emptyTargetMessage, noSafeLocationMessage);
            }

            // Player is free floating, we move the player only.
            if (target is IMyCubeGrid)
            {
                var grid = (Sandbox.Game.Entities.MyCubeGrid)target;

                // Station or Large ship grids.
                if (((IMyCubeGrid)target).GridSizeEnum != MyCubeSize.Small)
                {
                    IMyControllableEntity targetCockpit = null;

                    if (grid.HasMainCockpit())
                    {
                        // Select the main cockpit.
                        targetCockpit = (IMyControllableEntity)grid.MainCockpit;
                    }
                    else
                    {
                        var cockpits = target.FindWorkingCockpits();
                        var operationalCockpit = cockpits.FirstOrDefault(c => ((Sandbox.ModAPI.Ingame.IMyCockpit)c).IsShipControlEnabled());

                        if (operationalCockpit != null)
                            // find a cockpit which is not a passenger seat.
                            targetCockpit = operationalCockpit;
                        else if (cockpits.Length > 0)
                            targetCockpit = cockpits[0];
                    }

                    if (targetCockpit != null)
                        return MovePlayerToCube(sourcePlayer, (IMyCubeBlock)targetCockpit, safely, updatedPosition, noSafeLocationMessage);
                }

                // Small ship grids. Also the fallback if a large ship does not have a cockpit.
                return MovePlayerToShipGrid(sourcePlayer, (IMyCubeGrid)target, safely, updatedPosition, noSafeLocationMessage);
            }

            if (target is IMyVoxelBase)
            {
                return MovePlayerToVoxel(sourcePlayer, (IMyVoxelBase)target, safely, updatedPosition, emptySourceMessage, emptyTargetMessage, noSafeLocationMessage);
            }

            return false;
        }
        private void MovePlayerPilotToShip(IMyPlayer sourcePlayer, IMyEntity targetedShip)
        {
            if (sourcePlayer == null)
            {
                MyAPIGateway.Utilities.ShowMessage("Teleport failed", "Source Player no longer exists.");
                return;
            }

            if (targetedShip == null)
            {
                MyAPIGateway.Utilities.ShowMessage("Teleport failed", "Targeted Ship not found.");
                return;
            }

            if (targetedShip.Closed)
            {
                MyAPIGateway.Utilities.ShowMessage("Teleport failed", "Targeted Ship no longer exists.");
                return;
            }

            bool success;

            if (sourcePlayer.Controller.ControlledEntity is IMyCubeBlock)
            {
                // TODO: complete code.
                success = Support.MoveShipToShip(sourcePlayer.Controller.ControlledEntity.Entity.GetTopMostParent(), targetedShip);
            }
            else
            {
                // Move the player only.
                var cockpits = targetedShip.FindWorkingCockpits();
                if (cockpits.Length > 0 && ((IMyCubeGrid)targetedShip).GridSizeEnum != Sandbox.Common.ObjectBuilders.MyCubeSize.Small)
                {
                    success = Support.MovePlayerToCockpit(sourcePlayer, (IMyEntity)cockpits[0]);
                }
                else
                {
                    success = Support.MovePlayerToShipGrid(sourcePlayer, targetedShip);
                }
            }

            if (!success)
                MyAPIGateway.Utilities.ShowMessage("Teleport failed", "Could not find a safe location to teleport to.");
        }