/*
 * Trident - A Multithreaded Server Alternative
 * Copyright 2017 The TridentSDK Team
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *    http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package net.tridentsdk.event;

import javax.annotation.concurrent.ThreadSafe;
import java.util.function.Consumer;

/**
 * An event controller manages and handles dispatched
 * events and their corresponding listeners
 *
 * @author TridentSDK
 * @since 0.5-alpha
 */
@ThreadSafe
public interface EventController {
    /**
     * Registers the given listener object to receive
     * events dispatched by the controller.
     *
     * <p>This method should be default accept duplicates.
     * Events being fired twice should be checked to ensure
     * that they were not already registered.</p>
     *
     * @param listener the listener to register
     */
    void register(Listener listener);

    /**
     * Removes the given listener from being handling
     * events dispatched by the event controller.
     *
     * @param listener the listener to remove
     */
    void unregister(Class<? extends Listener> listener);

    /**
     * Dispatches the event to the event listener/handlers
     * that are registered under the event controller.
     *
     * <p>This method passes events to their respective
     * listeners without responding to them.</p>
     *
     * @param event the event to dispatch
     * @param <T> the event type
     */
    <T extends Event> void dispatch(T event);

    /**
     * Dispatches the event to the event listener/handlers
     * that are registered under the event controller.
     *
     * <p>This method dispatches events to their listeners
     * and processes the event when done in the plugin
     * thread.</p>
     *
     * @param event the event to dispatch
     * @param callback the callback to execute when the
     * controller finishes processing all listeners
     * @param <T> the event type
     */
    <T extends Event> void dispatch(T event, Consumer<T> callback);
}
@@ -674,16 +674,51 @@
 event;%0A%0A
+import net.tridentsdk.doc.Policy;%0A%0A
 import j
@@ -744,16 +744,19 @@
 current.
+Not
 ThreadSa
@@ -948,16 +948,19 @@
 ha%0A */%0A@
+Not
 ThreadSa
@@ -1733,32 +1733,116 @@
 troller.%0A     *%0A
+     * %3Cp%3EThis method must always be called on the plugin%0A     * thread.%3C/p%3E%0A     *%0A
      * %3Cp%3EThis m
@@ -2012,32 +2012,69 @@
 nt type%0A     */%0A
+    @Policy(%22call on plugin thread%22)%0A
     %3CT extends E

Remove possible livelock in EventController, closes TridentSDK/Trident#83