aboutsummaryrefslogtreecommitdiff
path: root/src/main/java
diff options
context:
space:
mode:
authorLulonaut <lulonaut@lulonaut.tech>2024-01-04 11:13:33 +0100
committerGitHub <noreply@github.com>2024-01-04 11:13:33 +0100
commited5b74e3d9fc3056187cd153a118019b657e061a (patch)
treee91f7a22822046a17608090ba2309e30b89e01a4 /src/main/java
parent5e21422a8e8cb164a46f5eede9a6f28f84a35675 (diff)
downloadNotEnoughUpdates-ed5b74e3d9fc3056187cd153a118019b657e061a.tar.gz
NotEnoughUpdates-ed5b74e3d9fc3056187cd153a118019b657e061a.tar.bz2
NotEnoughUpdates-ed5b74e3d9fc3056187cd153a118019b657e061a.zip
Fix crash for old player profiles (#987)
Diffstat (limited to 'src/main/java')
-rw-r--r--src/main/java/io/github/moulberry/notenoughupdates/profileviewer/GuiProfileViewer.java28
1 files changed, 14 insertions, 14 deletions
diff --git a/src/main/java/io/github/moulberry/notenoughupdates/profileviewer/GuiProfileViewer.java b/src/main/java/io/github/moulberry/notenoughupdates/profileviewer/GuiProfileViewer.java
index 21bdfa43..86db77ca 100644
--- a/src/main/java/io/github/moulberry/notenoughupdates/profileviewer/GuiProfileViewer.java
+++ b/src/main/java/io/github/moulberry/notenoughupdates/profileviewer/GuiProfileViewer.java
@@ -19,6 +19,7 @@
package io.github.moulberry.notenoughupdates.profileviewer;
+import com.google.gson.JsonPrimitive;
import io.github.moulberry.notenoughupdates.NotEnoughUpdates;
import io.github.moulberry.notenoughupdates.core.util.StringUtils;
import io.github.moulberry.notenoughupdates.cosmetics.ShaderManager;
@@ -191,11 +192,7 @@ public class GuiProfileViewer extends GuiScreen {
GuiProfileViewer.profile = profile;
GuiProfileViewer.profileName = profile.getLatestProfileName();
- String playerName = "";
- if (profile.getHypixelProfile() != null) {
- playerName = profile.getHypixelProfile().get("displayname").getAsString();
- }
- playerNameTextField = new GuiElementTextField(playerName, GuiElementTextField.SCALE_TEXT);
+ playerNameTextField = new GuiElementTextField(getDisplayName(), GuiElementTextField.SCALE_TEXT);
playerNameTextField.setSize(100, 20);
if (currentPage == ProfileViewerPage.LOADING) {
@@ -647,11 +644,16 @@ public class GuiProfileViewer extends GuiScreen {
Utils.drawItemStack(stack, x + 6, y + 9);
}
+ private static String getDisplayName() {
+ return Utils.getElementOrDefault(
+ profile.getHypixelProfile(),
+ "displayname",
+ new JsonPrimitive(EnumChatFormatting.RED + "ERROR")
+ ).getAsString();
+ }
+
private void renderRecentPlayers(boolean renderCurrent) {
- String playerName = "";
- if (profile.getHypixelProfile() != null) {
- playerName = profile.getHypixelProfile().get("displayname").getAsString();
- }
+ String playerName = getDisplayName();
boolean selected = Objects.equals(Minecraft.getMinecraft().thePlayer.getName(), playerName);
if (selected == renderCurrent) {
@@ -749,10 +751,8 @@ public class GuiProfileViewer extends GuiScreen {
}
}
- String playerName = "";
- if (profile.getHypixelProfile() != null) {
- playerName = profile.getHypixelProfile().get("displayname").getAsString().toLowerCase();
- }
+ String playerName = getDisplayName();
+
int x = guiLeft + sizeX;
int y = guiTop;
List<String> previousProfileSearches = NotEnoughUpdates.INSTANCE.config.hidden.previousProfileSearches;
@@ -799,7 +799,7 @@ public class GuiProfileViewer extends GuiScreen {
) {
if (mouseY > guiTop + sizeY + 3 && mouseY < guiTop + sizeY + 23) {
String url =
- "https://sky.shiiyu.moe/stats/" + profile.getHypixelProfile().get("displayname").getAsString() + "/" +
+ "https://sky.shiiyu.moe/stats/" + getDisplayName() + "/" +
profileName;
Utils.openUrl(url);
Utils.playPressSound();