diff --git a/src/main/java/com/iridium/iridiumteams/gui/MissionGUI.java b/src/main/java/com/iridium/iridiumteams/gui/MissionGUI.java index 8a0f211e..362d0a39 100755 --- a/src/main/java/com/iridium/iridiumteams/gui/MissionGUI.java +++ b/src/main/java/com/iridium/iridiumteams/gui/MissionGUI.java @@ -21,6 +21,7 @@ import java.util.List; import java.util.Map; +import java.util.Optional; import java.util.stream.Collectors; import java.util.stream.IntStream; @@ -52,14 +53,23 @@ public void addContent(Inventory inventory) { super.addContent(inventory); List teamMissions = iridiumTeams.getTeamManager().getTeamMissions(team); + + // Deals where slot is not null for (Map.Entry entry : iridiumTeams.getMissions().missions.entrySet()) { if (entry.getValue().getMissionType() != missionType) continue; - int level = teamMissions.stream().filter(m -> m.getMissionName().equals(entry.getKey())).map(TeamMission::getMissionLevel).findFirst().orElse(1); + Optional teamMission = teamMissions.stream().filter(m -> m.getMissionName().equals(entry.getKey())).findFirst(); + int level = teamMission.map(TeamMission::getMissionLevel).orElse(1); + if(teamMission.isPresent() && teamMission.get().hasExpired()){ + iridiumTeams.getTeamManager().deleteTeamMission(teamMission.get()); + iridiumTeams.getTeamManager().deleteTeamMissionData(teamMission.get()); + level = 1; + } MissionData missionData = entry.getValue().getMissionData().get(level); if (missionData.getItem().slot == null) continue; inventory.setItem(missionData.getItem().slot, getItem(entry.getKey())); } + // Deals where slot is null, to randomly pick a few missions List missions = iridiumTeams.getTeamManager().getTeamMission(team, missionType); int index = 0; for (String missionName : missions) { @@ -71,6 +81,7 @@ public void addContent(Inventory inventory) { } private ItemStack getItem(String missionName) { + // This will create the mission if it doesnt exist TeamMission teamMission = iridiumTeams.getTeamManager().getTeamMission(team, missionName); Mission mission = iridiumTeams.getMissions().missions.get(missionName); MissionData missionData = mission.getMissionData().get(teamMission.getMissionLevel());