All Downloads are FREE. Search and download functionalities are using the official Maven repository.

skadistats.clarity.event.Event Maven / Gradle / Ivy

Go to download

Clarity is an open source replay parser for Dota 2, CSGO, CS2 and Deadlock written in Java.

There is a newer version: 3.1.1
Show newest version
package skadistats.clarity.event;


import skadistats.clarity.processor.runner.Runner;

import java.lang.annotation.Annotation;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;
import java.util.TreeMap;

public class Event {

    private final Runner runner;
    private final Class eventType;
    private final Map>> orderedListeners;

    public Event(Runner runner, Class eventType, Set> listeners) {
        this.runner = runner;
        this.eventType = eventType;
        orderedListeners = new TreeMap<>();
        for (var listener : listeners) {
            var container = orderedListeners.get(listener.order);
            if (container == null) {
                container = new HashSet<>();
                orderedListeners.put(listener.order, container);
            }
            container.add(listener);
        }
    }

    public boolean isListenedTo() {
        return orderedListeners.size() > 0;
    }

    public void raise(Object... args){
        for (var listeners : orderedListeners.values()) {
            for (var listener : listeners) {
                if (listener.isInvokedForArguments(args)) {
                    try {
                        listener.invoke(args);
                    } catch (Throwable throwable) {
                        runner.getExceptionHandler().handleException(eventType, args, throwable);
                    }
                }
            }
        }
    }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy