Ensure that the profile map is never null

Do not let the user launch the game if the version id is "Unknown"
This commit is contained in:
artdeell 2023-03-02 16:49:52 +03:00
parent a768f22dda
commit 7c3aacd2af
2 changed files with 3 additions and 3 deletions

View File

@ -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;
}

View File

@ -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<>();