package io.github.deathcap.bukkit2sponge.event;

import io.github.deathcap.bukkit2sponge.Bukkit2Sponge;
import org.spongepowered.api.event.Cancellable;
import org.spongepowered.api.event.Event;

import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;

/**
 * Container for a single object listening for some event.
 */
public final class EventRegistration {

    private final Object object;
    private final Method method;
    private final boolean ignoreCancelled;
    private final Class<?> clazz;

    public EventRegistration(Object object, Method method, boolean ignoreCancelled) {
        this.object = object;
        this.method = method;
        this.ignoreCancelled = ignoreCancelled;
        clazz = method.getParameterTypes()[0];
    }

    public Object getObject() {
        return object;
    }

    public void call(Event event) {
        if (ignoreCancelled && (event instanceof Cancellable) && ((Cancellable) event).isCancelled()) {
            return;
        }

        if (clazz.isAssignableFrom(event.getClass())) {
            try {
                method.invoke(object, event);
            } catch (InvocationTargetException e) {
                Bukkit2Sponge.instance.getLogger().warning("Event error" + e.getTargetException());
            } catch (IllegalAccessException e) {
                Bukkit2Sponge.instance.getLogger().warning("Event error" + e);
            }
        }
    }
}

@@ -272,16 +272,48 @@
 .Method;
+%0Aimport java.util.logging.Level;
 %0A%0A/**%0A *
@@ -1257,32 +1257,43 @@
 getLogger().
-warning(
+log(Level.WARNING, 
 %22Event error
@@ -1293,18 +1293,17 @@
 t error%22
- +
+,
  e.getTa
@@ -1424,16 +1424,27 @@
 r().
-warning(
+log(Level.WARNING, 
 %22Eve
@@ -1456,10 +1456,9 @@
 ror%22
- +
+,
  e);

Fix logging exception stack trace in EventRegistration