Search in sources :

Example 1 with AbstractEvent

use of com.laytonsmith.core.events.AbstractEvent in project CommandHelper by EngineHub.

the class ExtensionTracker method registerEvent.

public void registerEvent(Event e) {
    if (e instanceof AbstractEvent) {
        AbstractEvent ae = (AbstractEvent) e;
        // Get the mixin for this server, and add it to e
        Class mixinClass = StaticLayer.GetServerEventMixin();
        try {
            Constructor mixinConstructor = mixinClass.getConstructor(AbstractEvent.class);
            EventMixinInterface mixin = (EventMixinInterface) mixinConstructor.newInstance(e);
            ae.setAbstractEventMixin(mixin);
        } catch (Exception ex) {
            // This is a serious problem, and it should kill the plugin, for fast failure detection.
            throw new Error("Could not properly instantiate the mixin class. " + "The constructor with the signature \"public " + mixinClass.getSimpleName() + "(AbstractEvent e)\" is missing" + " from " + mixinClass.getName());
        }
    }
    // Finally, add it to the list, and hook it.
    if (!events.containsKey(e.driver())) {
        events.put(e.driver(), new TreeSet<Event>());
    }
    events.get(e.driver()).add(e);
}
Also used : Constructor(java.lang.reflect.Constructor) EventMixinInterface(com.laytonsmith.core.events.EventMixinInterface) Event(com.laytonsmith.core.events.Event) AbstractEvent(com.laytonsmith.core.events.AbstractEvent) AbstractEvent(com.laytonsmith.core.events.AbstractEvent)

Aggregations

AbstractEvent (com.laytonsmith.core.events.AbstractEvent)1 Event (com.laytonsmith.core.events.Event)1 EventMixinInterface (com.laytonsmith.core.events.EventMixinInterface)1 Constructor (java.lang.reflect.Constructor)1