From 7c3aacd2af884b7497fbc51321cbbcb129d002e4 Mon Sep 17 00:00:00 2001 From: artdeell Date: Thu, 2 Mar 2023 16:49:52 +0300 Subject: [PATCH] Ensure that the profile map is never null Do not let the user launch the game if the version id is "Unknown" --- .../src/main/java/net/kdt/pojavlaunch/LauncherActivity.java | 5 ++--- .../pojavlaunch/value/launcherprofiles/LauncherProfiles.java | 1 + 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/app_pojavlauncher/src/main/java/net/kdt/pojavlaunch/LauncherActivity.java b/app_pojavlauncher/src/main/java/net/kdt/pojavlaunch/LauncherActivity.java index 8f3f487c7..d457f428a 100644 --- a/app_pojavlauncher/src/main/java/net/kdt/pojavlaunch/LauncherActivity.java +++ b/app_pojavlauncher/src/main/java/net/kdt/pojavlaunch/LauncherActivity.java @@ -106,13 +106,12 @@ public class LauncherActivity extends BaseActivity { } String selectedProfile = LauncherPreferences.DEFAULT_PREF.getString(LauncherPreferences.PREF_KEY_CURRENT_PROFILE,""); - if (LauncherProfiles.mainProfileJson == null || LauncherProfiles.mainProfileJson.profiles == null - || !LauncherProfiles.mainProfileJson.profiles.containsKey(selectedProfile)){ + if (LauncherProfiles.mainProfileJson == null || !LauncherProfiles.mainProfileJson.profiles.containsKey(selectedProfile)){ Toast.makeText(this, R.string.error_no_version, Toast.LENGTH_LONG).show(); return false; } MinecraftProfile prof = LauncherProfiles.mainProfileJson.profiles.get(selectedProfile); - if (prof == null || prof.lastVersionId == null){ + if (prof == null || prof.lastVersionId == null || "Unknown".equals(prof.lastVersionId)){ Toast.makeText(this, R.string.error_no_version, Toast.LENGTH_LONG).show(); return false; } diff --git a/app_pojavlauncher/src/main/java/net/kdt/pojavlaunch/value/launcherprofiles/LauncherProfiles.java b/app_pojavlauncher/src/main/java/net/kdt/pojavlaunch/value/launcherprofiles/LauncherProfiles.java index a231f0126..0efd39842 100644 --- a/app_pojavlauncher/src/main/java/net/kdt/pojavlaunch/value/launcherprofiles/LauncherProfiles.java +++ b/app_pojavlauncher/src/main/java/net/kdt/pojavlaunch/value/launcherprofiles/LauncherProfiles.java @@ -12,6 +12,7 @@ public class LauncherProfiles { if (mainProfileJson == null) { if (launcherProfilesFile.exists()) { mainProfileJson = Tools.GLOBAL_GSON.fromJson(Tools.read(launcherProfilesFile.getAbsolutePath()), MinecraftLauncherProfiles.class); + if(mainProfileJson.profiles == null) mainProfileJson.profiles = new HashMap<>(); } else { mainProfileJson = new MinecraftLauncherProfiles(); mainProfileJson.profiles = new HashMap<>();