// Path: BiliLiveLib/src/main/java/charlie/bililivelib/danmaku/event/DanmakuEvent.java
// @Getter
// public class DanmakuEvent extends EventObject {
//     private Kind kind;
//     private Object param;
// 
//     /**
//      * Constructs a prototypical Event.
//      *
//      * @param source The object on which the Event initially occurred.
//      * @throws IllegalArgumentException if source is null.
//      */
//     public DanmakuEvent(Object source) {
//         super(source);
//     }
// 
//     public DanmakuEvent(Object source, Object param, Kind kind) {
//         super(source);
//         this.kind = kind;
//         this.param = param;
//     }
// 
//     public enum Kind {
//         JOINED, ERROR, ERROR_DOWN, NEW_DANMAKU, WATCHER_COUNT,
//         START_STOP, WELCOME_VIP, GIVE_GIFT, GLOBAL_GIFT, GLOBAL_ANNOUNCE
//     }
// }
// 
// Path: BiliLiveLib/src/main/java/charlie/bililivelib/danmaku/event/DanmakuListener.java
// public interface DanmakuListener {
//     void danmakuEvent(@NotNull DanmakuEvent event);
// 
//     void watcherCountEvent(@NotNull DanmakuEvent event);
// 
//     void errorEvent(@NotNull DanmakuEvent event);
// 
//     void startStopEvent(@NotNull DanmakuEvent event);
// 
//     void statusEvent(@NotNull DanmakuEvent event);
// 
//     void welcomeVipEvent(@NotNull DanmakuEvent event);
// 
//     void giveGiftEvent(@NotNull DanmakuEvent event);
// 
//     void globalGiftEvent(@NotNull DanmakuEvent event);
// 
//     void globalAnnounceEvent(@NotNull DanmakuEvent event);
// }


import charlie.bililivelib.danmaku.event.DanmakuEvent;
import charlie.bililivelib.danmaku.event.DanmakuListener;
import org.jetbrains.annotations.NotNull;
import java.util.LinkedList;
import java.util.List;
package charlie.bililivelib.danmaku.dispatch;



/**
 * 用于管理分发器的管理器。
 *
 * @author Charlie Jiang
 * @since rv1
 */
public class DispatchManager {
    private List<Dispatcher> dispatchers = new LinkedList<>();

    /**
     * 注册新的分发器。
     * @param dispatcher 分发器
     */
    public void registerDispatcher(@NotNull Dispatcher dispatcher) {
        dispatchers.add(dispatcher);
    }

    /**
     * 注销指定分发器。
     * @param dispatcher 分发器
     */
    public void unregisterDispatcher(@NotNull Dispatcher dispatcher) {
        dispatchers.remove(dispatcher);
    }

    /**
     * 尝试分发信息。
     * @param listeners 监听器列表
     * @param body 信息体
     * @param source 事件源
     */
    public void dispatch(@NotNull List<DanmakuListener> listeners, @NotNull String body, @NotNull Object source) {
        for (Dispatcher dispatcher : dispatchers) {
            try {
                dispatcher.tryDispatch(listeners, body, source);
            } catch (Exception ex) {
// Path: BiliLiveLib/src/main/java/charlie/bililivelib/danmaku/event/DanmakuEvent.java
// @Getter
// public class DanmakuEvent extends EventObject {
//     private Kind kind;
//     private Object param;
// 
//     /**
//      * Constructs a prototypical Event.
//      *
//      * @param source The object on which the Event initially occurred.
//      * @throws IllegalArgumentException if source is null.
//      */
//     public DanmakuEvent(Object source) {
//         super(source);
//     }
// 
//     public DanmakuEvent(Object source, Object param, Kind kind) {
//         super(source);
//         this.kind = kind;
//         this.param = param;
//     }
// 
//     public enum Kind {
//         JOINED, ERROR, ERROR_DOWN, NEW_DANMAKU, WATCHER_COUNT,
//         START_STOP, WELCOME_VIP, GIVE_GIFT, GLOBAL_GIFT, GLOBAL_ANNOUNCE
//     }
// }
// 
// Path: BiliLiveLib/src/main/java/charlie/bililivelib/danmaku/event/DanmakuListener.java
// public interface DanmakuListener {
//     void danmakuEvent(@NotNull DanmakuEvent event);
// 
//     void watcherCountEvent(@NotNull DanmakuEvent event);
// 
//     void errorEvent(@NotNull DanmakuEvent event);
// 
//     void startStopEvent(@NotNull DanmakuEvent event);
// 
//     void statusEvent(@NotNull DanmakuEvent event);
// 
//     void welcomeVipEvent(@NotNull DanmakuEvent event);
// 
//     void giveGiftEvent(@NotNull DanmakuEvent event);
// 
//     void globalGiftEvent(@NotNull DanmakuEvent event);
// 
//     void globalAnnounceEvent(@NotNull DanmakuEvent event);
// }


// Path: BiliLiveLib/src/main/java/charlie/bililivelib/danmaku/dispatch/DispatchManager.java
import charlie.bililivelib.danmaku.event.DanmakuEvent;
import charlie.bililivelib.danmaku.event.DanmakuListener;
import org.jetbrains.annotations.NotNull;
import java.util.LinkedList;
import java.util.List;

package charlie.bililivelib.danmaku.dispatch;



/**
 * 用于管理分发器的管理器。
 *
 * @author Charlie Jiang
 * @since rv1
 */
public class DispatchManager {
    private List<Dispatcher> dispatchers = new LinkedList<>();

    /**
     * 注册新的分发器。
     * @param dispatcher 分发器
     */
    public void registerDispatcher(@NotNull Dispatcher dispatcher) {
        dispatchers.add(dispatcher);
    }

    /**
     * 注销指定分发器。
     * @param dispatcher 分发器
     */
    public void unregisterDispatcher(@NotNull Dispatcher dispatcher) {
        dispatchers.remove(dispatcher);
    }

    /**
     * 尝试分发信息。
     * @param listeners 监听器列表
     * @param body 信息体
     * @param source 事件源
     */
    public void dispatch(@NotNull List<DanmakuListener> listeners, @NotNull String body, @NotNull Object source) {
        for (Dispatcher dispatcher : dispatchers) {
            try {
                dispatcher.tryDispatch(listeners, body, source);
            } catch (Exception ex) {
                DanmakuEvent event = new DanmakuEvent(dispatcher, ex, DanmakuEvent.Kind.ERROR);