package io.github.thatsmusic99.headsplus.util.events;

import io.github.thatsmusic99.headsplus.util.DebugFileCreator;
import org.bukkit.event.Event;
import org.bukkit.event.EventException;
import org.bukkit.event.Listener;
import org.bukkit.plugin.EventExecutor;
import org.jetbrains.annotations.NotNull;

public class HeadsPlusEventExecutor implements EventExecutor {

    //
    private Class<? extends Event> eventClass;
    private HeadsPlusTimingsHandler handler;

    public HeadsPlusEventExecutor(Class<? extends Event> clazz, String name) {
        eventClass = clazz;
        handler = new HeadsPlusTimingsHandler(name);
    }

    @Override
    public void execute(@NotNull Listener listener, @NotNull Event event) throws EventException {
        if (listener instanceof HeadsPlusListener) {
            // Make sure it's a class we're listening for
            if (eventClass.isAssignableFrom(event.getClass())) {
                HeadsPlusListener<Event> hpListener = (HeadsPlusListener<Event>) listener;
                try {
                    handler.start();
                    hpListener.onEvent(event);
                    handler.finish();
                } catch (Exception ex) {
                    HeadsPlusException ex1 = new HeadsPlusException(ex, hpListener.getData());
                    DebugFileCreator.createReport(ex1);
                    handler.finish();
                }
            }
        }
    }
}

@@ -48,16 +48,67 @@
 vents;%0A%0A
+import io.github.thatsmusic99.headsplus.HeadsPlus;%0A
 import i
@@ -158,24 +158,24 @@
 ileCreator;%0A
-
 import org.b
@@ -350,16 +350,50 @@
 tNull;%0A%0A
+import java.util.logging.Logger;%0A%0A
 public c
@@ -1275,24 +1275,66 @@
 ption ex) %7B%0A
+                    ex.printStackTrace();%0A
             
@@ -1435,16 +1435,27 @@
         
+ String s =
  DebugFi
@@ -1513,32 +1513,645 @@
 ndler.finish();%0A
+                    Logger log = HeadsPlus.getInstance().getLogger();%0A                    log.severe(%22HeadsPlus has failed to execute this task. An error report has been made in /plugins/HeadsPlus/debug%22);%0A                    log.severe(%22Report name: %22 + s);%0A                    log.severe(%22Please submit this report to the developer at one of the following links:%22);%0A                    log.severe(%22https://github.com/Thatsmusic99/HeadsPlus/issues%22);%0A                    log.severe(%22https://discord.gg/nbT7wC2%22);%0A                    log.severe(%22https://www.spigotmc.org/threads/headsplus-1-8-x-1-12-x.237088/%22);%0A
                 

Create a debug report when events fail