Add limit for number of logs generated (#5)

* Add limit for number of logs generated

* Extract common code

* better GTNH mode

* Open issue tracker for both opened and closed issues
This commit is contained in:
miozune authored and GitHub committed 2022-08-09 01:25:17 +04:00
1 parent 6e1b2b3e36
commit 7532b3e0fb
7 files changed
+161 -119

No files matched your search

@@ -6,12 +6,15 @@
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;
import java.util.Arrays;
import java.util.Collections;
@@ -29,13 +32,28 @@ import vfyjxf.bettercrashes.BetterCrashesConfig;
@SideOnly(Side.CLIENT)
public abstract class GuiProblemScreen extends GuiScreen {
private static Field fieldClientCrashCount = null;
private static Field fieldServerCrashCount = null;
static {
try {
// these are actually reachable, see MinecraftMixin
fieldClientCrashCount = Minecraft.class.getDeclaredField("clientCrashCount");
fieldClientCrashCount.setAccessible(true);
fieldServerCrashCount = Minecraft.class.getDeclaredField("serverCrashCount");
fieldServerCrashCount.setAccessible(true);
} catch (Exception e) {
e.printStackTrace();
}
}
protected final CrashReport report;
private volatile String hasteLink = null;
private String modListString;
protected static final List<String> UNSUPPORTED_MOD_IDS = Arrays.asList();
protected List<String> detectedUnsupportedModNames;
private static final String GTNH_ISSUE_TRACKER =
"https://github.com/GTNewHorizons/GT-New-Horizons-Modpack/labels/Type%3A%20Crash";
"https://github.com/GTNewHorizons/GT-New-Horizons-Modpack/issues?q=label%3A%22Type%3A+Crash%22";
public GuiProblemScreen(CrashReport report) {
this.report = report;
@@ -121,6 +139,72 @@ public abstract class GuiProblemScreen extends GuiScreen {
@Override
protected void keyTyped(char typedChar, int keyCode) {}
protected abstract String getScreenTitle();
protected abstract String getScreenSummary();
@Override
public void drawScreen(int mouseX, int mouseY, float partialTicks) {
if (detectedUnsupportedModNames == null) {
detectedUnsupportedModNames = getUnsupportedMods();
}
boolean hasUnsupportedMods = !detectedUnsupportedModNames.isEmpty();
drawDefaultBackground();
drawCenteredString(
fontRendererObj,
getScreenTitle(),
width / 2,
height / 4 - 40 - (hasUnsupportedMods ? 16 : 0),
0xFFFFFF);
int textColor = 0xD0D0D0;
int x = width / 2 - 155;
int y = height / 4;
if (hasUnsupportedMods) {
y -= 32;
}
drawString(fontRendererObj, getScreenSummary(), x, y, textColor);
drawString(fontRendererObj, I18n.format("bettercrashes.gui.common.paragraph1"), x, y += 18, textColor);
drawCenteredString(fontRendererObj, getModListString(), width / 2, y += 11, 0xE0E000);
if (isCrashLogExpectedToBeGenerated()) {
drawString(fontRendererObj, I18n.format("bettercrashes.gui.common.paragraph2"), x, y += 11, textColor);
drawCenteredString(
fontRendererObj,
report.getFile() != null
? "\u00A7n" + report.getFile().getName()
: I18n.format("bettercrashes.gui.common.reportSaveFailed"),
width / 2,
y += 11,
0x00FF00);
} else {
drawString(fontRendererObj, I18n.format("bettercrashes.gui.common.paragraph6"), x, y += 11, textColor);
drawString(fontRendererObj, I18n.format("bettercrashes.gui.common.paragraph7"), x, y += 11, textColor);
}
y += 12;
y += drawLongString(
fontRendererObj,
I18n.format("bettercrashes.gui.common.paragraph3" + (isGTNH ? "_gtnh" : "")),
x,
y,
340,
textColor);
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);
drawString(fontRendererObj, I18n.format("bettercrashes.gui.common.paragraph5_gtnh"), x, y += 12, textColor);
}
super.drawScreen(mouseX, mouseY, partialTicks);
}
protected String getModListString() {
if (modListString == null) {
final Set<ModContainer> suspectedMods = ((IPatchedCrashReport) report).getSuspectedMods();
@@ -164,4 +248,31 @@ public abstract class GuiProblemScreen extends GuiScreen {
}
return list;
}
private int getClientCrashCount() {
if (fieldClientCrashCount != null) {
try {
return (int) fieldClientCrashCount.get(Minecraft.getMinecraft());
} catch (Exception e) {
e.printStackTrace();
}
}
return 0;
}
private int getServerCrashCount() {
if (fieldServerCrashCount != null) {
try {
return (int) fieldServerCrashCount.get(Minecraft.getMinecraft());
} catch (Exception e) {
e.printStackTrace();
}
}
return 0;
}
protected boolean isCrashLogExpectedToBeGenerated() {
return getClientCrashCount() <= BetterCrashesConfig.crashLogLimitClient
&& getServerCrashCount() <= BetterCrashesConfig.crashLogLimitServer;
}
}