1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
|
/*
* Copyright (C) 2024 NotEnoughUpdates contributors
*
* This file is part of NotEnoughUpdates.
*
* NotEnoughUpdates is free software: you can redistribute it
* and/or modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation, either
* version 3 of the License, or (at your option) any later version.
*
* NotEnoughUpdates is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with NotEnoughUpdates. If not, see <https://www.gnu.org/licenses/>.
*/
package io.github.moulberry.notenoughupdates.profileviewer;
import io.github.moulberry.moulconfig.internal.ClipboardUtils;
import io.github.moulberry.notenoughupdates.NotEnoughUpdates;
import io.github.moulberry.notenoughupdates.core.util.render.RenderUtils;
import io.github.moulberry.notenoughupdates.util.Rectangle;
import io.github.moulberry.notenoughupdates.util.Utils;
import lombok.val;
import net.minecraft.client.Minecraft;
import net.minecraft.client.renderer.GlStateManager;
import net.minecraft.crash.CrashReport;
import net.minecraft.init.Bootstrap;
import java.io.IOException;
import java.time.Instant;
import java.time.OffsetDateTime;
import java.time.ZoneId;
import java.time.format.DateTimeFormatter;
public class CrashRecoveryPage extends GuiProfileViewerPage {
private final Exception exception;
private final String timestamp;
private final GuiProfileViewer.ProfileViewerPage lastViewedPage;
private int offset = 0;
private final CrashReport crashReport;
public CrashRecoveryPage(
GuiProfileViewer instance,
Exception exception,
GuiProfileViewer.ProfileViewerPage lastViewedPage
) {
super(instance);
this.lastViewedPage = lastViewedPage;
this.timestamp = DateTimeFormatter.ISO_ZONED_DATE_TIME.format(OffsetDateTime.ofInstant(
Instant.now(),
ZoneId.systemDefault()
));
this.exception = exception;
val profile = GuiProfileViewer.getProfile();
crashReport = new CrashReport("NEU Profile Viewer crashed", exception);
val parameters = crashReport.makeCategory("Profile Viewer Parameters");
parameters.addCrashSection("Viewed Player", getInstance().getEntityPlayer().getName());
parameters.addCrashSection("Viewed Player UUID", (profile == null ? "null" : profile.getUuid()));
parameters.addCrashSection("Viewed Profile", GuiProfileViewer.getProfileName());
parameters.addCrashSection("Timestamp", timestamp);
parameters.addCrashSection("Last Viewed Page", lastViewedPage);
if (NotEnoughUpdates.INSTANCE.manager.onBackupRepo) {
parameters.addCrashSection("Repo Commit", "Using Backup");
} else {
parameters.addCrashSection("Repo Commit", NotEnoughUpdates.INSTANCE.manager.latestRepoCommit);
}
Bootstrap.printToSYSOUT(crashReport.getCompleteReport());
}
@Override
public void drawPage(int mouseX, int mouseY, float partialTicks) {
GlStateManager.pushMatrix();
GlStateManager.translate(
GuiProfileViewer.getGuiLeft() + getInstance().sizeX / 2f,
GuiProfileViewer.getGuiTop() + 20,
0
);
offset = 20;
drawTitle();
drawString("§cLooks like your profile viewer crashed.");
drawString("§cPlease immediately send a screenshot of this screen into #neu-support.");
drawString("§cJoin our support server at §adiscord.gg/moulberry§c.");
val profile = GuiProfileViewer.getProfile();
drawString("Viewed Player: " + getInstance().getEntityPlayer().getName());
drawString("Viewed Player UUID: " + (profile == null ? "null" : profile.getUuid()));
drawString("Viewed Profile: " + GuiProfileViewer.getProfileName());
drawString("Timestamp: " + timestamp);
drawString("");
drawString(exception.toString());
for (StackTraceElement stackTraceElement : exception.getStackTrace()) {
if (offset >= getInstance().sizeY - 50) break;
drawString(stackTraceElement.toString());
}
GlStateManager.popMatrix();
val buttonCoords = getButtonCoordinates();
RenderUtils.drawFloatingRectWithAlpha(
buttonCoords.getX(), buttonCoords.getY(),
buttonCoords.getWidth(), buttonCoords.getHeight(),
100, true
);
Utils.drawStringCenteredScaledMaxWidth(
"Copy Report",
buttonCoords.getCenterX(),
buttonCoords.getCenterY(),
false,
buttonCoords.getWidth(),
-1
);
}
@Override
public boolean mouseClicked(int mouseX, int mouseY, int mouseButton) throws IOException {
if (getButtonCoordinates().contains(mouseX, mouseY) && mouseButton == 0) {
ClipboardUtils.copyToClipboard(crashReport.getCompleteReport());
}
return super.mouseClicked(mouseX, mouseY, mouseButton);
}
private Rectangle getButtonCoordinates() {
return new Rectangle(
GuiProfileViewer.getGuiLeft() + getInstance().sizeX / 2 - 40,
GuiProfileViewer.getGuiTop() + getInstance().sizeY - 30,
80, 12
);
}
private void drawString(String text) {
Utils.drawStringCenteredScaledMaxWidth(text, 0, 0, false, getInstance().sizeX - 20, -1);
val spacing = Minecraft.getMinecraft().fontRendererObj.FONT_HEIGHT + 2;
GlStateManager.translate(0, spacing, 0);
offset += spacing;
}
private void drawTitle() {
GlStateManager.pushMatrix();
GlStateManager.scale(2, 2, 2);
Utils.drawStringCenteredScaledMaxWidth("§cKA-BOOM!", 0, 0, false, getInstance().sizeX / 2, -1);
GlStateManager.popMatrix();
val spacing = Minecraft.getMinecraft().fontRendererObj.FONT_HEIGHT * 2 + 6;
GlStateManager.translate(0, spacing, 0);
offset += spacing;
}
}
|