From b7fab1a5aabd2da37c26783b086f6e3580c08c49 Mon Sep 17 00:00:00 2001 From: Jason Mitchell Date: Sat, 28 Jan 2023 20:05:27 -0800 Subject: [PATCH] [ci skip] spotlessApply with the new settings --- .../vfyjxf/bettercrashes/BetterCrashes.java | 5 +- .../bettercrashes/BetterCrashesConfig.java | 4 +- .../bettercrashes/mixinplugin/Mixin.java | 9 +-- .../mixinplugin/MixinPlugin.java | 9 +-- .../mixinplugin/TargetedMod.java | 11 ++- .../mixins/minecraft/CrashReportMixin.java | 35 ++++---- .../mixins/minecraft/MinecraftMixin.java | 64 +++++++-------- .../bettercrashes/utils/CrashUtils.java | 19 +++-- .../bettercrashes/utils/GuiCrashScreen.java | 11 +-- .../utils/GuiInitErrorScreen.java | 41 +++++----- .../bettercrashes/utils/GuiProblemScreen.java | 81 ++++++++++--------- .../utils/IPatchedCrashReport.java | 10 ++- .../utils/IPatchedMinecraft.java | 1 + .../bettercrashes/utils/ModIdentifier.java | 21 ++--- .../utils/StacktraceDeobfuscator.java | 29 ++++--- .../bettercrashes/utils/StateManager.java | 8 +- 16 files changed, 191 insertions(+), 167 deletions(-) diff --git a/src/main/java/vfyjxf/bettercrashes/BetterCrashes.java b/src/main/java/vfyjxf/bettercrashes/BetterCrashes.java index 514fa36..248ccc8 100644 --- a/src/main/java/vfyjxf/bettercrashes/BetterCrashes.java +++ b/src/main/java/vfyjxf/bettercrashes/BetterCrashes.java @@ -1,9 +1,10 @@ package vfyjxf.bettercrashes; +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; + import cpw.mods.fml.common.Mod; import cpw.mods.fml.common.event.FMLPreInitializationEvent; -import org.apache.logging.log4j.LogManager; -import org.apache.logging.log4j.Logger; @Mod( modid = BetterCrashes.MODID, diff --git a/src/main/java/vfyjxf/bettercrashes/BetterCrashesConfig.java b/src/main/java/vfyjxf/bettercrashes/BetterCrashesConfig.java index e459bfa..33fba68 100644 --- a/src/main/java/vfyjxf/bettercrashes/BetterCrashesConfig.java +++ b/src/main/java/vfyjxf/bettercrashes/BetterCrashesConfig.java @@ -1,9 +1,11 @@ package vfyjxf.bettercrashes; -import cpw.mods.fml.common.Loader; import java.io.File; + import net.minecraftforge.common.config.Configuration; +import cpw.mods.fml.common.Loader; + public class BetterCrashesConfig { public static Configuration config; diff --git a/src/main/java/vfyjxf/bettercrashes/mixinplugin/Mixin.java b/src/main/java/vfyjxf/bettercrashes/mixinplugin/Mixin.java index b61dcd0..53989a8 100644 --- a/src/main/java/vfyjxf/bettercrashes/mixinplugin/Mixin.java +++ b/src/main/java/vfyjxf/bettercrashes/mixinplugin/Mixin.java @@ -2,10 +2,11 @@ package vfyjxf.bettercrashes.mixinplugin; import static vfyjxf.bettercrashes.mixinplugin.TargetedMod.VANILLA; -import cpw.mods.fml.relauncher.FMLLaunchHandler; import java.util.Arrays; import java.util.List; +import cpw.mods.fml.relauncher.FMLLaunchHandler; + public enum Mixin { // @@ -35,10 +36,8 @@ public enum Mixin { } public boolean shouldLoad(List loadedMods) { - return (side == Side.BOTH - || side == Side.SERVER && FMLLaunchHandler.side().isServer() - || side == Side.CLIENT && FMLLaunchHandler.side().isClient()) - && loadedMods.containsAll(targetedMods); + return (side == Side.BOTH || side == Side.SERVER && FMLLaunchHandler.side().isServer() + || side == Side.CLIENT && FMLLaunchHandler.side().isClient()) && loadedMods.containsAll(targetedMods); } } diff --git a/src/main/java/vfyjxf/bettercrashes/mixinplugin/MixinPlugin.java b/src/main/java/vfyjxf/bettercrashes/mixinplugin/MixinPlugin.java index 8e70429..c5bdac5 100644 --- a/src/main/java/vfyjxf/bettercrashes/mixinplugin/MixinPlugin.java +++ b/src/main/java/vfyjxf/bettercrashes/mixinplugin/MixinPlugin.java @@ -12,12 +12,15 @@ import java.util.Arrays; import java.util.List; import java.util.Set; import java.util.stream.Collectors; + import net.minecraft.launchwrapper.Launch; + import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; import org.spongepowered.asm.mixin.extensibility.IMixinConfigPlugin; import org.spongepowered.asm.mixin.extensibility.IMixinInfo; import org.spongepowered.libraries.org.objectweb.asm.tree.ClassNode; + import ru.timeconqueror.spongemixins.MinecraftURLClassPath; public class MixinPlugin implements IMixinConfigPlugin { @@ -90,11 +93,7 @@ public class MixinPlugin implements IMixinConfigPlugin { public static File findJarOf(final TargetedMod mod) { try { - return walk(MODS_DIRECTORY_PATH) - .filter(mod::isMatchingJar) - .map(Path::toFile) - .findFirst() - .orElse(null); + return walk(MODS_DIRECTORY_PATH).filter(mod::isMatchingJar).map(Path::toFile).findFirst().orElse(null); } catch (IOException e) { e.printStackTrace(); return null; diff --git a/src/main/java/vfyjxf/bettercrashes/mixinplugin/TargetedMod.java b/src/main/java/vfyjxf/bettercrashes/mixinplugin/TargetedMod.java index 3047557..3f146e1 100644 --- a/src/main/java/vfyjxf/bettercrashes/mixinplugin/TargetedMod.java +++ b/src/main/java/vfyjxf/bettercrashes/mixinplugin/TargetedMod.java @@ -1,8 +1,9 @@ package vfyjxf.bettercrashes.mixinplugin; -import com.google.common.io.Files; import java.nio.file.Path; +import com.google.common.io.Files; + public enum TargetedMod { // @@ -38,7 +39,11 @@ public enum TargetedMod { @Override public String toString() { return "TargetedMod{" + "modName='" - + modName + '\'' + ", jarNamePrefixLowercase='" - + jarNamePrefixLowercase + '\'' + '}'; + + modName + + '\'' + + ", jarNamePrefixLowercase='" + + jarNamePrefixLowercase + + '\'' + + '}'; } } diff --git a/src/main/java/vfyjxf/bettercrashes/mixins/minecraft/CrashReportMixin.java b/src/main/java/vfyjxf/bettercrashes/mixins/minecraft/CrashReportMixin.java index 5ad126a..df8882f 100644 --- a/src/main/java/vfyjxf/bettercrashes/mixins/minecraft/CrashReportMixin.java +++ b/src/main/java/vfyjxf/bettercrashes/mixins/minecraft/CrashReportMixin.java @@ -1,12 +1,11 @@ /* - *This file is from - *https://github.com/DimensionalDevelopment/VanillaFix/blob/master/src/main/java/org/dimdev/vanillafix/crashes/mixins/MixinCrashReport.java - *The source file uses the MIT License. + * This file is from + * https://github.com/DimensionalDevelopment/VanillaFix/blob/master/src/main/java/org/dimdev/vanillafix/crashes/mixins/ + * MixinCrashReport.java The source file uses the MIT License. */ package vfyjxf.bettercrashes.mixins.minecraft; -import cpw.mods.fml.common.ModContainer; import java.io.PrintWriter; import java.io.StringWriter; import java.text.SimpleDateFormat; @@ -14,8 +13,10 @@ import java.util.ArrayList; import java.util.Date; import java.util.List; import java.util.Set; + import net.minecraft.crash.CrashReport; import net.minecraft.crash.CrashReportCategory; + import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.exception.ExceptionUtils; import org.spongepowered.asm.mixin.Final; @@ -25,12 +26,15 @@ import org.spongepowered.asm.mixin.Shadow; import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.Inject; import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; + import vfyjxf.bettercrashes.utils.IPatchedCrashReport; import vfyjxf.bettercrashes.utils.ModIdentifier; import vfyjxf.bettercrashes.utils.StacktraceDeobfuscator; +import cpw.mods.fml.common.ModContainer; @Mixin(value = CrashReport.class, priority = 500) public class CrashReportMixin implements IPatchedCrashReport { + @Shadow @Final private CrashReportCategory theReportCategory; @@ -58,6 +62,7 @@ public class CrashReportMixin implements IPatchedCrashReport { public Set getSuspectedMods() { return suspectedMods; } + /** @reason Adds a list of mods which may have caused the crash to the report. */ @Inject(method = "populateEnvironment", at = @At("TAIL")) private void afterPopulateEnvironment(CallbackInfo ci) { @@ -95,20 +100,11 @@ public class CrashReportMixin implements IPatchedCrashReport { public String getCompleteReport() { StringBuilder builder = new StringBuilder(); - builder.append("---- Minecraft Crash Report ----\n") - .append("// ") - .append(getVanillaFixComment()) - .append("\n\n") - .append("Time: ") - .append(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss z").format(new Date())) - .append("\n") - .append("Description: ") - .append(description) - .append("\n\n") - .append(stacktraceToString(cause) - .replace( - "\t", - " ")) // Vanilla's getCauseStackTraceOrString doesn't print causes and suppressed + builder.append("---- Minecraft Crash Report ----\n").append("// ").append(getVanillaFixComment()).append("\n\n") + .append("Time: ").append(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss z").format(new Date())).append("\n") + .append("Description: ").append(description).append("\n\n") + .append(stacktraceToString(cause).replace("\t", " ")) // Vanilla's getCauseStackTraceOrString doesn't + // print causes and suppressed // exceptions .append( "\n\nA detailed walkthrough of the error, its code path and all known details is as follows:\n"); @@ -149,8 +145,7 @@ public class CrashReportMixin implements IPatchedCrashReport { String author = mod.getMetadata().authorList.get(0); return "I blame " + author + "."; } - } catch (Throwable ignored) { - } + } catch (Throwable ignored) {} return getWittyComment(); } diff --git a/src/main/java/vfyjxf/bettercrashes/mixins/minecraft/MinecraftMixin.java b/src/main/java/vfyjxf/bettercrashes/mixins/minecraft/MinecraftMixin.java index 3bcd37e..2ed6450 100644 --- a/src/main/java/vfyjxf/bettercrashes/mixins/minecraft/MinecraftMixin.java +++ b/src/main/java/vfyjxf/bettercrashes/mixins/minecraft/MinecraftMixin.java @@ -1,16 +1,15 @@ /* - *This file is modified based on - *https://github.com/DimensionalDevelopment/VanillaFix/blob/master/src/main/java/org/dimdev/vanillafix/crashes/mixins/client/MixinMinecraft.java - *The source file uses the MIT License. + * This file is modified based on + * https://github.com/DimensionalDevelopment/VanillaFix/blob/master/src/main/java/org/dimdev/vanillafix/crashes/mixins/ + * client/MixinMinecraft.java The source file uses the MIT License. */ package vfyjxf.bettercrashes.mixins.minecraft; -import cpw.mods.fml.client.SplashProgress; -import cpw.mods.fml.common.Loader; import java.io.IOException; import java.util.List; import java.util.Queue; + import net.minecraft.client.Minecraft; import net.minecraft.client.audio.SoundHandler; import net.minecraft.client.gui.*; @@ -29,6 +28,7 @@ import net.minecraft.util.ChatComponentText; import net.minecraft.util.MinecraftError; import net.minecraft.util.ReportedException; import net.minecraft.util.ResourceLocation; + import org.apache.logging.log4j.Logger; import org.lwjgl.LWJGLException; import org.lwjgl.input.Mouse; @@ -38,11 +38,14 @@ import org.spongepowered.asm.mixin.Final; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.Overwrite; import org.spongepowered.asm.mixin.Shadow; + import vfyjxf.bettercrashes.BetterCrashesConfig; import vfyjxf.bettercrashes.utils.CrashUtils; import vfyjxf.bettercrashes.utils.GuiCrashScreen; import vfyjxf.bettercrashes.utils.GuiInitErrorScreen; import vfyjxf.bettercrashes.utils.StateManager; +import cpw.mods.fml.client.SplashProgress; +import cpw.mods.fml.common.Loader; /** * @author Runemoro @@ -201,8 +204,7 @@ public abstract class MinecraftMixin { crashReporter = null; } } - } catch (MinecraftError ignored) { - } finally { + } catch (MinecraftError ignored) {} finally { shutdownMinecraftApplet(); } } @@ -220,7 +222,7 @@ public abstract class MinecraftMixin { // Reset hasCrashed, debugCrashKeyPressTime, and crashIntegratedServerNextTick hasCrashed = false; field_83002_am = -1; - // crashIntegratedServerNextTick = false; + // crashIntegratedServerNextTick = false; // Vanilla does this when switching to main menu but not our custom crash screen // nor the out of memory screen (see https://bugs.mojang.com/browse/MC-128953) @@ -228,25 +230,24 @@ public abstract class MinecraftMixin { ingameGUI.getChatGUI().clearChatMessages(); // Display the crash screen - // runGUILoop(new GuiCrashScreen(report)); + // runGUILoop(new GuiCrashScreen(report)); displayGuiScreen(new GuiCrashScreen(report)); } catch (Throwable t) { // The crash screen has crashed. Report it normally instead. logger.error( - "An uncaught exception occured while displaying the crash screen, making normal report instead", t); + "An uncaught exception occured while displaying the crash screen, making normal report instead", + t); displayCrashReport(report); System.exit(report.getFile() != null ? -1 : -2); } } private void addInfoToCrash(CrashReport crashReport) { - crashReport - .getCategory() + crashReport.getCategory() .addCrashSectionCallable("Client Crashes Since Restart", () -> String.valueOf(clientCrashCount)); - crashReport - .getCategory() - .addCrashSectionCallable( - "Integrated Server Crashes Since Restart", () -> String.valueOf(serverCrashCount)); + crashReport.getCategory().addCrashSectionCallable( + "Integrated Server Crashes Since Restart", + () -> String.valueOf(serverCrashCount)); } /** @@ -261,14 +262,12 @@ public abstract class MinecraftMixin { originalMemoryReserveSize = memoryReserve.length; memoryReserve = new byte[0]; } - } catch (Throwable ignored) { - } + } catch (Throwable ignored) {} StateManager.resetStates(); if (getNetHandler() != null) { - getNetHandler() - .getNetworkManager() + getNetHandler().getNetworkManager() .closeChannel(new ChatComponentText("[BetterCrashes] Client crashed")); } loadWorld(null); @@ -280,16 +279,14 @@ public abstract class MinecraftMixin { if (originalMemoryReserveSize != -1) { try { memoryReserve = new byte[originalMemoryReserveSize]; - } catch (Throwable ignored) { - } + } catch (Throwable ignored) {} } System.gc(); } catch (Throwable t) { logger.error("Failed to reset state after a crash", t); try { StateManager.resetStates(); - } catch (Throwable ignored) { - } + } catch (Throwable ignored) {} } } @@ -311,7 +308,10 @@ public abstract class MinecraftMixin { refreshResources(); // TODO: Why is this necessary? fontRenderer = new FontRenderer( - gameSettings, new ResourceLocation("textures/font/ascii.png"), renderEngine, false); + gameSettings, + new ResourceLocation("textures/font/ascii.png"), + renderEngine, + false); mcResourceManager.registerReloadListener(fontRenderer); mcSoundHandler = new SoundHandler(mcResourceManager, gameSettings); @@ -319,10 +319,9 @@ public abstract class MinecraftMixin { running = true; try { - //noinspection deprecation + // noinspection deprecation SplashProgress.finish(); // Disable the forge splash progress screen - } catch (Throwable ignored) { - } + } catch (Throwable ignored) {} runGUILoop(new GuiInitErrorScreen(report)); } catch (Throwable t) { logger.error( @@ -339,8 +338,7 @@ public abstract class MinecraftMixin { */ private void runGUILoop(GuiScreen screen) throws IOException { displayGuiScreen(screen); - while (running - && currentScreen != null + while (running && currentScreen != null && !(currentScreen instanceof GuiMainMenu) && !(Loader.isModLoaded("custommainmenu"))) { if (Display.isCreated() && Display.isCloseRequested()) { @@ -358,8 +356,10 @@ public abstract class MinecraftMixin { GL11.glViewport(0, 0, displayWidth, displayHeight); // EntityRenderer.setupOverlayRendering - ScaledResolution scaledResolution = - new ScaledResolution((Minecraft) (Object) this, displayWidth, displayHeight); + ScaledResolution scaledResolution = new ScaledResolution( + (Minecraft) (Object) this, + displayWidth, + displayHeight); GL11.glClear(256); GL11.glMatrixMode(5889); GL11.glLoadIdentity(); diff --git a/src/main/java/vfyjxf/bettercrashes/utils/CrashUtils.java b/src/main/java/vfyjxf/bettercrashes/utils/CrashUtils.java index 7038834..92d898b 100644 --- a/src/main/java/vfyjxf/bettercrashes/utils/CrashUtils.java +++ b/src/main/java/vfyjxf/bettercrashes/utils/CrashUtils.java @@ -1,7 +1,7 @@ /* - *This file is modified based on - *https://github.com/DimensionalDevelopment/VanillaFix/blob/99cb47cc05b4790e8ef02bbcac932b21dafa107f/src/main/java/org/dimdev/vanillafix/crashes/CrashUtils.java - *The source file uses the MIT License. + * This file is modified based on + * https://github.com/DimensionalDevelopment/VanillaFix/blob/99cb47cc05b4790e8ef02bbcac932b21dafa107f/src/main/java/org/ + * dimdev/vanillafix/crashes/CrashUtils.java The source file uses the MIT License. */ package vfyjxf.bettercrashes.utils; @@ -13,8 +13,10 @@ import java.net.URI; import java.net.URISyntaxException; import java.text.SimpleDateFormat; import java.util.Date; + import net.minecraft.client.Minecraft; import net.minecraft.crash.CrashReport; + import vfyjxf.bettercrashes.BetterCrashes; /** @@ -34,8 +36,7 @@ public class CrashUtils { reportName += Minecraft.getMinecraft().func_152345_ab() ? "-client" : "-server"; reportName += ".txt"; - File reportsDir = isClient() - ? new File(Minecraft.getMinecraft().mcDataDir, "crash-reports") + File reportsDir = isClient() ? new File(Minecraft.getMinecraft().mcDataDir, "crash-reports") : new File("crash-reports"); File reportFile = new File(reportsDir, reportName); @@ -45,11 +46,9 @@ public class CrashUtils { BetterCrashes.logger.fatal("Failed saving report", e); } - BetterCrashes.logger.fatal("Minecraft ran into a problem! " - + (report.getFile() != null - ? "Report saved to: " + report.getFile() - : "Crash report could not be saved.") - + "\n" + report.getCompleteReport()); + BetterCrashes.logger.fatal( + "Minecraft ran into a problem! " + (report.getFile() != null ? "Report saved to: " + report.getFile() + : "Crash report could not be saved.") + "\n" + report.getCompleteReport()); } /** diff --git a/src/main/java/vfyjxf/bettercrashes/utils/GuiCrashScreen.java b/src/main/java/vfyjxf/bettercrashes/utils/GuiCrashScreen.java index e4f1df9..459b066 100644 --- a/src/main/java/vfyjxf/bettercrashes/utils/GuiCrashScreen.java +++ b/src/main/java/vfyjxf/bettercrashes/utils/GuiCrashScreen.java @@ -1,19 +1,20 @@ /* - *This file is modified based on - *https://github.com/DimensionalDevelopment/VanillaFix/blob/99cb47cc05b4790e8ef02bbcac932b21dafa107f/src/main/java/org/dimdev/vanillafix/crashes/GuiCrashScreen.java - *The source file uses the MIT License. + * This file is modified based on + * https://github.com/DimensionalDevelopment/VanillaFix/blob/99cb47cc05b4790e8ef02bbcac932b21dafa107f/src/main/java/org/ + * dimdev/vanillafix/crashes/GuiCrashScreen.java The source file uses the MIT License. */ package vfyjxf.bettercrashes.utils; -import cpw.mods.fml.relauncher.Side; -import cpw.mods.fml.relauncher.SideOnly; import net.minecraft.client.gui.GuiButton; import net.minecraft.client.gui.GuiMainMenu; import net.minecraft.client.gui.GuiOptionButton; import net.minecraft.client.resources.I18n; import net.minecraft.crash.CrashReport; +import cpw.mods.fml.relauncher.Side; +import cpw.mods.fml.relauncher.SideOnly; + @SideOnly(Side.CLIENT) public class GuiCrashScreen extends GuiProblemScreen { diff --git a/src/main/java/vfyjxf/bettercrashes/utils/GuiInitErrorScreen.java b/src/main/java/vfyjxf/bettercrashes/utils/GuiInitErrorScreen.java index 27ba6ce..746f9d0 100644 --- a/src/main/java/vfyjxf/bettercrashes/utils/GuiInitErrorScreen.java +++ b/src/main/java/vfyjxf/bettercrashes/utils/GuiInitErrorScreen.java @@ -1,17 +1,18 @@ /* - *This file is modified based on - *https://github.com/DimensionalDevelopment/VanillaFix/blob/99cb47cc05b4790e8ef02bbcac932b21dafa107f/src/main/java/org/dimdev/vanillafix/crashes/GuiInitErrorScreen.java - *The source file uses the MIT License. + * This file is modified based on + * https://github.com/DimensionalDevelopment/VanillaFix/blob/99cb47cc05b4790e8ef02bbcac932b21dafa107f/src/main/java/org/ + * dimdev/vanillafix/crashes/GuiInitErrorScreen.java The source file uses the MIT License. */ package vfyjxf.bettercrashes.utils; -import cpw.mods.fml.relauncher.Side; -import cpw.mods.fml.relauncher.SideOnly; import net.minecraft.client.gui.GuiButton; import net.minecraft.client.resources.I18n; import net.minecraft.crash.CrashReport; +import cpw.mods.fml.relauncher.Side; +import cpw.mods.fml.relauncher.SideOnly; + @SideOnly(Side.CLIENT) public class GuiInitErrorScreen extends GuiProblemScreen { @@ -23,20 +24,22 @@ public class GuiInitErrorScreen extends GuiProblemScreen { public void initGui() { mc.setIngameNotInFocus(); buttonList.clear(); - buttonList.add(new GuiButton( - 1, - width / 2 - 155, - height / 4 + 120 + 12, - 150, - 20, - I18n.format("bettercrashes.gui.common.openCrashReport"))); - buttonList.add(new GuiButton( - 2, - width / 2 - 155 + 160, - height / 4 + 120 + 12, - 150, - 20, - I18n.format("bettercrashes.gui.common.uploadReportAndCopyLink"))); + buttonList.add( + new GuiButton( + 1, + width / 2 - 155, + height / 4 + 120 + 12, + 150, + 20, + I18n.format("bettercrashes.gui.common.openCrashReport"))); + buttonList.add( + new GuiButton( + 2, + width / 2 - 155 + 160, + height / 4 + 120 + 12, + 150, + 20, + I18n.format("bettercrashes.gui.common.uploadReportAndCopyLink"))); } @Override diff --git a/src/main/java/vfyjxf/bettercrashes/utils/GuiProblemScreen.java b/src/main/java/vfyjxf/bettercrashes/utils/GuiProblemScreen.java index 079ce14..301a444 100644 --- a/src/main/java/vfyjxf/bettercrashes/utils/GuiProblemScreen.java +++ b/src/main/java/vfyjxf/bettercrashes/utils/GuiProblemScreen.java @@ -1,18 +1,13 @@ /* - *This file is modified based on - *https://github.com/DimensionalDevelopment/VanillaFix/blob/99cb47cc05b4790e8ef02bbcac932b21dafa107f/src/main/java/org/dimdev/vanillafix/crashes/GuiProblemScreen.java - *The source file uses the MIT License. + * This file is modified based on + * https://github.com/DimensionalDevelopment/VanillaFix/blob/99cb47cc05b4790e8ef02bbcac932b21dafa107f/src/main/java/org/ + * dimdev/vanillafix/crashes/GuiProblemScreen.java The source file uses the MIT License. */ package vfyjxf.bettercrashes.utils; import static vfyjxf.bettercrashes.BetterCrashesConfig.isGTNH; -import cpw.mods.fml.client.FMLClientHandler; -import cpw.mods.fml.common.Loader; -import cpw.mods.fml.common.ModContainer; -import cpw.mods.fml.relauncher.Side; -import cpw.mods.fml.relauncher.SideOnly; import java.io.IOException; import java.lang.reflect.Field; import java.util.ArrayList; @@ -20,14 +15,22 @@ import java.util.Arrays; import java.util.Collections; import java.util.List; import java.util.Set; + import net.minecraft.client.Minecraft; import net.minecraft.client.gui.FontRenderer; import net.minecraft.client.gui.GuiButton; import net.minecraft.client.gui.GuiScreen; import net.minecraft.client.resources.I18n; import net.minecraft.crash.CrashReport; + import org.apache.commons.lang3.StringUtils; + import vfyjxf.bettercrashes.BetterCrashesConfig; +import cpw.mods.fml.client.FMLClientHandler; +import cpw.mods.fml.common.Loader; +import cpw.mods.fml.common.ModContainer; +import cpw.mods.fml.relauncher.Side; +import cpw.mods.fml.relauncher.SideOnly; @SideOnly(Side.CLIENT) public abstract class GuiProblemScreen extends GuiScreen { @@ -52,8 +55,7 @@ public abstract class GuiProblemScreen extends GuiScreen { private String modListString; protected static final List UNSUPPORTED_MOD_IDS = Arrays.asList(); protected List detectedUnsupportedModNames; - private static final String GTNH_ISSUE_TRACKER = - "https://github.com/GTNewHorizons/GT-New-Horizons-Modpack/issues?q=label%3A%22Type%3A+Crash%22"; + private static final String GTNH_ISSUE_TRACKER = "https://github.com/GTNewHorizons/GT-New-Horizons-Modpack/issues?q=label%3A%22Type%3A+Crash%22"; public GuiProblemScreen(CrashReport report) { this.report = report; @@ -63,28 +65,31 @@ public abstract class GuiProblemScreen extends GuiScreen { public void initGui() { mc.setIngameNotInFocus(); buttonList.clear(); - buttonList.add(new GuiButton( - 1, - width / 2 - 50, - height / 4 + 120 + 12, - 110, - 20, - I18n.format("bettercrashes.gui.common.openCrashReport"))); - buttonList.add(new GuiButton( - 2, - width / 2 - 50 + 115, - height / 4 + 120 + 12, - 110, - 20, - I18n.format("bettercrashes.gui.common.uploadReportAndCopyLink"))); + buttonList.add( + new GuiButton( + 1, + width / 2 - 50, + height / 4 + 120 + 12, + 110, + 20, + I18n.format("bettercrashes.gui.common.openCrashReport"))); + buttonList.add( + new GuiButton( + 2, + width / 2 - 50 + 115, + height / 4 + 120 + 12, + 110, + 20, + I18n.format("bettercrashes.gui.common.uploadReportAndCopyLink"))); if (BetterCrashesConfig.isGTNH) { - buttonList.add(new GuiButton( - 3, - width / 2 - 50 - 15, - height / 4 + 120 + 12 + 25, - 140, - 20, - I18n.format("bettercrashes.gui.common.gtnhIssueTracker"))); + buttonList.add( + new GuiButton( + 3, + width / 2 - 50 - 15, + height / 4 + 120 + 12 + 25, + 140, + 20, + I18n.format("bettercrashes.gui.common.gtnhIssueTracker"))); } } @@ -104,11 +109,12 @@ public abstract class GuiProblemScreen extends GuiScreen { button.enabled = false; button.displayString = I18n.format("bettercrashes.gui.common.uploading"); Thread thread = new Thread("BetterCrashes report uploading") { + @Override public void run() { try { - hasteLink = CrashReportUpload.uploadToUbuntuPastebin( - "https://paste.ubuntu.com", report.getCompleteReport()); + hasteLink = CrashReportUpload + .uploadToUbuntuPastebin("https://paste.ubuntu.com", report.getCompleteReport()); synchronized (button) { button.enabled = true; button.displayString = I18n.format("bettercrashes.gui.common.success"); @@ -175,8 +181,7 @@ public abstract class GuiProblemScreen extends GuiScreen { drawCenteredString( fontRendererObj, - report.getFile() != null - ? "\u00A7n" + report.getFile().getName() + report.getFile() != null ? "\u00A7n" + report.getFile().getName() : I18n.format("bettercrashes.gui.common.reportSaveFailed"), width / 2, y += 11, @@ -198,7 +203,11 @@ public abstract class GuiProblemScreen extends GuiScreen { if (hasUnsupportedMods) { drawString(fontRendererObj, I18n.format("bettercrashes.gui.common.paragraph4_gtnh"), x, y += 10, textColor); drawCenteredString( - fontRendererObj, StringUtils.join(detectedUnsupportedModNames, ", "), width / 2, y += 11, 0xE0E000); + fontRendererObj, + StringUtils.join(detectedUnsupportedModNames, ", "), + width / 2, + y += 11, + 0xE0E000); drawString(fontRendererObj, I18n.format("bettercrashes.gui.common.paragraph5_gtnh"), x, y += 12, textColor); } diff --git a/src/main/java/vfyjxf/bettercrashes/utils/IPatchedCrashReport.java b/src/main/java/vfyjxf/bettercrashes/utils/IPatchedCrashReport.java index bdd939b..95b94b0 100644 --- a/src/main/java/vfyjxf/bettercrashes/utils/IPatchedCrashReport.java +++ b/src/main/java/vfyjxf/bettercrashes/utils/IPatchedCrashReport.java @@ -1,17 +1,19 @@ /* - *This file is from - *https://github.com/DimensionalDevelopment/VanillaFix/blob/99cb47cc05b4790e8ef02bbcac932b21dafa107f/src/main/java/org/dimdev/vanillafix/crashes/IPatchedCrashReport.java - *The source file uses the MIT License. + * This file is from + * https://github.com/DimensionalDevelopment/VanillaFix/blob/99cb47cc05b4790e8ef02bbcac932b21dafa107f/src/main/java/org/ + * dimdev/vanillafix/crashes/IPatchedCrashReport.java The source file uses the MIT License. */ package vfyjxf.bettercrashes.utils; -import cpw.mods.fml.common.ModContainer; import java.util.Set; +import cpw.mods.fml.common.ModContainer; + /** * @author Runemoro */ public interface IPatchedCrashReport { + Set getSuspectedMods(); } diff --git a/src/main/java/vfyjxf/bettercrashes/utils/IPatchedMinecraft.java b/src/main/java/vfyjxf/bettercrashes/utils/IPatchedMinecraft.java index d8e0eb8..082effa 100644 --- a/src/main/java/vfyjxf/bettercrashes/utils/IPatchedMinecraft.java +++ b/src/main/java/vfyjxf/bettercrashes/utils/IPatchedMinecraft.java @@ -3,6 +3,7 @@ package vfyjxf.bettercrashes.utils; import net.minecraft.crash.CrashReport; public interface IPatchedMinecraft { + boolean shouldCrashIntegratedServerNextTick(); void showWarningScreen(CrashReport report); diff --git a/src/main/java/vfyjxf/bettercrashes/utils/ModIdentifier.java b/src/main/java/vfyjxf/bettercrashes/utils/ModIdentifier.java index f7cefad..5e6cd65 100644 --- a/src/main/java/vfyjxf/bettercrashes/utils/ModIdentifier.java +++ b/src/main/java/vfyjxf/bettercrashes/utils/ModIdentifier.java @@ -1,28 +1,32 @@ /* - *This file is from - *https://github.com/DimensionalDevelopment/VanillaFix/blob/master/src/main/java/org/dimdev/utils/ModIdentifier.java - *The source file uses the MIT License. + * This file is from + * https://github.com/DimensionalDevelopment/VanillaFix/blob/master/src/main/java/org/dimdev/utils/ModIdentifier.java + * The source file uses the MIT License. */ package vfyjxf.bettercrashes.utils; -import cpw.mods.fml.common.Loader; -import cpw.mods.fml.common.ModContainer; import java.io.File; import java.io.IOException; import java.lang.reflect.Method; import java.net.URISyntaxException; import java.net.URL; import java.util.*; + import net.minecraft.launchwrapper.Launch; import net.minecraft.launchwrapper.LaunchClassLoader; + import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; +import cpw.mods.fml.common.Loader; +import cpw.mods.fml.common.ModContainer; + /** * @author Runemoro */ public final class ModIdentifier { + private static final Logger log = LogManager.getLogger(); public static Set identifyFromStacktrace(Throwable e) { @@ -63,8 +67,7 @@ public final class ModIdentifier { // Get the mod containing that class try { - if (url.getProtocol().equals("jar")) - url = new URL(url.getFile().substring(0, url.getFile().indexOf('!'))); + if (url.getProtocol().equals("jar")) url = new URL(url.getFile().substring(0, url.getFile().indexOf('!'))); return modMap.get(new File(url.toURI()).getCanonicalFile()); } catch (URISyntaxException | IOException e) { throw new RuntimeException("Exception processing URL " + url, e); @@ -85,8 +88,8 @@ public final class ModIdentifier { try { modMap.remove(Loader.instance().getMinecraftModContainer().getSource()); // Ignore minecraft jar (minecraft) - modMap.remove( - Loader.instance().getIndexedModList().get("FML").getSource()); // Ignore forge jar (FML, forge) + modMap.remove(Loader.instance().getIndexedModList().get("FML").getSource()); // Ignore forge jar (FML, + // forge) } catch (NullPointerException ignored) { // Workaround for https://github.com/MinecraftForge/MinecraftForge/issues/4919 } diff --git a/src/main/java/vfyjxf/bettercrashes/utils/StacktraceDeobfuscator.java b/src/main/java/vfyjxf/bettercrashes/utils/StacktraceDeobfuscator.java index 209ef7f..f9cc355 100644 --- a/src/main/java/vfyjxf/bettercrashes/utils/StacktraceDeobfuscator.java +++ b/src/main/java/vfyjxf/bettercrashes/utils/StacktraceDeobfuscator.java @@ -1,7 +1,7 @@ /* - *This file is from - *https://github.com/DimensionalDevelopment/VanillaFix/blob/master/src/main/java/org/dimdev/vanillafix/crashes/StacktraceDeobfuscator.java - *The source file uses the MIT License. + * This file is from + * https://github.com/DimensionalDevelopment/VanillaFix/blob/master/src/main/java/org/dimdev/vanillafix/crashes/ + * StacktraceDeobfuscator.java The source file uses the MIT License. */ package vfyjxf.bettercrashes.utils; @@ -20,13 +20,14 @@ import java.util.zip.ZipInputStream; * @author Runemoro */ public final class StacktraceDeobfuscator { - private static final boolean DEBUG_IN_DEV = - false; // Makes this MCP -> SRG for testing in dev. Don't forget to set to false when done! + + private static final boolean DEBUG_IN_DEV = false; // Makes this MCP -> SRG for testing in dev. Don't forget to set + // to false when done! private static HashMap srgMcpMethodMap = null; /** - * If the file does not exits, downloads latest method mappings and saves them to it. - * Initializes a HashMap between obfuscated and deobfuscated names from that file. + * If the file does not exits, downloads latest method mappings and saves them to it. Initializes a HashMap between + * obfuscated and deobfuscated names from that file. */ public static void init(File mappings) { if (srgMcpMethodMap != null) return; @@ -35,8 +36,8 @@ public final class StacktraceDeobfuscator { if (!mappings.exists()) { HttpURLConnection connection = null; try { - URL mappingsURL = - new URL("http://export.mcpbot.bspk.rs/mcp_stable_nodoc/39-1.12/mcp_stable_nodoc-39-1.12.zip"); + URL mappingsURL = new URL( + "http://export.mcpbot.bspk.rs/mcp_stable_nodoc/39-1.12/mcp_stable_nodoc-39-1.12.zip"); connection = (HttpURLConnection) mappingsURL.openConnection(); connection.setDoInput(true); connection.connect(); @@ -74,9 +75,8 @@ public final class StacktraceDeobfuscator { String mappingLine = scanner.nextLine(); int commaIndex = mappingLine.indexOf(','); String srgName = mappingLine.substring(0, commaIndex); - String mcpName = mappingLine.substring( - commaIndex + 1, - commaIndex + 1 + mappingLine.substring(commaIndex + 1).indexOf(',')); + String mcpName = mappingLine + .substring(commaIndex + 1, commaIndex + 1 + mappingLine.substring(commaIndex + 1).indexOf(',')); // System.out.println(srgName + " <=> " + mcpName); if (!DEBUG_IN_DEV) { @@ -108,7 +108,10 @@ public final class StacktraceDeobfuscator { int index = 0; for (StackTraceElement el : stackTrace) { stackTrace[index++] = new StackTraceElement( - el.getClassName(), deobfuscateMethodName(el.getMethodName()), el.getFileName(), el.getLineNumber()); + el.getClassName(), + deobfuscateMethodName(el.getMethodName()), + el.getFileName(), + el.getLineNumber()); } return stackTrace; } diff --git a/src/main/java/vfyjxf/bettercrashes/utils/StateManager.java b/src/main/java/vfyjxf/bettercrashes/utils/StateManager.java index ab22c1a..50f891d 100644 --- a/src/main/java/vfyjxf/bettercrashes/utils/StateManager.java +++ b/src/main/java/vfyjxf/bettercrashes/utils/StateManager.java @@ -1,7 +1,7 @@ /* - *This file is from - *https://github.com/DimensionalDevelopment/VanillaFix/blob/master/src/main/java/org/dimdev/vanillafix/crashes/StateManager.java - *The source file uses the MIT License. + * This file is from + * https://github.com/DimensionalDevelopment/VanillaFix/blob/master/src/main/java/org/dimdev/vanillafix/crashes/ + * StateManager.java The source file uses the MIT License. */ package vfyjxf.bettercrashes.utils; @@ -15,7 +15,9 @@ import java.util.Set; * @author Runemoro */ public class StateManager { + public interface IResettable { + default void register() { resettableRefs.add(new WeakReference<>(this)); }