public void AddEventHandler(Plugin plugin, Type eventType, IEventHandler handler, Priority priority = Priority.Normal)
        {
            plugin.Debug(string.Format("Adding event handler from: {0} type: {1} priority: {2} handler: {3}", plugin.Details.name, eventType, priority, handler.GetType()));
            EventHandlerWrapper wrapper = new EventHandlerWrapper(plugin, priority, handler);

            // If the plugin is not enabled
            if (PluginManager.Manager.GetEnabledPlugin(plugin.Details.id) == null)
            {
                if (!snapshots.ContainsKey(plugin))
                {
                    snapshots.Add(plugin, new Snapshot());
                }
                snapshots[plugin].Entries.Add(new Snapshot.SnapshotEntry(eventType, wrapper));
            }

            AddEventMeta(eventType, wrapper, handler);
        }
 private void AddEventMeta(Type eventType, EventHandlerWrapper wrapper, IEventHandler handler)
 {
     if (!event_meta.ContainsKey(eventType))
     {
         event_meta.Add(eventType, new List <EventHandlerWrapper>
         {
             wrapper
         });
     }
     else
     {
         List <EventHandlerWrapper> meta = event_meta[eventType];
         meta.Add(wrapper);
         // Doing this stuff on register instead of when the event is called for events that trigger lots (OnUpdate etc)
         meta.Sort(priorityCompare);
         meta.Reverse();
     }
 }
Ejemplo n.º 3
0
        public void AddEventHandler(Plugin plugin, Type eventType, IEventHandler handler, Priority priority = Priority.Normal)
        {
            plugin.Debug(string.Format("Adding event handler from: {0} type: {1} priority: {2} handler: {3}", plugin.Details.name, eventType, priority, handler.GetType()));
            EventHandlerWrapper wrapper = new EventHandlerWrapper(plugin, priority, handler);

            if (!event_meta.ContainsKey(eventType))
            {
                event_meta.Add(eventType, new List <EventHandlerWrapper>());
                event_meta[eventType].Add(wrapper);
                event_handlers.Add(eventType, new List <IEventHandler>());
                event_handlers[eventType].Add(handler);
            }
            else
            {
                List <EventHandlerWrapper> meta = event_meta[eventType];
                meta.Add(wrapper);
                // Doing this stuff on register instead of when the event is called for events that trigger lots (OnUpdate etc)
                meta.Sort(priorityCompare);
                meta.Reverse();
                RebuildHandlerList(eventType);
            }
        }
 public SnapshotEntry(Type type, EventHandlerWrapper wrapper)
 {
     Type    = type;
     Wrapper = wrapper;
 }