Add event logging

This commit is contained in:
JeremyStar™ 2024-06-11 16:35:01 +02:00
parent 00268e4307
commit acbfd6b189
Signed by: JeremyStarTM
GPG key ID: E366BAEF67E4704D

View file

@ -21,6 +21,8 @@ package de.staropensource.sosengine.base.classes.helpers;
import de.staropensource.sosengine.base.annotations.EventListener; import de.staropensource.sosengine.base.annotations.EventListener;
import de.staropensource.sosengine.base.classes.Event; import de.staropensource.sosengine.base.classes.Event;
import de.staropensource.sosengine.base.logging.Logger;
import de.staropensource.sosengine.base.types.LogIssuer;
import lombok.Getter; import lombok.Getter;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
import org.reflections.Reflections; import org.reflections.Reflections;
@ -45,6 +47,16 @@ public class EventHelper {
*/ */
public EventHelper() {} public EventHelper() {}
/**
* Logs the event call.
*
* @param clazz event class
* @since 1-alpha0
*/
@NotNull
public static void logCall(Class<? extends Event> clazz) {
Logger.diag(new LogIssuer(clazz), "Event " + clazz.getName() + " called");
}
/** /**
* Returns all annotated methods. * Returns all annotated methods.
@ -81,6 +93,8 @@ public class EventHelper {
* @since 1-alpha0 * @since 1-alpha0
*/ */
public static void invokeAnnotatedMethods(Class<? extends Event> clazz) { public static void invokeAnnotatedMethods(Class<? extends Event> clazz) {
logCall(clazz);
for (Method method : getAnnotatedMethods(clazz)) { for (Method method : getAnnotatedMethods(clazz)) {
try { try {
method.invoke(null); method.invoke(null);