Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 20 additions & 1 deletion src/main/java/org/dimdev/vanillafix/crashes/CrashUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,13 @@

import java.io.File;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

public final class CrashUtils {
private static final Logger log = LogManager.getLogger("VF");
private static final List<CrashListener> listeners = new ArrayList<>();

public static void crash(CrashReport report) {
throw new ReportedException(report);
Expand All @@ -23,7 +26,7 @@ public static void warn(CrashReport report) {
// Don't inline showWarningScreen, that will cause Java to load the GuiScreen
// class on servers, because of the lambda!
((IPatchedMinecraft) Minecraft.getMinecraft()).showWarningScreen(report);
} else {
} else {
log.fatal(report.getDescription(), report.getCrashCause());
}
}
Expand Down Expand Up @@ -55,6 +58,14 @@ public static void outputReport(CrashReport report) {
log.fatal("Failed saving report", e);
}

for (int i = 0; i < listeners.size(); i++) {
try {
listeners.get(i).onReport(report);
} catch (Throwable e) {
log.fatal("Failed report crash to listener", e);
}
}

log.fatal("Minecraft ran into a problem! " + (report.getFile() != null ? "Report saved to: " + report.getFile() : "Crash report could not be saved.")
+ "\n" + report.getCompleteReport());
}
Expand All @@ -66,4 +77,12 @@ private static boolean isClient() {
return false;
}
}

public static void addListener(CrashListener crashListener) {
listeners.add(crashListener);
}

public interface CrashListener {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

add a @FunctionalInterface annotation

void onReport(CrashReport report);
}
}