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 440b41853d..5417be3087 100644 --- a/Mage.Client/src/main/java/mage/client/dialog/NewTournamentDialog.java +++ b/Mage.Client/src/main/java/mage/client/dialog/NewTournamentDialog.java @@ -49,6 +49,7 @@ import javax.swing.JOptionPane; import javax.swing.JTextArea; import javax.swing.SpinnerNumberModel; import javax.swing.filechooser.FileFilter; +import mage.cards.decks.Deck; import mage.cards.decks.importer.DeckImporterUtil; import mage.cards.repository.ExpansionInfo; import mage.cards.repository.ExpansionRepository; @@ -58,6 +59,7 @@ import mage.constants.MatchTimeLimit; import mage.constants.MultiplayerAttackOption; import mage.constants.RangeOfInfluence; import mage.constants.SkillLevel; +import mage.game.GameException; import mage.game.draft.DraftOptions; import mage.game.draft.DraftOptions.TimingOption; import mage.game.tournament.LimitedOptions; @@ -559,7 +561,15 @@ public class NewTournamentDialog extends MageDialog { if (tournamentType.isCubeBooster()) { tOptions.getLimitedOptions().setDraftCubeName(this.cbDraftCube.getSelectedItem().toString()); if (!(cubeFromDeckFilename.equals(""))) { - tOptions.getLimitedOptions().setCubeFromDeckFilename(cubeFromDeckFilename); + Deck cubeFromDeck = new Deck(); + try { + cubeFromDeck = Deck.load(DeckImporterUtil.importDeck(cubeFromDeckFilename), true, true); + } catch (GameException e1) { + JOptionPane.showMessageDialog(MageFrame.getDesktop(), e1.getMessage(), "Error loading deck", JOptionPane.ERROR_MESSAGE); + } + if (cubeFromDeck != null) { + tOptions.getLimitedOptions().setCubeFromDeck(cubeFromDeck); + } } } else if (tournamentType.isRandom() || tournamentType.isRichMan()) { this.isRandom = tournamentType.isRandom(); diff --git a/Mage.Server.Plugins/Mage.Tournament.BoosterDraft/src/mage/tournament/cubes/CubeFromDeck.java b/Mage.Server.Plugins/Mage.Tournament.BoosterDraft/src/mage/tournament/cubes/CubeFromDeck.java index 2d55daa72e..b4212eb369 100644 --- a/Mage.Server.Plugins/Mage.Tournament.BoosterDraft/src/mage/tournament/cubes/CubeFromDeck.java +++ b/Mage.Server.Plugins/Mage.Tournament.BoosterDraft/src/mage/tournament/cubes/CubeFromDeck.java @@ -27,6 +27,7 @@ */ package mage.tournament.cubes; +import mage.cards.decks.Deck; import mage.cards.decks.DeckCardInfo; import mage.cards.decks.DeckCardLists; import mage.cards.decks.importer.DeckImporterUtil; @@ -39,14 +40,17 @@ import mage.game.draft.DraftCube; */ public class CubeFromDeck extends DraftCube { - public CubeFromDeck(String chosenDckFile) { + public CubeFromDeck(Deck cubeFromDeck) { super("Cube From Deck"); - DeckCardLists cards = DeckImporterUtil.importDeck(chosenDckFile); - + DeckCardLists cards = null; + if (cubeFromDeck != null) { + cards = cubeFromDeck.getDeckCardLists(); + } + if (cards != null) { for (DeckCardInfo card : cards.getCards()) { - cubeCards.add(new CardIdentity(card.getCardName(), card.getSetCode())); + cubeCards.add(new CardIdentity(card.getCardName(), "")); } } } diff --git a/Mage.Server/src/main/java/mage/server/draft/CubeFactory.java b/Mage.Server/src/main/java/mage/server/draft/CubeFactory.java index ca1e2dd9c8..ad10a8b3fc 100644 --- a/Mage.Server/src/main/java/mage/server/draft/CubeFactory.java +++ b/Mage.Server/src/main/java/mage/server/draft/CubeFactory.java @@ -31,6 +31,7 @@ import java.lang.reflect.Constructor; import java.util.LinkedHashMap; import java.util.Map; import java.util.Set; +import mage.cards.decks.Deck; import mage.game.draft.DraftCube; import org.apache.log4j.Logger; @@ -67,13 +68,13 @@ public class CubeFactory { return draftCube; } - public DraftCube createDeckDraftCube(String draftCubeName, String chosenDckFile) { + public DraftCube createDeckDraftCube(String draftCubeName, Deck cubeFromDeck) { DraftCube draftCube; Constructor con; try { - con = draftCubes.get(draftCubeName).getConstructor(new Class[]{String.class}); - draftCube = (DraftCube)con.newInstance(new Object[] {chosenDckFile}); + con = draftCubes.get(draftCubeName).getConstructor(new Class[]{Deck.class}); + draftCube = (DraftCube)con.newInstance(new Object[] {cubeFromDeck}); } catch (Exception ex) { logger.fatal("CubeFactory error", ex); return null; diff --git a/Mage.Server/src/main/java/mage/server/tournament/TournamentFactory.java b/Mage.Server/src/main/java/mage/server/tournament/TournamentFactory.java index 32ce0dbb97..ddfd7d1445 100644 --- a/Mage.Server/src/main/java/mage/server/tournament/TournamentFactory.java +++ b/Mage.Server/src/main/java/mage/server/tournament/TournamentFactory.java @@ -81,8 +81,8 @@ public class TournamentFactory { if (tournament.getTournamentType().isCubeBooster()) { DraftCube draftCube = null; - if (tournament.getOptions().getLimitedOptions().getCubeFromDeckFilename().length() != 0) { - draftCube = CubeFactory.getInstance().createDeckDraftCube(tournament.getOptions().getLimitedOptions().getDraftCubeName(), tournament.getOptions().getLimitedOptions().getCubeFromDeckFilename()); + if (tournament.getOptions().getLimitedOptions().getCubeFromDeck() != null) { + draftCube = CubeFactory.getInstance().createDeckDraftCube(tournament.getOptions().getLimitedOptions().getDraftCubeName(), tournament.getOptions().getLimitedOptions().getCubeFromDeck()); } else { draftCube = CubeFactory.getInstance().createDraftCube(tournament.getOptions().getLimitedOptions().getDraftCubeName()); } diff --git a/Mage/src/main/java/mage/game/tournament/LimitedOptions.java b/Mage/src/main/java/mage/game/tournament/LimitedOptions.java index 9845e420f3..3e6fec25ee 100644 --- a/Mage/src/main/java/mage/game/tournament/LimitedOptions.java +++ b/Mage/src/main/java/mage/game/tournament/LimitedOptions.java @@ -31,6 +31,7 @@ package mage.game.tournament; import java.io.Serializable; import java.util.ArrayList; import java.util.List; +import mage.cards.decks.Deck; import mage.game.draft.DraftCube; /** @@ -45,7 +46,7 @@ public class LimitedOptions implements Serializable { protected DraftCube draftCube; protected int numberBoosters; protected boolean isRandom; - protected String cubeFromDeckFilename = ""; + protected Deck cubeFromDeck = null; public List getSetCodes() { return sets; @@ -67,12 +68,12 @@ public class LimitedOptions implements Serializable { this.draftCubeName = draftCubeName; } - public void setCubeFromDeckFilename(String cubeFromDeckFilename) { - this.cubeFromDeckFilename = cubeFromDeckFilename; + public void setCubeFromDeck(Deck cubeFromDeck) { + this.cubeFromDeck = cubeFromDeck; } - public String getCubeFromDeckFilename() { - return cubeFromDeckFilename; + public Deck getCubeFromDeck() { + return cubeFromDeck; } public DraftCube getDraftCube() {