diff --git a/Mage.Client/src/main/java/mage/client/dialog/NewTournamentDialog.java b/Mage.Client/src/main/java/mage/client/dialog/NewTournamentDialog.java index 8e34f93df0..bc884ff57d 100644 --- a/Mage.Client/src/main/java/mage/client/dialog/NewTournamentDialog.java +++ b/Mage.Client/src/main/java/mage/client/dialog/NewTournamentDialog.java @@ -785,19 +785,21 @@ public class NewTournamentDialog extends MageDialog { return ""; } + private JFileChooser fcJumpstartSelectDeck = null; + protected String playerLoadJumpstartPacks() { - if (fcSelectDeck == null) { - fcSelectDeck = new JFileChooser(); - fcSelectDeck.setAcceptAllFileFilterUsed(false); - fcSelectDeck.addChoosableFileFilter(new DeckFileFilter("txt", "Jumpstart Packs (*.txt)")); + if (fcJumpstartSelectDeck == null) { + fcJumpstartSelectDeck = new JFileChooser(); + fcJumpstartSelectDeck.setAcceptAllFileFilterUsed(false); + fcJumpstartSelectDeck.addChoosableFileFilter(new DeckFileFilter("txt", "Jumpstart Packs (*.txt)")); } String lastFolder = MageFrame.getPreferences().get("lastDeckFolder", ""); if (!lastFolder.isEmpty()) { - fcSelectDeck.setCurrentDirectory(new File(lastFolder)); + fcJumpstartSelectDeck.setCurrentDirectory(new File(lastFolder)); } - int ret = fcSelectDeck.showDialog(this, "Select Jumpstart Packs file"); + int ret = fcJumpstartSelectDeck.showDialog(this, "Select Jumpstart Packs file"); if (ret == JFileChooser.APPROVE_OPTION) { - File file = fcSelectDeck.getSelectedFile(); + File file = fcJumpstartSelectDeck.getSelectedFile(); return (file.getPath()); } return ""; @@ -1234,6 +1236,10 @@ public class NewTournamentDialog extends MageDialog { String jumpstartPacksData = ""; try { jumpstartPacksData = new String(Files.readAllBytes(Paths.get(jumpstartPacksFilename))); + if (jumpstartPacksData.length() > 300000) { + JOptionPane.showMessageDialog(MageFrame.getDesktop(), "Chosen file too big", "Jumpstart Packs data is too long. Please trim or choose another file.", JOptionPane.ERROR_MESSAGE); + jumpstartPacksData = ""; + } } catch (IOException e2) { JOptionPane.showMessageDialog(MageFrame.getDesktop(), e2.getMessage(), "Error loading Jumpstart Packs data", JOptionPane.ERROR_MESSAGE); } diff --git a/Mage/src/main/java/mage/game/jumpstart/JumpstartPoolGenerator.java b/Mage/src/main/java/mage/game/jumpstart/JumpstartPoolGenerator.java index 147ce1e6d7..1108f29954 100644 --- a/Mage/src/main/java/mage/game/jumpstart/JumpstartPoolGenerator.java +++ b/Mage/src/main/java/mage/game/jumpstart/JumpstartPoolGenerator.java @@ -48,9 +48,14 @@ public class JumpstartPoolGenerator { * Deck Lists: https://magic.wizards.com/en/articles/archive/feature/jumpstart-decklists-2020-06-18 */ private static final String RESOURCE_NAME = "jumpstart/jumpstart.txt"; - private static List JUMPSTART_PACKS; + private static final List JUMPSTART_PACKS; - private static void setupPacks(String jumpstartPacks, boolean useDefault) { + static { + List packs = getPacks ("", true); + JUMPSTART_PACKS = Collections.unmodifiableList(packs); + } + + private static List getPacks(String jumpstartPacks, boolean useDefault) { try { CharSource source; if (useDefault) { @@ -77,19 +82,19 @@ public class JumpstartPoolGenerator { } } } - JUMPSTART_PACKS = Collections.unmodifiableList(packs); + return packs; } catch (IOException e) { throw new UncheckedIOException(e); } } - private static Set doGeneratePool() { + private static Set doGeneratePool(List packs) { try { DeckCardLists list = new DeckCardLists(); SecureRandom random = new SecureRandom(); for (int i = 0; i < 2; i++) { - int index = random.nextInt(JUMPSTART_PACKS.size()); - list.getCards().addAll(JUMPSTART_PACKS.get(index).getCards()); + int index = random.nextInt(packs.size()); + list.getCards().addAll(packs.get(index).getCards()); } return Deck.load(list, false, false).getCards(); } catch (GameException e) { @@ -111,13 +116,15 @@ public class JumpstartPoolGenerator { * https://mtg.gamepedia.com/Jumpstart#Marketing */ public static Set generatePool() { - setupPacks("", true); - return doGeneratePool(); + return doGeneratePool(JUMPSTART_PACKS); } public static Set generatePool(String userJumpstartPacks) { - setupPacks(userJumpstartPacks, false); - return doGeneratePool(); + if (userJumpstartPacks == null || userJumpstartPacks.length() > 300000) { + return generatePool(); + } + List packs = getPacks(userJumpstartPacks, false); + return doGeneratePool(packs); } public static class JumpstartPack {