From c79aa54e7168ded846398c82508d5bc75352adbf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=9D=D0=B8=D0=BA=D0=B8=D1=82=D0=B0=20=D0=9A=D1=83=D0=BB?= =?UTF-8?q?=D0=B8=D0=BA=D0=BE=D0=B2?= Date: Mon, 16 Mar 2020 19:33:31 +0300 Subject: [PATCH] Add listener to CrashUtils --- .../dimdev/vanillafix/crashes/CrashUtils.java | 21 ++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/src/main/java/org/dimdev/vanillafix/crashes/CrashUtils.java b/src/main/java/org/dimdev/vanillafix/crashes/CrashUtils.java index da6d203..4f969e5 100644 --- a/src/main/java/org/dimdev/vanillafix/crashes/CrashUtils.java +++ b/src/main/java/org/dimdev/vanillafix/crashes/CrashUtils.java @@ -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 listeners = new ArrayList<>(); public static void crash(CrashReport report) { throw new ReportedException(report); @@ -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()); } } @@ -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()); } @@ -66,4 +77,12 @@ private static boolean isClient() { return false; } } + + public static void addListener(CrashListener crashListener) { + listeners.add(crashListener); + } + + public interface CrashListener { + void onReport(CrashReport report); + } }