skadistats.clarity.event.Event Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of clarity Show documentation
Show all versions of clarity Show documentation
Clarity is an open source replay parser for Dota 2, CSGO, CS2 and Deadlock written in Java.
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);
}
}
}
}
}
}