SEModAPIExtensions.API.PluginManager.DoUpdate C# (CSharp) Method

DoUpdate() public static method

public static DoUpdate ( object args ) : void
args object
return void
        public static void DoUpdate( object args )
        {
            try
            {
                if ( args == null )
                    return;
                PluginManagerThreadParams parameters = (PluginManagerThreadParams)args;

                List<EntityEventManager.EntityEvent> events = parameters.Events;
                List<ChatManager.ChatEvent> chatEvents = parameters.ChatEvents;
                Object plugin = parameters.Plugin;
                Dictionary<Guid, IPlugin> plugins = parameters.Plugins;
                Dictionary<Guid, bool> pluginState = parameters.PluginState;

                //Run entity events
                foreach ( EntityEventManager.EntityEvent entityEvent in events )
                {
                    //If this is a cube block created event and the parent cube grid is still loading then defer the event
                    if ( entityEvent.type == EntityEventManager.EntityEventType.OnCubeBlockCreated )
                    {
                        CubeBlockEntity cubeBlock = (CubeBlockEntity)entityEvent.entity;
                        if ( cubeBlock.Parent.IsLoading )
                        {
                            EntityEventManager.Instance.AddEvent( entityEvent );
                            continue;
                        }
                    }

                    switch ( entityEvent.type )
                    {
                        case EntityEventManager.EntityEventType.OnPlayerJoined:
                            try
                            {
                                MethodInfo updateMethod = plugin.GetType( ).GetMethod( "OnPlayerJoined" );
                                if ( updateMethod != null )
                                {
                                    //FIXME - Temporary hack to pass along the player's steam id
                                    ulong steamId = (ulong)entityEvent.entity;
                                    updateMethod.Invoke( plugin, new object[ ] { steamId } );
                                }
                            }
                            catch ( Exception ex )
                            {
                                ApplicationLog.BaseLog.Error( ex );
                            }
                            break;
                        case EntityEventManager.EntityEventType.OnPlayerLeft:
                            try
                            {
                                MethodInfo updateMethod = plugin.GetType( ).GetMethod( "OnPlayerLeft" );
                                if ( updateMethod != null )
                                {
                                    //FIXME - Temporary hack to pass along the player's steam id
                                    ulong steamId = (ulong)entityEvent.entity;
                                    updateMethod.Invoke( plugin, new object[ ] { steamId } );
                                }
                            }
                            catch ( Exception ex )
                            {
                                ApplicationLog.BaseLog.Error( ex );
                            }
                            break;
                        case EntityEventManager.EntityEventType.OnPlayerWorldSent:
                            try
                            {
                                MethodInfo updateMethod = plugin.GetType( ).GetMethod( "OnPlayerWorldSent" );
                                if ( updateMethod != null )
                                {
                                    //FIXME - Temporary hack to pass along the player's steam id
                                    ulong steamId = (ulong)entityEvent.entity;
                                    updateMethod.Invoke( plugin, new object[ ] { steamId } );
                                }
                            }
                            catch ( Exception ex )
                            {
                                ApplicationLog.BaseLog.Error( ex );
                            }
                            break;
                        default:
                            try
                            {
                                string methodName = entityEvent.type.ToString( );
                                MethodInfo updateMethod = plugin.GetType( ).GetMethod( methodName );
                                if ( updateMethod != null )
                                    updateMethod.Invoke( plugin, new[ ] { entityEvent.entity } );
                            }
                            catch ( Exception ex )
                            {
                                ApplicationLog.BaseLog.Error( ex );
                            }
                            break;
                    }
                }

                //Run chat events
                foreach ( ChatManager.ChatEvent chatEvent in chatEvents )
                {
                    try
                    {
                        bool discard = false;
                        HookChatMessage( plugin, plugins, pluginState, chatEvent, out discard );

                        if ( discard )
                            continue;

                        string methodName = chatEvent.Type.ToString( );
                        MethodInfo updateMethod = plugin.GetType( ).GetMethod( methodName );
                        if ( updateMethod != null )
                            updateMethod.Invoke( plugin, new object[ ] { chatEvent } );
                    }
                    catch ( Exception ex )
                    {
                        ApplicationLog.BaseLog.Error( ex );
                    }
                }

                //Run update
                try
                {
                    MethodInfo updateMethod = plugin.GetType( ).GetMethod( "Update" );
                    updateMethod.Invoke( plugin, new object[ ] { } );
                }
                catch ( Exception ex )
                {
                    ApplicationLog.BaseLog.Error( ex );
                }
            }
            catch ( Exception ex )
            {
                ApplicationLog.BaseLog.Error( ex );
            }
        }