diff --git a/changelog.md b/changelog.md index 342c8ad..129378e 100644 --- a/changelog.md +++ b/changelog.md @@ -4,6 +4,7 @@ - Fixed MatchRunner not working for users with spaces in their windows username. - NicEastvillage - Adjusted logger formatting. - NicEastvillage - Fixed "succesfully saved"-alert when saving was cancelled. #129 - NicEastvillage +- Fixed loading of tournaments where a participating bot has been deleted. #130 - NicEastvillage #### Version 1.8.2 - April 2024 - Updated RLBot python path to python 3.11 installation. #117/#127 - CodeRed/NicEastvillage diff --git a/src/main/java/dk/aau/cs/ds306e18/tournament/model/BotFromConfig.java b/src/main/java/dk/aau/cs/ds306e18/tournament/model/BotFromConfig.java index 0d6f892..c55360e 100644 --- a/src/main/java/dk/aau/cs/ds306e18/tournament/model/BotFromConfig.java +++ b/src/main/java/dk/aau/cs/ds306e18/tournament/model/BotFromConfig.java @@ -35,7 +35,7 @@ public boolean reload() { configLoadedCorrectly = true; } catch (Exception e) { configLoadedCorrectly = false; - throw new RuntimeException("Could not load bot from config " + pathToConfig + ", reason: " + e.getMessage()); + throw new RuntimeException("Could not load bot from config " + pathToConfig, e); } return loadedCorrectly(); } diff --git a/src/main/java/dk/aau/cs/ds306e18/tournament/model/Team.java b/src/main/java/dk/aau/cs/ds306e18/tournament/model/Team.java index 443315e..5494393 100644 --- a/src/main/java/dk/aau/cs/ds306e18/tournament/model/Team.java +++ b/src/main/java/dk/aau/cs/ds306e18/tournament/model/Team.java @@ -3,6 +3,7 @@ import dk.aau.cs.ds306e18.tournament.model.stats.StatsManager; import java.util.ArrayList; +import java.util.Collections; import java.util.List; import java.util.Objects; @@ -91,6 +92,7 @@ public StatsManager getStatsManager() { * Repairs properties that cannot be deserialized. */ public void postDeserializationRepair() { + bots.removeAll(Collections.singletonList(null)); statsManager = new StatsManager(this); } diff --git a/src/main/java/dk/aau/cs/ds306e18/tournament/serialization/BotAdapter.java b/src/main/java/dk/aau/cs/ds306e18/tournament/serialization/BotAdapter.java index 594046f..7db3ffa 100644 --- a/src/main/java/dk/aau/cs/ds306e18/tournament/serialization/BotAdapter.java +++ b/src/main/java/dk/aau/cs/ds306e18/tournament/serialization/BotAdapter.java @@ -3,11 +3,14 @@ import com.google.gson.TypeAdapter; import com.google.gson.stream.JsonReader; import com.google.gson.stream.JsonWriter; +import dk.aau.cs.ds306e18.tournament.Main; import dk.aau.cs.ds306e18.tournament.model.Bot; import dk.aau.cs.ds306e18.tournament.model.BotFromConfig; import dk.aau.cs.ds306e18.tournament.rlbot.configuration.BotSkill; import dk.aau.cs.ds306e18.tournament.model.PsyonixBotFromConfig; import dk.aau.cs.ds306e18.tournament.rlbot.BotCollection; +import dk.aau.cs.ds306e18.tournament.utility.Alerts; +import javafx.application.Platform; import java.io.IOException; @@ -51,11 +54,16 @@ public Bot read(JsonReader in) throws IOException { in.nextName(); double skill = in.nextDouble(); in.endObject(); - PsyonixBotFromConfig bot = new PsyonixBotFromConfig(config, BotSkill.getSkillFromNumber(skill)); - - // Add to BotCollection and return - BotCollection.global.add(bot); - return bot; + try { + PsyonixBotFromConfig bot = new PsyonixBotFromConfig(config, BotSkill.getSkillFromNumber(skill)); + BotCollection.global.add(bot); + return bot; + + } catch (RuntimeException e) { + Main.LOGGER.log(System.Logger.Level.ERROR, "Failed to load bot from config. " + e.getCause().getMessage()); + Platform.runLater(() -> Alerts.errorNotification("Failed to load bot: " + config, e.getCause().getMessage())); + return null; + } } else if (BotFromConfig.class.getSimpleName().equals(clazz)) { @@ -63,11 +71,16 @@ public Bot read(JsonReader in) throws IOException { in.nextName(); String config = in.nextString(); in.endObject(); - BotFromConfig bot = new BotFromConfig(config); - - // Add to BotCollection and return - BotCollection.global.add(bot); - return bot; + try { + BotFromConfig bot = new BotFromConfig(config); + BotCollection.global.add(bot); + return bot; + + } catch (RuntimeException e) { + Main.LOGGER.log(System.Logger.Level.ERROR, "Failed to load bot from config. " + e.getCause().getMessage()); + Platform.runLater(() -> Alerts.errorNotification("Failed to load bot: " + config, e.getCause().getMessage())); + return null; + } } in.endObject();