mirror of
https://github.com/correl/mage.git
synced 2025-01-12 19:25:44 +00:00
Prevent NPE if client never connected to any server and doesn't have
sets downloaded.
This commit is contained in:
parent
9da86fefad
commit
3658a8c7bc
3 changed files with 25 additions and 4 deletions
|
@ -54,6 +54,14 @@ import mage.util.TournamentUtil;
|
|||
*/
|
||||
public class DeckGenerator {
|
||||
|
||||
public static class DeckGeneratorException extends RuntimeException {
|
||||
|
||||
public DeckGeneratorException(String message) {
|
||||
super(message);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private static final int MAX_TRIES = 8196;
|
||||
private static DeckGeneratorDialog genDialog;
|
||||
private static DeckGeneratorPool genPool;
|
||||
|
@ -82,6 +90,9 @@ public class DeckGenerator {
|
|||
String format = genDialog.getSelectedFormat();
|
||||
|
||||
List<String> setsToUse = ConstructedFormats.getSetsByFormat(format);
|
||||
if (setsToUse == null) {
|
||||
throw new DeckGeneratorException("Deck sets aren't initialized; please connect to a server to update the database.");
|
||||
}
|
||||
if (setsToUse.isEmpty()) {
|
||||
// Default to using all sets
|
||||
setsToUse = ExpansionRepository.instance.getSetCodes();
|
||||
|
|
|
@ -66,6 +66,7 @@ import static mage.client.dialog.PreferencesDialog.KEY_CONNECT_FLAG;
|
|||
import mage.client.preference.MagePreferences;
|
||||
import mage.client.util.Config;
|
||||
import mage.client.util.gui.countryBox.CountryItemEditor;
|
||||
import mage.client.util.sets.ConstructedFormats;
|
||||
import mage.remote.Connection;
|
||||
import org.apache.log4j.Logger;
|
||||
|
||||
|
@ -442,6 +443,7 @@ public class ConnectDialog extends MageDialog {
|
|||
private void connected() {
|
||||
this.saveSettings();
|
||||
this.hideDialog();
|
||||
ConstructedFormats.ensureLists();
|
||||
}
|
||||
|
||||
private void keyTyped(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_keyTyped
|
||||
|
|
|
@ -50,6 +50,12 @@ public class ConstructedFormats {
|
|||
|
||||
}
|
||||
|
||||
public static void ensureLists() {
|
||||
if (getSetsByFormat(ConstructedFormats.STANDARD) == null) {
|
||||
buildLists();
|
||||
}
|
||||
}
|
||||
|
||||
private static void buildLists() {
|
||||
GregorianCalendar cutoff;
|
||||
// month is zero based so January = 0
|
||||
|
@ -60,6 +66,7 @@ public class ConstructedFormats {
|
|||
cutoff = new GregorianCalendar(calendar.get(Calendar.YEAR) - 2, Calendar.SEPTEMBER, 1);
|
||||
}
|
||||
final Map<String, ExpansionInfo> expansionInfo = new HashMap<>();
|
||||
formats.clear(); // prevent NPE on sorting if this is not the first try
|
||||
for (ExpansionInfo set : ExpansionRepository.instance.getAll()) {
|
||||
expansionInfo.put(set.getName(), set);
|
||||
formats.add(set.getName());
|
||||
|
@ -207,10 +214,11 @@ public class ConstructedFormats {
|
|||
}
|
||||
|
||||
});
|
||||
|
||||
formats.add(0, MODERN);
|
||||
formats.add(0, EXTENDED);
|
||||
formats.add(0, STANDARD);
|
||||
if (!formats.isEmpty()) {
|
||||
formats.add(0, MODERN);
|
||||
formats.add(0, EXTENDED);
|
||||
formats.add(0, STANDARD);
|
||||
}
|
||||
formats.add(0, ALL);
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue