Skip to content

Commit

Permalink
only show crashpatch server gui if a solution is detected
Browse files Browse the repository at this point in the history
  • Loading branch information
Wyvest committed Mar 23, 2022
1 parent 1ff6235 commit d74c1ab
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 16 deletions.
10 changes: 7 additions & 3 deletions src/main/java/cc/woverflow/crashpatch/mixin/MixinMinecraft.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@

package cc.woverflow.crashpatch.mixin;

import cc.woverflow.crashpatch.crashes.CrashHelper;
import cc.woverflow.crashpatch.crashes.CrashScan;
import cc.woverflow.crashpatch.crashes.StateManager;
import cc.woverflow.crashpatch.gui.GuiCrashMenu;
import cc.woverflow.crashpatch.gui.GuiServerDisconnectMenu;
Expand All @@ -27,7 +29,6 @@
import net.minecraft.client.settings.GameSettings;
import net.minecraft.client.shader.Framebuffer;
import net.minecraft.crash.CrashReport;
import net.minecraft.util.IChatComponent;
import net.minecraft.util.MinecraftError;
import net.minecraft.util.ReportedException;
import net.minecraft.util.ResourceLocation;
Expand Down Expand Up @@ -183,9 +184,12 @@ public void run(CallbackInfo ci) {
@Inject(method = "displayGuiScreen", at = @At("HEAD"), cancellable = true)
private void onGUIDisplay(GuiScreen i, CallbackInfo ci) {
if (i instanceof GuiDisconnected) {
ci.cancel();
AccessorGuiDisconnected gui = ((AccessorGuiDisconnected) i);
displayGuiScreen(new GuiServerDisconnectMenu(gui.getMessage(), gui.getReason()));
CrashScan scan = CrashHelper.scanReport(gui.getMessage().getFormattedText(), true);
if (scan != null && !scan.getSolutions().isEmpty()) {
ci.cancel();
displayGuiScreen(new GuiServerDisconnectMenu(gui.getMessage(), gui.getReason(), scan));
}
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package cc.woverflow.crashpatch.gui

import cc.woverflow.crashpatch.CrashPatch
import cc.woverflow.crashpatch.crashes.CrashHelper
import cc.woverflow.crashpatch.crashes.CrashScan
import cc.woverflow.crashpatch.gui.components.Button
import cc.woverflow.crashpatch.gui.components.TextButton
import cc.woverflow.crashpatch.logger
Expand All @@ -26,15 +26,8 @@ import java.awt.Color
import java.io.File
import java.io.IOException

class GuiServerDisconnectMenu(private val component: IChatComponent, reason: String) : WindowScreen(version = ElementaVersion.V1) {
class GuiServerDisconnectMenu(private val component: IChatComponent, reason: String, crashScan: CrashScan) : WindowScreen(version = ElementaVersion.V1) {
private var hasteLink: String? = null
private val crashScan by lazy {
var yes = CrashHelper.scanReport(component.formattedText, true)
if (yes != null && yes!!.solutions.isEmpty()) {
yes = null
}
yes
}

private var hasteFailed = false

Expand Down Expand Up @@ -72,7 +65,7 @@ class GuiServerDisconnectMenu(private val component: IChatComponent, reason: Str

private val second by UIWrappedText("""
${component.formattedText}
${if (CrashPatch.isSkyclient) "${ChatColor.BLUE}Please go to https://discord.gg/eh7tNFezct for support IF AND ONLY IF there is a solution below this." else ""}
${if (CrashPatch.isSkyclient) "${ChatColor.RED}PLEASE GO TO https://discord.gg/eh7tNFezct FOR SUPPORT." else ""}${"\nYou may also have a look at the suggestions below to fix the issue.\n"}
""".trimIndent(), centered = true) constrain {
x = 2.percent()
y = SiblingConstraint(9f)
Expand All @@ -94,7 +87,7 @@ class GuiServerDisconnectMenu(private val component: IChatComponent, reason: Str
height = 50.percent()
} childOf content

private val scrollableSolutions by ScrollComponent("No solutions found :( Please go to the discord server to support.", customScissorBoundingBox = block) constrain {
private val scrollableSolutions by ScrollComponent("No solutions found :(", customScissorBoundingBox = block) constrain {
width = 100.percent()
height = 100.percent()
} childOf block
Expand All @@ -106,7 +99,7 @@ class GuiServerDisconnectMenu(private val component: IChatComponent, reason: Str
} childOf block

init {
crashScan?.solutions?.let {
crashScan.solutions.let {
var yes = 0
it.forEach { list ->
++yes
Expand Down Expand Up @@ -175,4 +168,4 @@ class GuiServerDisconnectMenu(private val component: IChatComponent, reason: Str
content.setVerticalScrollBarComponent(scrollBar, true)
logger.error("Connection failed. Reason: $reason | Message: ${component.formattedText}")
}
}
}

0 comments on commit d74c1ab

Please sign in to comment.