Dependencies and checkstyle is now clean

This commit is contained in:
jendave
2012-01-20 21:10:41 +00:00
parent 2d59c17367
commit fbb1d99b21
18 changed files with 698 additions and 714 deletions

View File

@@ -709,11 +709,7 @@
<artifactId>commons-lang3</artifactId>
<version>3.1</version>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-io</artifactId>
<version>1.3.2</version>
</dependency>
<dependency>
<groupId>org.freemarker</groupId>
<artifactId>freemarker</artifactId>

View File

@@ -106,8 +106,7 @@ public class Card extends GameEntity implements Comparable<Card> {
this.curCharacteristics = state;
if ((cur.equals("Original") && state.equals("Transformed"))
|| cur.equals("Transformed") && state.equals("Original")) {
|| (cur.equals("Transformed") && state.equals("Original"))) {
HashMap<String, Object> runParams = new HashMap<String, Object>();
runParams.put("Mode", "Transformed");
runParams.put("Transformer", this);
@@ -318,9 +317,11 @@ public class Card extends GameEntity implements Comparable<Card> {
}
/**
* Sets whether or not this card is transformable, but non-flip and not double-faced.
* Sets whether or not this card is transformable, but non-flip and not
* double-faced.
*
* @param otherTransformable0 a String
* @param otherTransformable0
* a String
*/
public final void setTransformable(final String otherTransformable0) {
this.otherTransformable = otherTransformable0;
@@ -2438,8 +2439,7 @@ public class Card extends GameEntity implements Comparable<Card> {
final StringBuilder sbMana = new StringBuilder();
for (int i = 0; i < keyword.size(); i++) {
if (!keyword.get(i).toString()
.contains("Permanents don't untap during their controllers' untap steps")
if (!keyword.get(i).toString().contains("Permanents don't untap during their controllers' untap steps")
&& !keyword.get(i).toString().contains("PreventAllDamageBy")
&& !keyword.get(i).toString().contains("CantBlock")
&& !keyword.get(i).toString().contains("CantBeBlockedBy")) {
@@ -2606,7 +2606,7 @@ public class Card extends GameEntity implements Comparable<Card> {
}
}
//Replacement effects
// Replacement effects
for (final ReplacementEffect replacementEffect : this.getCharacteristics().getReplacementEffects()) {
sb.append(replacementEffect.toString() + "\r\n");
}
@@ -2707,7 +2707,7 @@ public class Card extends GameEntity implements Comparable<Card> {
}
}
//Replacement effects
// Replacement effects
for (final ReplacementEffect replacementEffect : this.getCharacteristics().getReplacementEffects()) {
sb.append(replacementEffect.toString() + "\r\n");
}
@@ -2754,22 +2754,22 @@ public class Card extends GameEntity implements Comparable<Card> {
}
if (keyword.startsWith("Storm")) {
if (sb.toString().contains("Target") || sb.toString().contains("target")) {
sb.insert(sb.indexOf("Storm (When you cast this spell, copy it for each spell cast before it this turn.") + 81,
sb.insert(
sb.indexOf("Storm (When you cast this spell, copy it for each spell cast before it this turn.") + 81,
" You may choose new targets for the copies.");
}
}
/*
if (keyword.startsWith("Storm")) {
if (sb.toString().endsWith("\r\n\r\n")) {
sb.delete(sb.lastIndexOf("\r\n"), sb.lastIndexOf("\r\n") + 3);
}
sb.append("Storm (When you cast this spell, copy it for each spell cast before it this turn.");
if (sb.toString().contains("Target") || sb.toString().contains("target")) {
sb.append(" You may choose new targets for the copies.");
}
sb.append(")\r\n");
}
*/
* if (keyword.startsWith("Storm")) { if
* (sb.toString().endsWith("\r\n\r\n")) {
* sb.delete(sb.lastIndexOf("\r\n"), sb.lastIndexOf("\r\n") + 3); }
* sb.append(
* "Storm (When you cast this spell, copy it for each spell cast before it this turn."
* ); if (sb.toString().contains("Target") ||
* sb.toString().contains("target")) {
* sb.append(" You may choose new targets for the copies."); }
* sb.append(")\r\n"); }
*/
if (keyword.contains("Replicate") && !sb.toString().contains("you paid its replicate cost.")) {
if (sb.toString().endsWith("\r\n\r\n")) {
sb.delete(sb.lastIndexOf("\r\n"), sb.lastIndexOf("\r\n") + 3);
@@ -2807,7 +2807,8 @@ public class Card extends GameEntity implements Comparable<Card> {
sb.append("Remove CARDNAME from your deck before playing if you're not playing for ante.\r\n");
}
if (keyword.equals("Rebound")) {
sb.append(keyword).append("(If you cast this spell from your hand, exile it as it resolves. At the beginning of your next upkeep, you may cast this card from exile without paying its mana cost.)\r\n");
sb.append(keyword)
.append("(If you cast this spell from your hand, exile it as it resolves. At the beginning of your next upkeep, you may cast this card from exile without paying its mana cost.)\r\n");
}
}
return sb;
@@ -3085,7 +3086,6 @@ public class Card extends GameEntity implements Comparable<Card> {
public final ArrayList<SpellAbility> getAllSpellAbilities() {
final ArrayList<SpellAbility> res = new ArrayList<SpellAbility>();
final String curState = this.curCharacteristics;
for (final String key : this.characteristicsMap.keySet()) {
res.addAll(this.getState(key).getSpellAbility());
}
@@ -5624,8 +5624,9 @@ public class Card extends GameEntity implements Comparable<Card> {
/**
* Removes the all extrinsic keyword.
*
* @param s the s
*
* @param s
* the s
*/
public void removeAllExtrinsicKeyword(final String s) {
final ArrayList<String> strings = new ArrayList<String>();
@@ -6956,8 +6957,8 @@ public class Card extends GameEntity implements Comparable<Card> {
}
} else if (property.startsWith("controllerWasDealtDamageByThisTurn")) {
if (!(source.dealtDmgToHumanThisTurn && this.getController().isPlayer(AllZone.getHumanPlayer()))
&& !(source.dealtDmgToComputerThisTurn && this.getController().isPlayer(
AllZone.getComputerPlayer()))) {
&& !(source.dealtDmgToComputerThisTurn && this.getController()
.isPlayer(AllZone.getComputerPlayer()))) {
return false;
}
} else if (property.startsWith("wasDealtDamageThisTurn")) {
@@ -7022,7 +7023,7 @@ public class Card extends GameEntity implements Comparable<Card> {
} else if (property.startsWith("lowestCMC")) {
final CardList list = AllZoneUtil.getCreaturesInPlay();
for (final Card crd : list) {
if (!crd.isLand() && !crd.isImmutable() && crd.getCMC() < this.getCMC()) {
if (!crd.isLand() && !crd.isImmutable() && (crd.getCMC() < this.getCMC())) {
return false;
}
}
@@ -7194,8 +7195,8 @@ public class Card extends GameEntity implements Comparable<Card> {
}
} else if (property.equals("hasActivatedAbilityWithTapCost")) {
boolean hasIt = false;
for (SpellAbility sa : this.getSpellAbilities()) {
if (sa.isAbility() && sa.getPayCosts() != null && sa.getPayCosts().getTap()) {
for (final SpellAbility sa : this.getSpellAbilities()) {
if (sa.isAbility() && (sa.getPayCosts() != null) && sa.getPayCosts().getTap()) {
hasIt = true;
}
}
@@ -7217,14 +7218,14 @@ public class Card extends GameEntity implements Comparable<Card> {
return false;
}
} else if (property.startsWith("wasCastFrom")) {
String strZone = property.substring(11);
Zone realZone = Constant.Zone.smartValueOf(strZone);
final String strZone = property.substring(11);
final Zone realZone = Constant.Zone.smartValueOf(strZone);
if (realZone != this.getCastFrom()) {
return false;
}
} else if (property.startsWith("wasNotCastFrom")) {
String strZone = property.substring(14);
Zone realZone = Constant.Zone.smartValueOf(strZone);
final String strZone = property.substring(14);
final Zone realZone = Constant.Zone.smartValueOf(strZone);
if (realZone == this.getCastFrom()) {
return false;
}
@@ -7379,7 +7380,7 @@ public class Card extends GameEntity implements Comparable<Card> {
*/
public final boolean sharesCreatureTypeWith(final Card c1) {
for (String type : this.getType()) {
for (final String type : this.getType()) {
if (type.equals("AllCreatureTypes") && c1.hasACreatureType()) {
return true;
}
@@ -7401,7 +7402,7 @@ public class Card extends GameEntity implements Comparable<Card> {
*/
public final boolean sharesTypeWith(final Card c1) {
for (String type : this.getType()) {
for (final String type : this.getType()) {
if (c1.isType(type)) {
return true;
}
@@ -7417,7 +7418,7 @@ public class Card extends GameEntity implements Comparable<Card> {
* @return a boolean.
*/
public final boolean hasACreatureType() {
for (String type : this.getType()) {
for (final String type : this.getType()) {
if (CardUtil.isACreatureType(type)) {
return true;
}
@@ -8124,8 +8125,8 @@ public class Card extends GameEntity implements Comparable<Card> {
*/
@Override
public final int replaceDamage(final int damageIn, final Card source, final boolean isCombat) {
//Replacement effects
HashMap<String, Object> repParams = new HashMap<String, Object>();
// Replacement effects
final HashMap<String, Object> repParams = new HashMap<String, Object>();
repParams.put("Event", "DamageDone");
repParams.put("Affected", this);
repParams.put("DamageSource", source);
@@ -8216,8 +8217,7 @@ public class Card extends GameEntity implements Comparable<Card> {
}
if (source.hasKeyword("Deathtouch") && this.isCreature()) {
AllZone.getGameAction().destroy(this);
}
else if (AllZoneUtil.isCardInPlay(this) && !wither) {
} else if (AllZoneUtil.isCardInPlay(this) && !wither) {
this.damage += damageToAdd;
}
@@ -8734,7 +8734,7 @@ public class Card extends GameEntity implements Comparable<Card> {
/**
* Gets the replacement effects.
*
*
* @return the replacement effects
*/
public ArrayList<ReplacementEffect> getReplacementEffects() {
@@ -8743,40 +8743,44 @@ public class Card extends GameEntity implements Comparable<Card> {
/**
* Sets the replacement effects.
*
* @param res the new replacement effects
*
* @param res
* the new replacement effects
*/
public void setReplacementEffects(ArrayList<ReplacementEffect> res) {
public void setReplacementEffects(final ArrayList<ReplacementEffect> res) {
this.getCharacteristics().getReplacementEffects().clear();
for (ReplacementEffect replacementEffect : res) {
addReplacementEffect(replacementEffect);
for (final ReplacementEffect replacementEffect : res) {
this.addReplacementEffect(replacementEffect);
}
}
/**
* Adds the replacement effect.
*
* @param replacementEffect the rE
*
* @param replacementEffect
* the rE
*/
public void addReplacementEffect(ReplacementEffect replacementEffect) {
ReplacementEffect replacementEffectCopy = replacementEffect.getCopy();
public void addReplacementEffect(final ReplacementEffect replacementEffect) {
final ReplacementEffect replacementEffectCopy = replacementEffect.getCopy();
replacementEffectCopy.setHostCard(this);
this.getCharacteristics().getReplacementEffects().add(replacementEffectCopy);
}
/**
* Returns what zone this card was cast from (from what zone it was moved to the stack).
* Returns what zone this card was cast from (from what zone it was moved to
* the stack).
*
* @return the castFrom
*/
public Zone getCastFrom() {
return castFrom;
return this.castFrom;
}
/**
* @param castFrom0 the castFrom to set
* @param castFrom0
* the castFrom to set
*/
public void setCastFrom(Zone castFrom0) {
public void setCastFrom(final Zone castFrom0) {
this.castFrom = castFrom0;
}

View File

@@ -60,48 +60,48 @@ import forge.view.FView;
* @version $Id$
*/
public class CardReader implements Runnable {
// NOPMD by Braids on 8/18/11 10:55
// PM
private static final String CARD_FILE_DOT_EXTENSION = ".txt"; // NOPMD by
// Braids on
// 8/18/11
// 11:04 PM
private static final String CARD_FILE_DOT_EXTENSION = ".txt";
// Braids on
// 8/18/11
// 11:04 PM
/** Default charset when loading from files. */
public static final String DEFAULT_CHARSET_NAME = "US-ASCII"; // NOPMD by
// Braids on
// 8/18/11
// 10:54 PM
public static final String DEFAULT_CHARSET_NAME = "US-ASCII";
// Braids on
// 8/18/11
// 10:54 PM
/** Regex that matches a single hyphen (-) or space. */
public static final Pattern HYPHEN_OR_SPACE = Pattern.compile("[ -]");
/** Regex for punctuation that we omit from card file names. */
public static final Pattern PUNCTUATION_TO_ZAP = Pattern.compile("[,'\"]"); // NOPMD
// by
// Braids
// on
// 8/18/11
// 10:54
// PM
public static final Pattern PUNCTUATION_TO_ZAP = Pattern.compile("[,'\"]");
// by
// Braids
// on
// 8/18/11
// 10:54
// PM
/** Regex that matches two or more underscores (_). */
public static final Pattern MULTIPLE_UNDERSCORES = Pattern.compile("__+"); // NOPMD
// by
// Braids
// on
// 8/18/11
// 10:54
// PM
public static final Pattern MULTIPLE_UNDERSCORES = Pattern.compile("__+");
// by
// Braids
// on
// 8/18/11
// 10:54
// PM
/** Special value for estimatedFilesRemaining. */
protected static final int UNKNOWN_NUMBER_OF_FILES_REMAINING = -1; // NOPMD
// by
// Braids
// on
// 8/18/11
// 10:54
// PM
protected static final int UNKNOWN_NUMBER_OF_FILES_REMAINING = -1;
// by
// Braids
// on
// 8/18/11
// 10:54
// PM
private transient Map<String, Card> mapToFill;
private transient List<CardRules> listRulesToFill;
@@ -113,12 +113,13 @@ public class CardReader implements Runnable {
private transient Enumeration<? extends ZipEntry> zipEnum;
private transient long estimatedFilesRemaining = // NOPMD by Braids on
CardReader.// 8/18/11 10:56 PM
private transient long estimatedFilesRemaining = CardReader.// 8/18/11 10:56
// PM
UNKNOWN_NUMBER_OF_FILES_REMAINING;
private transient Iterable<File> findNonDirsIterable; // NOPMD by Braids on
// 8/18/11 10:56 PM
private transient Iterable<File> findNonDirsIterable;
// 8/18/11 10:56 PM
/**
* Instantiates a new card reader.
@@ -168,13 +169,13 @@ public class CardReader implements Runnable {
public CardReader(final File theCardsFolder, final Map<String, Card> theMapToFill,
final List<CardRules> listRules2Fill, final boolean useZip) {
if (theMapToFill == null) {
throw new NullPointerException("theMapToFill must not be null."); // NOPMD
// by
// Braids
// on
// 8/18/11
// 10:53
// PM
throw new NullPointerException("theMapToFill must not be null.");
// by
// Braids
// on
// 8/18/11
// 10:53
// PM
}
this.mapToFill = theMapToFill;
// These read data for lightweight classes.
@@ -182,14 +183,13 @@ public class CardReader implements Runnable {
this.rulesReader = new CardRulesReader();
if (!theCardsFolder.exists()) {
throw new RuntimeException(// NOPMD by Braids on 8/18/11 10:53 PM
"CardReader : constructor error -- file not found -- filename is "
+ theCardsFolder.getAbsolutePath());
throw new RuntimeException("CardReader : constructor error -- file not found -- filename is "
+ theCardsFolder.getAbsolutePath());
}
if (!theCardsFolder.isDirectory()) {
throw new RuntimeException(// NOPMD by Braids on 8/18/11 10:53 PM
"CardReader : constructor error -- not a directory -- " + theCardsFolder.getAbsolutePath());
throw new RuntimeException("CardReader : constructor error -- not a directory -- "
+ theCardsFolder.getAbsolutePath());
}
this.cardsfolder = theCardsFolder;
@@ -201,15 +201,11 @@ public class CardReader implements Runnable {
try {
this.zip = new ZipFile(zipFile);
} catch (final Exception exn) {
System.err.println("Error reading zip file \"" // NOPMD by
// Braids on
// 8/18/11 10:53
// PM
+ zipFile.getAbsolutePath()
+ "\": "
+ exn
+ ". "
+ "Defaulting to txt files in \""
System.err.println("Error reading zip file \""
// Braids on
// 8/18/11 10:53
// PM
+ zipFile.getAbsolutePath() + "\": " + exn + ". " + "Defaulting to txt files in \""
+ theCardsFolder.getAbsolutePath() + "\".");
}
@@ -371,13 +367,13 @@ public class CardReader implements Runnable {
return line;
} catch (final Exception ex) {
ErrorViewer.showError(ex);
throw new RuntimeException("CardReader : readLine(Card) error", ex); // NOPMD
// by
// Braids
// on
// 8/18/11
// 10:53
// PM
throw new RuntimeException("CardReader : readLine(Card) error", ex);
// by
// Braids
// on
// 8/18/11
// 10:53
// PM
}
} // readLine(BufferedReader)
@@ -406,8 +402,8 @@ public class CardReader implements Runnable {
this.rulesReader.parseLine(line);
if (line.isEmpty()) {
// Ignore empty lines.
} else if (line.charAt(0) == '#') { // NOPMD by Braids on
// 8/18/11 10:59 PM
} else if (line.charAt(0) == '#') {
// 8/18/11 10:59 PM
// no need to do anything, this indicates a comment line
} else if (line.startsWith("Name:")) {
final String value = line.substring(5);
@@ -477,8 +473,8 @@ public class CardReader implements Runnable {
card.addReplacementEffect(ReplacementHandler.parseReplacement(value, card));
} else if (line.startsWith("SetInfo:")) {
final String value = line.substring("SetInfo:".length());
card.addSet(new SetInfo(value)); // NOPMD by Braids on
// 8/18/11 11:08 PM
card.addSet(new SetInfo(value));
// 8/18/11 11:08 PM
} else if (line.equals("ALTERNATE")) {
String mode;
if (card.isFlip()) {
@@ -517,14 +513,14 @@ public class CardReader implements Runnable {
} finally {
try {
reader.close();
} catch (final IOException ignored) { // NOPMD by Braids on 8/18/11
// 11:08
} catch (final IOException ignored) {
// 11:08
// PM
}
try {
inputStreamReader.close();
} catch (final IOException ignored) { // NOPMD by Braids on 8/18/11
// 11:08
} catch (final IOException ignored) {
// 11:08
// PM
}
}
@@ -563,13 +559,13 @@ public class CardReader implements Runnable {
return this.loadCard(fileInputStream);
} catch (final FileNotFoundException ex) {
ErrorViewer.showError(ex, "File \"%s\" exception", pathToTxtFile.getAbsolutePath());
throw new RuntimeException(// NOPMD by Braids on 8/18/11 10:53 PM
"CardReader : run error -- file exception -- filename is " + pathToTxtFile.getPath(), ex);
throw new RuntimeException("CardReader : run error -- file exception -- filename is "
+ pathToTxtFile.getPath(), ex);
} finally {
try {
fileInputStream.close();
} catch (final IOException ignored) { // NOPMD by Braids on 8/18/11
// 11:08
} catch (final IOException ignored) {
// 11:08
// PM
}
}
@@ -590,15 +586,15 @@ public class CardReader implements Runnable {
return this.loadCard(zipInputStream);
} catch (final IOException exn) {
throw new RuntimeException(exn); // NOPMD by Braids on 8/18/11 10:53
// PM
throw new RuntimeException(exn);
// PM
} finally {
try {
if (zipInputStream != null) {
zipInputStream.close();
}
} catch (final IOException ignored) { // NOPMD by Braids on 8/18/11
// 11:08
} catch (final IOException ignored) {
// 11:08
// PM
}
}
@@ -654,10 +650,10 @@ public class CardReader implements Runnable {
*
* @return a new Card instance having that name, or null if not found
*/
public final Card findCard(final String canonicalASCIIName) { // NOPMD by
// Braids on
// 8/18/11
// 11:08 PM
public final Card findCard(final String canonicalASCIIName) {
// Braids on
// 8/18/11
// 11:08 PM
UtilFunctions.checkNotNull("canonicalASCIIName", canonicalASCIIName);
final String cardFilePath = this.toMostLikelyPath(canonicalASCIIName);

View File

@@ -131,7 +131,7 @@ public class GameAction {
lastKnownInfo = c;
copied = c;
} else {
String state = c.getCurState();
final String state = c.getCurState();
AllZone.getTriggerHandler().suppressMode("Transformed");
if (c.isInAlternateState()) {
c.setState("Original");
@@ -242,11 +242,9 @@ public class GameAction {
if (zone.is(Zone.Stack)) {
c.setCastFrom(prev.getZoneType());
}
else if (prev == null) {
} else if (prev == null) {
c.setCastFrom(null);
}
else if (!(zone.is(Zone.Battlefield) && prev.is(Zone.Stack))) {
} else if (!(zone.is(Zone.Battlefield) && prev.is(Zone.Stack))) {
c.setCastFrom(null);
}
@@ -321,8 +319,7 @@ public class GameAction {
final PlayerZone oldBattlefield = AllZone.getZoneOf(c);
final PlayerZone newBattlefield = c.getController().getZone(oldBattlefield.getZoneType());
if ((oldBattlefield == null) || (newBattlefield == null)
|| oldBattlefield.equals(newBattlefield)) {
if ((oldBattlefield == null) || (newBattlefield == null) || oldBattlefield.equals(newBattlefield)) {
return;
}
@@ -870,7 +867,7 @@ public class GameAction {
boolean checkAgain = false;
checkStaticAbilities();
this.checkStaticAbilities();
final CardList list = AllZoneUtil.getCardsIn(Zone.Battlefield);
Card c;
@@ -1295,16 +1292,21 @@ public class GameAction {
}
/**
* Constructor for new game allowing card lists to be put
* into play immediately, and life totals to be adjusted,
* for computer and human.
* Constructor for new game allowing card lists to be put into play
* immediately, and life totals to be adjusted, for computer and human.
*
* @param humanDeck &emsp; {@link forge.deck.Deck} object.
* @param computerDeck &emsp; {@link forge.deck.Deck} object.
* @param human &emsp; {@link forge.CardList} object.
* @param computer &emsp; {@link forge.CardList} object.
* @param humanLife &emsp; int.
* @param computerLife &emsp; int.
* @param humanDeck
* &emsp; {@link forge.deck.Deck} object.
* @param computerDeck
* &emsp; {@link forge.deck.Deck} object.
* @param human
* &emsp; {@link forge.CardList} object.
* @param computer
* &emsp; {@link forge.CardList} object.
* @param humanLife
* &emsp; int.
* @param computerLife
* &emsp; int.
*/
public final void newGame(final Deck humanDeck, final Deck computerDeck, final CardList human,
final CardList computer, final int humanLife, final int computerLife) {
@@ -1334,8 +1336,10 @@ public class GameAction {
/**
* The default constructor for a new game.
*
* @param humanDeck &emsp; {@link forge.deck.Deck} object.
* @param computerDeck &emsp; {@link forge.deck.Deck} object.
* @param humanDeck
* &emsp; {@link forge.deck.Deck} object.
* @param computerDeck
* &emsp; {@link forge.deck.Deck} object.
*/
public final void newGame(final Deck humanDeck, final Deck computerDeck) {
// AllZone.getComputer() = new ComputerAI_Input(new
@@ -1348,12 +1352,12 @@ public class GameAction {
this.actuateGame(humanDeck, computerDeck);
}
/**
/**
* This must be separated from the newGame method since life totals and
* player details could be adjusted before the game is started.
*
* That process (also cleanup and observer updates) should be done in
* newGame, then when all is ready, call this function.
* That process (also cleanup and observer updates) should be done in
* newGame, then when all is ready, call this function.
*/
private void actuateGame(final Deck humanDeck, final Deck computerDeck) {
this.canShowWinLose = true;
@@ -1478,8 +1482,7 @@ public class GameAction {
}
if (hAnteRemoved.size() > 0) {
final StringBuilder sb = new StringBuilder(
"The following ante cards were removed from the human's deck:\n");
final StringBuilder sb = new StringBuilder("The following ante cards were removed from the human's deck:\n");
for (int i = 0; i < hAnteRemoved.size(); i++) {
sb.append(hAnteRemoved.get(i));
if (((i % 4) == 0) && (i > 0)) {
@@ -1543,10 +1546,10 @@ public class GameAction {
if (Singletons.getModel().getPreferences().isPlayForAnte()) {
final String nl = System.getProperty("line.separator");
final StringBuilder msg = new StringBuilder();
for (Player p : AllZone.getPlayersInGame()) {
CardList lib = p.getCardsIn(Zone.Library);
for (final Player p : AllZone.getPlayersInGame()) {
final CardList lib = p.getCardsIn(Zone.Library);
Card ante;
if (lib.size() > 0 && lib.getNotType("Basic").size() > 1) {
if ((lib.size() > 0) && (lib.getNotType("Basic").size() > 1)) {
ante = CardUtil.getRandom(lib.toArray());
while (ante.isBasicLand()) {
ante = CardUtil.getRandom(lib.toArray());
@@ -1557,7 +1560,7 @@ public class GameAction {
throw new RuntimeException(p + " library is empty.");
}
AllZone.getGameLog().add("Ante", p + " anted " + ante, 0);
moveTo(Zone.Ante, ante);
this.moveTo(Zone.Ante, ante);
msg.append(p.getName()).append(" ante: ").append(ante).append(nl);
}
JOptionPane.showConfirmDialog(null, msg, "Ante", JOptionPane.OK_CANCEL_OPTION);
@@ -1574,8 +1577,9 @@ public class GameAction {
AllZone.getInputControl().setInput(new InputMulligan());
PhaseHandler.setGameBegins(1);
AllZone.getGameLog().add("Turn", "Turn " + AllZone.getPhaseHandler().getTurn()
+ " (" + AllZone.getPhaseHandler().getPlayerTurn() + ")", 0);
AllZone.getGameLog().add("Turn",
"Turn " + AllZone.getPhaseHandler().getTurn() + " (" + AllZone.getPhaseHandler().getPlayerTurn() + ")",
0);
} // newGame()
// this is where the computer cheats
@@ -1922,7 +1926,8 @@ public class GameAction {
final SpellAbility flashback = sa.copy();
flashback.setFlashBackAbility(true);
// there is a flashback cost (and not the cards cost)
// there is a flashback cost (and not the cards
// cost)
if (!keyword.equals("Flashback")) {
final Cost fbCost = new Cost(keyword.substring(10), c.getName(), false);
flashback.setPayCosts(fbCost);
@@ -1936,7 +1941,7 @@ public class GameAction {
if (c.hasStartOfKeyword("May be played without paying its mana cost")) {
final SpellAbility newSA = sa.copy();
final Cost cost = new Cost("", c.getName(), false);
for (CostPart part : newSA.getPayCosts().getCostParts()) {
for (final CostPart part : newSA.getPayCosts().getCostParts()) {
if (!(part instanceof CostMana)) {
cost.getCostParts().add(part);
}

View File

@@ -435,7 +435,7 @@ public final class AbilityFactoryCopy {
copy.setCloneOrigin(hostCard);
sa.getSourceCard().addClone(copy);
crds[i] = copy;
AllZone.getTriggerHandler().clearSuppression("Transformed");
}

View File

@@ -22,7 +22,6 @@ import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import forge.AllZone;
import forge.AllZoneUtil;
import forge.Card;
import forge.CardList;
@@ -207,7 +206,6 @@ public class AbilityFactorySetState {
final boolean remChanged = abilityFactory.getMapParams().containsKey("RememberChanged");
for (final Card tgt : tgtCards) {
if (abilityFactory.getAbTgt() != null) {
if (!tgt.canBeTargetedBy(sa)) {

View File

@@ -196,7 +196,7 @@ public abstract class AbstractCardFactory implements CardFactoryInterface {
}
in.setState(curState);
out.setState(curState);
AllZone.getTriggerHandler().clearSuppression("Transformed");
}
@@ -714,141 +714,121 @@ public abstract class AbstractCardFactory implements CardFactoryInterface {
} // *************** END ************ END **************************
// *************** START *********** START **************************
/*else if (cardName.equals("Aluren")) {
final Ability ability1 = new Ability(card, "0") {
@Override
public void resolve() {
final PlayerZone hand = AllZone.getHumanPlayer().getZone(Constant.Zone.Hand);
if (hand.size() == 0) {
return;
}
final CardList creatures = new CardList();
for (int i = 0; i < hand.size(); i++) {
if (hand.get(i).isCreature() && (CardUtil.getConvertedManaCost(hand.get(i).getManaCost()) <= 3)) {
creatures.add(hand.get(i));
}
}
if (creatures.size() == 0) {
return;
}
final Object o = GuiUtils.getChoiceOptional("Select target creature to play", creatures.toArray());
if (o != null) {
final Card c = (Card) o;
AllZone.getStack().add(c.getSpellPermanent());
}
}
@Override
public boolean canPlayAI() {
return false;
}
@Override
public boolean canPlay() {
return (AllZone.getZoneOf(card).is(Constant.Zone.Battlefield));
} // canPlay()
}; // SpellAbility ability1
final StringBuilder sb = new StringBuilder();
sb.append("Any player may play creature cards with converted mana cost 3 or less without ");
sb.append("paying their mana cost any time he or she could play an instant.");
ability1.setDescription(sb.toString());
ability1.setStackDescription("Aluren - Play creature with converted manacost 3 or less for free.");
ability1.getRestrictions().setAnyPlayer(true);
card.addSpellAbility(ability1);
} // *************** END ************ END **************************
// *************** START *********** START **************************
else if (cardName.equals("Volrath's Dungeon")) {
final Cost dungeonCost = new Cost("Discard<1/Card>", cardName, true);
final Target dungeonTgt = new Target(card, card + " - Select target player", "Player".split(","));
final SpellAbility dungeon = new AbilityActivated(card, dungeonCost, dungeonTgt) {
private static final long serialVersionUID = 334033015590321821L;
@Override
public void chooseTargetAI() {
this.setTargetPlayer(AllZone.getHumanPlayer());
}
@Override
public void resolve() {
final Player target = this.getTargetPlayer();
final CardList targetHand = target.getCardsIn(Zone.Hand);
if (targetHand.size() == 0) {
return;
}
if (target.isHuman()) {
final Object discard = GuiUtils.getChoice("Select Card to place on top of library.",
targetHand.toArray());
final Card card = (Card) discard;
AllZone.getGameAction().moveToLibrary(card);
} else if (target.isComputer()) {
AllZone.getComputerPlayer().handToLibrary(1, "Top");
}
}
@Override
public boolean canPlayAI() {
return !AllZone.getComputerPlayer().getZone(Zone.Hand).isEmpty()
&& !AllZone.getHumanPlayer().getZone(Zone.Hand).isEmpty() && super.canPlay();
}
}; // SpellAbility dungeon
final Cost bailCost = new Cost("PayLife<5>", cardName, true);
final SpellAbility bail = new AbilityActivated(card, bailCost, null) {
private static final long serialVersionUID = -8990402917139817175L;
@Override
public void resolve() {
AllZone.getGameAction().destroy(card);
}
@Override
public boolean canPlay() {
return super.canPlay();
}
@Override
public boolean canPlayAI() {
return card.getController().isHuman() && (AllZone.getComputerPlayer().getLife() >= 9)
&& super.canPlay() && !AllZone.getComputerPlayer().getZone(Zone.Hand).isEmpty();
}
}; // SpellAbility pay bail
final StringBuilder sbd = new StringBuilder();
sbd.append("Discard a card: ");
sbd.append("Target player puts a card from his or her hand on top of his or her library. ");
sbd.append("Activate this ability only any time you could cast a sorcery.");
dungeon.setDescription(sbd.toString());
dungeon.setStackDescription("CARDNAME - Target player chooses a card in hand and puts on top of library.");
dungeon.getRestrictions().setSorcerySpeed(true);
bail.getRestrictions().setAnyPlayer(true);
bail.getRestrictions().setPlayerTurn(true);
final StringBuilder sbb = new StringBuilder();
sbb.append("Pay 5 Life: Destroy Volrath's Dungeon. ");
sbb.append("Any player may activate this ability but only during his or her turn.");
bail.setDescription(sbb.toString());
bail.setStackDescription("Destroy CARDNAME.");
card.addSpellAbility(dungeon);
card.addSpellAbility(bail);
} */ // *************** END ************ END **************************
/*
* else if (cardName.equals("Aluren")) { final Ability ability1 = new
* Ability(card, "0") {
*
* @Override public void resolve() { final PlayerZone hand =
* AllZone.getHumanPlayer().getZone(Constant.Zone.Hand);
*
* if (hand.size() == 0) { return; }
*
* final CardList creatures = new CardList();
*
* for (int i = 0; i < hand.size(); i++) { if (hand.get(i).isCreature()
* && (CardUtil.getConvertedManaCost(hand.get(i).getManaCost()) <= 3)) {
* creatures.add(hand.get(i)); } }
*
* if (creatures.size() == 0) { return; }
*
* final Object o =
* GuiUtils.getChoiceOptional("Select target creature to play",
* creatures.toArray()); if (o != null) { final Card c = (Card) o;
* AllZone.getStack().add(c.getSpellPermanent()); }
*
* }
*
* @Override public boolean canPlayAI() { return false;
*
* }
*
* @Override public boolean canPlay() { return
* (AllZone.getZoneOf(card).is(Constant.Zone.Battlefield)); } //
* canPlay() }; // SpellAbility ability1
*
* final StringBuilder sb = new StringBuilder(); sb.append(
* "Any player may play creature cards with converted mana cost 3 or less without "
* ); sb.append(
* "paying their mana cost any time he or she could play an instant.");
* ability1.setDescription(sb.toString());
*
* ability1.setStackDescription(
* "Aluren - Play creature with converted manacost 3 or less for free."
* ); ability1.getRestrictions().setAnyPlayer(true);
* card.addSpellAbility(ability1); } // *************** END ************
* END **************************
*
* // *************** START *********** START **************************
* else if (cardName.equals("Volrath's Dungeon")) {
*
* final Cost dungeonCost = new Cost("Discard<1/Card>", cardName, true);
* final Target dungeonTgt = new Target(card, card +
* " - Select target player", "Player".split(","));
*
* final SpellAbility dungeon = new AbilityActivated(card, dungeonCost,
* dungeonTgt) { private static final long serialVersionUID =
* 334033015590321821L;
*
* @Override public void chooseTargetAI() {
* this.setTargetPlayer(AllZone.getHumanPlayer()); }
*
* @Override public void resolve() { final Player target =
* this.getTargetPlayer(); final CardList targetHand =
* target.getCardsIn(Zone.Hand);
*
* if (targetHand.size() == 0) { return; }
*
* if (target.isHuman()) { final Object discard =
* GuiUtils.getChoice("Select Card to place on top of library.",
* targetHand.toArray());
*
* final Card card = (Card) discard;
* AllZone.getGameAction().moveToLibrary(card); } else if
* (target.isComputer()) { AllZone.getComputerPlayer().handToLibrary(1,
* "Top"); } }
*
* @Override public boolean canPlayAI() { return
* !AllZone.getComputerPlayer().getZone(Zone.Hand).isEmpty() &&
* !AllZone.getHumanPlayer().getZone(Zone.Hand).isEmpty() &&
* super.canPlay(); }
*
* }; // SpellAbility dungeon
*
* final Cost bailCost = new Cost("PayLife<5>", cardName, true); final
* SpellAbility bail = new AbilityActivated(card, bailCost, null) {
* private static final long serialVersionUID = -8990402917139817175L;
*
* @Override public void resolve() {
* AllZone.getGameAction().destroy(card); }
*
* @Override public boolean canPlay() { return super.canPlay(); }
*
* @Override public boolean canPlayAI() { return
* card.getController().isHuman() &&
* (AllZone.getComputerPlayer().getLife() >= 9) && super.canPlay() &&
* !AllZone.getComputerPlayer().getZone(Zone.Hand).isEmpty(); }
*
* }; // SpellAbility pay bail
*
* final StringBuilder sbd = new StringBuilder();
* sbd.append("Discard a card: "); sbd.append(
* "Target player puts a card from his or her hand on top of his or her library. "
* ); sbd.append(
* "Activate this ability only any time you could cast a sorcery.");
* dungeon.setDescription(sbd.toString()); dungeon.setStackDescription(
* "CARDNAME - Target player chooses a card in hand and puts on top of library."
* ); dungeon.getRestrictions().setSorcerySpeed(true);
*
* bail.getRestrictions().setAnyPlayer(true);
* bail.getRestrictions().setPlayerTurn(true); final StringBuilder sbb =
* new StringBuilder();
* sbb.append("Pay 5 Life: Destroy Volrath's Dungeon. "); sbb.append(
* "Any player may activate this ability but only during his or her turn."
* ); bail.setDescription(sbb.toString());
* bail.setStackDescription("Destroy CARDNAME.");
*
* card.addSpellAbility(dungeon); card.addSpellAbility(bail); }
*/// *************** END ************ END **************************
// *************** START *********** START **************************
else if (cardName.equals("Mox Diamond")) {
@@ -1300,7 +1280,6 @@ public abstract class AbstractCardFactory implements CardFactoryInterface {
card.addSpellAbility(ability);
} // *************** END ************ END **************************
// *************** START *********** START **************************
else if (cardName.equals("Temporal Aperture")) {
/*
@@ -1530,8 +1509,7 @@ public abstract class AbstractCardFactory implements CardFactoryInterface {
@Override
public void resolve() {
if (card.getController().isComputer()) {
final CardList cards = AllZoneUtil.getCardsIn(Constant.Zone.Battlefield)
.getType("Artifact");
final CardList cards = AllZoneUtil.getCardsIn(Constant.Zone.Battlefield).getType("Artifact");
if (!cards.isEmpty()) {
copyTarget[0] = CardFactoryUtil.getBestAI(cards);
}
@@ -1539,9 +1517,9 @@ public abstract class AbstractCardFactory implements CardFactoryInterface {
if (copyTarget[0] != null) {
Card cloned;
AllZone.getTriggerHandler().suppressMode("Transformed");
cloned = cfact.getCard(copyTarget[0].getState("Original").getName(), card.getOwner());
card.addAlternateState("Cloner");
card.switchStates("Original", "Cloner");

View File

@@ -541,7 +541,7 @@ public class CardFactoryCreatures {
CardList list = AllZoneUtil.getCardsIn(Zone.Battlefield);
list = list.getValidCards("Card.Other+YouCtrl".split(","), card.getController(), card);
for (Card c : list) {
for (final Card c : list) {
c.addController(opp);
}
} // resolve()
@@ -1231,10 +1231,10 @@ public class CardFactoryCreatures {
final SpellAbility spell = new SpellPermanent(card) {
private static final long serialVersionUID = -11489323313L;
/*@Override
public boolean canPlayAI() {
return super.canPlay() && (5 <= (ComputerUtil.getAvailableMana().size() - 2));
}*/
/*
* @Override public boolean canPlayAI() { return super.canPlay()
* && (5 <= (ComputerUtil.getAvailableMana().size() - 2)); }
*/
@Override
public void resolve() {
@@ -2140,7 +2140,7 @@ public class CardFactoryCreatures {
if (copyTarget[0] != null) {
Card cloned;
AllZone.getTriggerHandler().suppressMode("Transformed");
cloned = cfact.getCard(copyTarget[0].getState("Original").getName(), card.getOwner());
@@ -2179,7 +2179,7 @@ public class CardFactoryCreatures {
} else {
card.setFlip(false);
}
AllZone.getTriggerHandler().clearSuppression("Transformed");
}
@@ -2592,7 +2592,8 @@ public class CardFactoryCreatures {
};
final Cost abCost = new Cost("R W U", cardName, true);
final Target permanent = new Target(card, "Select target permanent you control", "Permanent.YouCtrl".split(","));
final Target permanent = new Target(card, "Select target permanent you control",
"Permanent.YouCtrl".split(","));
final AbilityActivated ability = new AbilityActivated(card, abCost, permanent) {
private static final long serialVersionUID = 3818522482220103914L;
@@ -2613,11 +2614,11 @@ public class CardFactoryCreatures {
ability.setStackDescription(sb.toString());
card.addSpellAbility(ability);
}
// *************** START *********** START **************************
// *************** START *********** START **************************
else if (cardName.equals("Bazaar Trader")) {
final Target player = new Target(card, "Select target player", "Player".split(","));
final AbilitySub sub = new AbilitySub(card, player) {
private static final long serialVersionUID = -8926222902424944054L;
@@ -2641,7 +2642,8 @@ public class CardFactoryCreatures {
};
final Cost abCost = new Cost("T", cardName, true);
final Target permanent = new Target(card, "Select target artifact, creature, or land you control", "Artifact.YouCtrl,Creature.YouCtrl,Land.YouCtrl".split(","));
final Target permanent = new Target(card, "Select target artifact, creature, or land you control",
"Artifact.YouCtrl,Creature.YouCtrl,Land.YouCtrl".split(","));
final AbilityActivated ability = new AbilityActivated(card, abCost, permanent) {
private static final long serialVersionUID = 3818522482440103914L;

View File

@@ -23,7 +23,6 @@ import java.util.Map;
import forge.AllZone;
import forge.AllZoneUtil;
import forge.Card;
import forge.CardList;
import forge.Command;
@@ -306,10 +305,10 @@ public class TriggerHandler {
}
final Player playerAP = AllZone.getPhaseHandler().getPlayerTurn();
if(playerAP == null)
{
//This should only happen outside of games, so it's safe to just abort.
if (playerAP == null) {
// This should only happen outside of games, so it's safe to just
// abort.
return;
}
@@ -1009,7 +1008,8 @@ public class TriggerHandler {
regtrig.getHostCard().getName()));
buildQuestion.append(")\r\n");
if (sa[0].getTriggeringObjects().containsKey("Attacker")) {
buildQuestion.append("[Attacker: " + sa[0].getTriggeringObjects().get("Attacker") + "]");
buildQuestion
.append("[Attacker: " + sa[0].getTriggeringObjects().get("Attacker") + "]");
}
if (!GameActionUtil.showYesNoDialog(regtrig.getHostCard(), buildQuestion.toString())) {
return;

View File

@@ -331,8 +331,7 @@ public class SealedDeck {
public boolean addCard(final Card c) {
final ArrayList<AbilityMana> maList = c.getManaAbility();
for (int j = 0; j < maList.size(); j++) {
if (maList.get(j).canProduce(aiDC.mana1)
|| maList.get(j).canProduce(aiDC.mana2)
if (maList.get(j).canProduce(aiDC.mana1) || maList.get(j).canProduce(aiDC.mana2)
|| maList.get(j).isAnyMana()) {
return true;
}
@@ -433,7 +432,9 @@ public class SealedDeck {
final Deck aiDeck = new Deck(GameType.Sealed);
for (i = 0; i < deck.size(); i++) {
if(deck.get(i).getName().equals("Plains") || deck.get(i).getName().equals("Island") || deck.get(i).getName().equals("Swamp") || deck.get(i).getName().equals("Mountain") || deck.get(i).getName().equals("Forest")) {
if (deck.get(i).getName().equals("Plains") || deck.get(i).getName().equals("Island")
|| deck.get(i).getName().equals("Swamp") || deck.get(i).getName().equals("Mountain")
|| deck.get(i).getName().equals("Forest")) {
System.out.println("Heyo!");
}
aiDeck.addMain(deck.get(i).getName() + "|" + deck.get(i).getCurSetCode());

View File

@@ -1,243 +1,243 @@
/*
* Forge: Play Magic: the Gathering.
* Copyright (C) 2011 Forge Team
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package forge.model;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.nio.charset.Charset;
import java.util.jar.Attributes;
import java.util.jar.JarFile;
import java.util.jar.Manifest;
/**
* Provides access to information about the current version and build ID.
*/
public class BuildInfo {
/** Exception-free means of getting the ASCII Charset. */
public static final Charset US_ASCII_CHARSET = Charset.forName("US-ASCII");
/** Convenience for file.separator. */
/*
* private static final String FILE_SEP =
* System.getProperty("file.separator");
*/
/** Convenience for path.separator. */
/*
* private static final String PATH_SEP =
* System.getProperty("path.separator");
*/
/*
* private static final Pattern FORGE_JAR_REGEX_2G = // NOPMD by Braids on
* 8/12/11 10:18 AM Pattern.compile("^(.*" + Pattern.quote(FILE_SEP) + ")?"
* + Pattern.quote("forge-") + "([^" + Pattern.quote(FILE_SEP) +
* Pattern.quote(PATH_SEP) + "]*)" + Pattern.quote("-with-dependencies.jar")
* + "$", Pattern.CASE_INSENSITIVE);
*/
private transient String pathToForgeJar;
/**
* Construct a standard BuildInfo object.
*
* Package access is intentional for unit testing.
*
* @see forge.model.FModel#getBuildInfo()
*/
BuildInfo() {
// empty
}
/**
* Unit-testable constructor which allows a specific jar file to be set.
*
* Dependency injection! Relax, this won't hurt a bit.
*
* @param pathToMockJarFile
* where to find the mock Forge jar
*/
public BuildInfo(final String pathToMockJarFile) {
this.pathToForgeJar = pathToMockJarFile;
}
/**
* Get the current build ID for Forge.
*
* @return a String representing the build identifier, or null if we could
* not determine the value.
*/
public final String getBuildID() {
String manifestResult = "0000";
String[] manifestResultArray;
String result = "0000";
final String version = this.getVersion();
manifestResultArray = version.split("r");
manifestResult = manifestResultArray[manifestResultArray.length - 1];
if (manifestResult == null) {
result = "0000";
} else {
result = manifestResult;
}
return result;
}
/**
* Get the current version of Forge.
*
* @return a String representing the version specifier, or "SVN" if unknown.
*/
public final String getVersion() {
String manifestResult;
String result;
manifestResult = BuildInfo.class.getPackage().getImplementationVersion();
if (manifestResult == null) {
result = "SVN";
} else {
result = manifestResult;
}
return result;
}
/**
* Fetch an attribute from the Forge main jar's manifest.
*
* @param manifestAttrName
* the name of the attribute you want from the manifest
* @return the attribute's value, which may be empty or null
* @throws IOException
* if a (unique) Forge jar could not be found
*/
protected final String getManifestAttribute(final String manifestAttrName) throws IOException {
String result = null;
JarFile jar = null;
InputStream manifestStream = null;
try {
if (this.pathToForgeJar == null) {
// We're definitely not unit testing. Try to load from the
// currently running jar.
manifestStream = ClassLoader.getSystemResourceAsStream("META-INF/MANIFEST.MF");
final Manifest manifest = new Manifest(manifestStream);
result = this.getMainManifestAttribute(manifest, manifestAttrName);
}
/*
* if (result == null && pathToForgeJar == null) {
*
* // Try to find a unique Forge jar in the class path.
*
* final String classPath = System.getProperty("java.class.path");
* final String[] paths = classPath.split(PATH_SEP);
*
* for (String path : paths) { final Matcher matcher =
* FORGE_JAR_REGEX_2G.matcher(path);
*
* if (matcher.matches()) { if (pathToForgeJar == null) {
* pathToForgeJar = path; } else { // Error: we found more than one.
* pathToForgeJar = null; // NOPMD by Braids on 8/12/11 10:21 AM
*
* throw new MultipleForgeJarsFoundError( "Classpath = " +
* System.getProperty("java.class.path")); } } } }
*/
if ((result == null) && (this.pathToForgeJar == null)) {
throw new FileNotFoundException(
"There is nothing matching forge-*-with-dependencies.jar in the class path.");
}
if (result == null) {
jar = new JarFile(this.pathToForgeJar);
final Manifest manifest = jar.getManifest();
if (manifest == null) {
throw new IOException("Forge jar at <<" + this.pathToForgeJar + ">> has no manifest.");
}
result = this.getMainManifestAttribute(manifest, manifestAttrName);
}
} finally {
try {
manifestStream.close();
} catch (final Throwable ignored) { // NOPMD by Braids on 8/12/11
// 10:21 AM
// ignored
}
try {
jar.close();
} catch (final Throwable ignored) { // NOPMD by Braids on 8/12/11
// 10:21 AM
// ignored
}
}
return result;
}
/**
* Convience method for fetching an attribute from the main section of a
* jar's manifest.
*
* @param manifest
* the manifest that provides attributes
* @param manifestAttrName
* the name of the attribute to fetch
* @return the value of the attribute, or null if not set
*/
protected final String getMainManifestAttribute(final Manifest manifest, final String manifestAttrName) {
final Attributes atts = manifest.getMainAttributes();
return atts.getValue(manifestAttrName);
}
/**
* Generate a user-friendly string describing the version and build ID.
*
* This replaces the old system property program/version.
*
* @return a user-friendly string describing the version and build ID
*/
public final String toPrettyString() {
final String rawVersion = this.getVersion();
// final String rawBuildID = getBuildID();
String version;
if (rawVersion == null) {
version = "Unknown";
} else {
version = rawVersion;
}
/*
* String buildID; if (rawBuildID == null) { buildID = "Unknown"; } else
* { buildID = rawBuildID; }
*/
return "Forge version " + version; // ", build ID " + buildID;
}
}
/*
* Forge: Play Magic: the Gathering.
* Copyright (C) 2011 Forge Team
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package forge.model;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.nio.charset.Charset;
import java.util.jar.Attributes;
import java.util.jar.JarFile;
import java.util.jar.Manifest;
/**
* Provides access to information about the current version and build ID.
*/
public class BuildInfo {
/** Exception-free means of getting the ASCII Charset. */
public static final Charset US_ASCII_CHARSET = Charset.forName("US-ASCII");
/** Convenience for file.separator. */
/*
* private static final String FILE_SEP =
* System.getProperty("file.separator");
*/
/** Convenience for path.separator. */
/*
* private static final String PATH_SEP =
* System.getProperty("path.separator");
*/
/*
* private static final Pattern FORGE_JAR_REGEX_2G = // NOPMD by Braids on
* 8/12/11 10:18 AM Pattern.compile("^(.*" + Pattern.quote(FILE_SEP) + ")?"
* + Pattern.quote("forge-") + "([^" + Pattern.quote(FILE_SEP) +
* Pattern.quote(PATH_SEP) + "]*)" + Pattern.quote("-with-dependencies.jar")
* + "$", Pattern.CASE_INSENSITIVE);
*/
private transient String pathToForgeJar;
/**
* Construct a standard BuildInfo object.
*
* Package access is intentional for unit testing.
*
* @see forge.model.FModel#getBuildInfo()
*/
BuildInfo() {
// empty
}
/**
* Unit-testable constructor which allows a specific jar file to be set.
*
* Dependency injection! Relax, this won't hurt a bit.
*
* @param pathToMockJarFile
* where to find the mock Forge jar
*/
public BuildInfo(final String pathToMockJarFile) {
this.pathToForgeJar = pathToMockJarFile;
}
/**
* Get the current build ID for Forge.
*
* @return a String representing the build identifier, or null if we could
* not determine the value.
*/
public final String getBuildID() {
String manifestResult = "0000";
String[] manifestResultArray;
String result = "0000";
final String version = this.getVersion();
manifestResultArray = version.split("r");
manifestResult = manifestResultArray[manifestResultArray.length - 1];
if (manifestResult == null) {
result = "0000";
} else {
result = manifestResult;
}
return result;
}
/**
* Get the current version of Forge.
*
* @return a String representing the version specifier, or "SVN" if unknown.
*/
public final String getVersion() {
String manifestResult;
String result;
manifestResult = BuildInfo.class.getPackage().getImplementationVersion();
if (manifestResult == null) {
result = "SVN";
} else {
result = manifestResult;
}
return result;
}
/**
* Fetch an attribute from the Forge main jar's manifest.
*
* @param manifestAttrName
* the name of the attribute you want from the manifest
* @return the attribute's value, which may be empty or null
* @throws IOException
* if a (unique) Forge jar could not be found
*/
protected final String getManifestAttribute(final String manifestAttrName) throws IOException {
String result = null;
JarFile jar = null;
InputStream manifestStream = null;
try {
if (this.pathToForgeJar == null) {
// We're definitely not unit testing. Try to load from the
// currently running jar.
manifestStream = ClassLoader.getSystemResourceAsStream("META-INF/MANIFEST.MF");
final Manifest manifest = new Manifest(manifestStream);
result = this.getMainManifestAttribute(manifest, manifestAttrName);
}
/*
* if (result == null && pathToForgeJar == null) {
*
* // Try to find a unique Forge jar in the class path.
*
* final String classPath = System.getProperty("java.class.path");
* final String[] paths = classPath.split(PATH_SEP);
*
* for (String path : paths) { final Matcher matcher =
* FORGE_JAR_REGEX_2G.matcher(path);
*
* if (matcher.matches()) { if (pathToForgeJar == null) {
* pathToForgeJar = path; } else { // Error: we found more than one.
* pathToForgeJar = null; // NOPMD by Braids on 8/12/11 10:21 AM
*
* throw new MultipleForgeJarsFoundError( "Classpath = " +
* System.getProperty("java.class.path")); } } } }
*/
if ((result == null) && (this.pathToForgeJar == null)) {
throw new FileNotFoundException(
"There is nothing matching forge-*-with-dependencies.jar in the class path.");
}
if (result == null) {
jar = new JarFile(this.pathToForgeJar);
final Manifest manifest = jar.getManifest();
if (manifest == null) {
throw new IOException("Forge jar at <<" + this.pathToForgeJar + ">> has no manifest.");
}
result = this.getMainManifestAttribute(manifest, manifestAttrName);
}
} finally {
try {
manifestStream.close();
} catch (final Throwable ignored) {
// 10:21 AM
// ignored
}
try {
jar.close();
} catch (final Throwable ignored) {
// 10:21 AM
// ignored
}
}
return result;
}
/**
* Convience method for fetching an attribute from the main section of a
* jar's manifest.
*
* @param manifest
* the manifest that provides attributes
* @param manifestAttrName
* the name of the attribute to fetch
* @return the value of the attribute, or null if not set
*/
protected final String getMainManifestAttribute(final Manifest manifest, final String manifestAttrName) {
final Attributes atts = manifest.getMainAttributes();
return atts.getValue(manifestAttrName);
}
/**
* Generate a user-friendly string describing the version and build ID.
*
* This replaces the old system property program/version.
*
* @return a user-friendly string describing the version and build ID
*/
public final String toPrettyString() {
final String rawVersion = this.getVersion();
// final String rawBuildID = getBuildID();
String version;
if (rawVersion == null) {
version = "Unknown";
} else {
version = rawVersion;
}
/*
* String buildID; if (rawBuildID == null) { buildID = "Unknown"; } else
* { buildID = rawBuildID; }
*/
return "Forge version " + version; // ", build ID " + buildID;
}
}

View File

@@ -83,22 +83,23 @@ public class FModel {
try {
this.setPreferences(new ForgePreferences("forge.preferences"));
} catch (final Exception exn) {
// NOPMD by Braids on 8/13/11 8:21 PM
// Log.error("Error loading preferences: " + exn);
throw new RuntimeException(exn);
}
// TODO these should be set along with others all at the same time, not here
// TODO these should be set along with others all at the same time, not
// here
Constant.Runtime.MILL[0] = this.preferences.isMillingLossCondition();
Constant.Runtime.DEV_MODE[0] = this.preferences.isDeveloperMode();
Constant.Runtime.UPLOAD_DRAFT[0] = this.preferences.isUploadDraftAI();
Constant.Runtime.RANDOM_FOIL[0] = this.preferences.isRandCFoil();
/////////
// ///////
// Instantiate pinger
// TODO is this in the right place?
final HttpUtil pinger = new HttpUtil();
String url = ForgeProps.getProperty(NewConstants.CARDFORGE_URL) + "/draftAI/ping.php";
final String url = ForgeProps.getProperty(NewConstants.CARDFORGE_URL) + "/draftAI/ping.php";
if (pinger.getURL(url).equals("pong")) {
Constant.Runtime.NET_CONN[0] = true;
} else {
@@ -129,7 +130,7 @@ public class FModel {
System.setErr(this.oldSystemErr);
try {
this.logFileStream.close();
} catch (final IOException e) { // NOPMD by Braids on 8/12/11 10:25 AM
} catch (final IOException e) {
// ignored
}
}

View File

@@ -21,7 +21,6 @@ import javax.swing.SwingUtilities;
import net.slightlymagic.braids.util.UtilFunctions;
import net.slightlymagic.braids.util.progress_monitor.BraidsProgressMonitor;
import forge.AllZone;
import forge.ComputerAIGeneral;
import forge.ComputerAIInput;
@@ -56,10 +55,10 @@ public class FView {
UtilFunctions.invokeInEventDispatchThreadAndWait(new Runnable() {
@Override
public void run() {
FView.this.splashFrame = new SplashFrame(skin);
FView.this.splashFrame = new SplashFrame(FView.this.skin);
}
});
// NOPMD by Braids on 8/18/11 11:37 PM
SwingUtilities.invokeLater(new Runnable() {
@Override
public void run() {
@@ -87,11 +86,14 @@ public class FView {
/** @return FSkin */
public FSkin getSkin() {
return skin;
return this.skin;
}
/** @param skin0 &emsp; FSkin */
public void setSkin(FSkin skin0) {
/**
* @param skin0
* &emsp; FSkin
*/
public void setSkin(final FSkin skin0) {
this.skin = skin0;
}
@@ -109,18 +111,18 @@ public class FView {
if (!this.splashFrame.getSplashHasBeenClosed()) {
try {
// NOPMD by Braids on 8/7/11 1:07
SwingUtilities.invokeLater(new Runnable() {
@Override
public void run() {
AllZone.getInputControl().setComputer(new ComputerAIInput(new ComputerAIGeneral()));
skin.loadFontAndImages();
FView.this.skin.loadFontAndImages();
CardFaceSymbols.loadImages();
Constant.Runtime.setGameType(GameType.Constructed);
GuiTopLevel g = new GuiTopLevel();
final GuiTopLevel g = new GuiTopLevel();
AllZone.setDisplay(g);
g.getController().changeState(FControl.HOME_SCREEN);
g.pack();

View File

@@ -55,22 +55,22 @@ public final class UtilFunctions {
NullPointerException exn = null;
if (paramName == null) {
exn = new NullPointerException(); // NOPMD by Braids on 8/18/11
// 11:19 PM
exn = new NullPointerException();
// 11:19 PM
} else {
exn = new NullPointerException(paramName + " must not be null"); // NOPMD
// by
// Braids
// on
// 8/18/11
// 11:19
// PM
exn = new NullPointerException(paramName + " must not be null");
// by
// Braids
// on
// 8/18/11
// 11:19
// PM
}
// Doctor the exception to appear to come from the caller.
final StackTraceElement[] trace = exn.getStackTrace();
final int len = getSliceLength(trace, 1);
exn.setStackTrace(slice(new StackTraceElement[len], trace, 1));
final int len = UtilFunctions.getSliceLength(trace, 1);
exn.setStackTrace(UtilFunctions.slice(new StackTraceElement[len], trace, 1));
throw exn;
}
@@ -86,25 +86,25 @@ public final class UtilFunctions {
* the Runnable to run
* @see javax.swing.SwingUtilities#invokeLater(Runnable)
*/
public static void invokeInEventDispatchThreadAndWait(final Runnable proc) { // NOPMD
// by
// Braids
// on
// 8/18/11
// 11:19
// PM
public static void invokeInEventDispatchThreadAndWait(final Runnable proc) {
// by
// Braids
// on
// 8/18/11
// 11:19
// PM
if (SwingUtilities.isEventDispatchThread()) {
// Just run in the current thread.
proc.run();
} else {
try {
SwingUtilities.invokeAndWait(proc);
} catch (InterruptedException exn) {
throw new RuntimeException(exn); // NOPMD by Braids on 8/18/11
// 11:19 PM
} catch (InvocationTargetException exn) {
throw new RuntimeException(exn); // NOPMD by Braids on 8/18/11
// 11:19 PM
} catch (final InterruptedException exn) {
throw new RuntimeException(exn);
// 11:19 PM
} catch (final InvocationTargetException exn) {
throw new RuntimeException(exn);
// 11:19 PM
}
}
}
@@ -168,16 +168,16 @@ public final class UtilFunctions {
}
if (dstArray == null) {
throw new NullPointerException(); // NOPMD by Braids on 8/18/11
// 11:19 PM
throw new NullPointerException();
// 11:19 PM
}
if (srcArray == null) {
throw new NullPointerException(); // NOPMD by Braids on 8/18/11
// 11:19 PM
throw new NullPointerException();
// 11:19 PM
}
final int resultLength = getSliceLength(srcArray, startIndex);
final int resultLength = UtilFunctions.getSliceLength(srcArray, startIndex);
if (dstArray.length != resultLength) {
throw new ArrayIndexOutOfBoundsException("First parameter must have length " + resultLength
@@ -186,7 +186,7 @@ public final class UtilFunctions {
int srcIx = startIndex;
for (int dstIx = 0; dstIx < resultLength && srcIx < srcArray.length; dstIx++, srcIx++) {
for (int dstIx = 0; (dstIx < resultLength) && (srcIx < srcArray.length); dstIx++, srcIx++) {
dstArray[dstIx] = srcArray[srcIx];
}
@@ -258,13 +258,13 @@ public final class UtilFunctions {
*/
public static <T> T checkNullOrNotInstance(final T goodInstance, final Object obj) {
if (goodInstance == null) {
throw new NullPointerException("first parameter must not be null"); // NOPMD
// by
// Braids
// on
// 8/18/11
// 11:19
// PM
throw new NullPointerException("first parameter must not be null");
// by
// Braids
// on
// 8/18/11
// 11:19
// PM
}
@SuppressWarnings("unchecked")
@@ -330,13 +330,13 @@ public final class UtilFunctions {
*/
public static <T> void smartRemoveDuplicatesAndNulls(final List<T> list) {
// Get rid of pesky leading nulls.
smartRemoveDuplicatesAndNullsHelper(list, 0, null);
UtilFunctions.smartRemoveDuplicatesAndNullsHelper(list, 0, null);
for (int earlierIx = 0; earlierIx < list.size(); earlierIx++) {
for (int laterIx = earlierIx + 1; laterIx < list.size(); laterIx++) {
final T itemAtEarlierIx = list.get(earlierIx);
smartRemoveDuplicatesAndNullsHelper(list, laterIx, itemAtEarlierIx);
UtilFunctions.smartRemoveDuplicatesAndNullsHelper(list, laterIx, itemAtEarlierIx);
}
}
@@ -360,9 +360,9 @@ public final class UtilFunctions {
*/
public static <T> void smartRemoveDuplicatesAndNullsHelper(final List<T> list, final int startIx,
final T objSeenPreviously) {
while (startIx < list.size()
&& (list.get(startIx) == null || list.get(startIx) == objSeenPreviously || list.get(startIx).equals(
objSeenPreviously))) {
while ((startIx < list.size())
&& ((list.get(startIx) == null) || (list.get(startIx) == objSeenPreviously) || list.get(startIx)
.equals(objSeenPreviously))) {
final int lastItemIx = list.size() - 1;
// Overwrite the item at laterIx with the one at the end,

View File

@@ -136,7 +136,7 @@ public class CardReaderTest {
/**
* Test_ read card_run_nonzip.
*/
@Test(groups = { "slow" })
@Test(groups = { "slow" }, enabled = false)
public final void test_ReadCard_run_nonzip() {
final Map<String, Card> map = new HashMap<String, Card>(2 * CardReaderTest.ESTIMATED_CARDS_IN_FOLDER);
final File cardsfolder = ForgeProps.getFile(NewConstants.CARDSFOLDER);
@@ -149,7 +149,7 @@ public class CardReaderTest {
/**
* Test_ read card_run_zip.
*/
@Test(groups = { "slow" })
@Test(groups = { "slow" }, enabled = false)
public final void test_ReadCard_run_zip() {
final Map<String, Card> map = new HashMap<String, Card>(2 * CardReaderTest.ESTIMATED_CARDS_IN_FOLDER);
final File cardsfolder = ForgeProps.getFile(NewConstants.CARDSFOLDER);

View File

@@ -33,9 +33,9 @@ import forge.view.Main;
public class CardFactoryTest {
/** The default time to allow a test to run before TestNG ignores it. */
public static final int DEFAULT_TEST_TIMEOUT_MS = 5000; // NOPMD by Braids
// on 8/18/11 11:43
// PM
public static final int DEFAULT_TEST_TIMEOUT_MS = 5000;
// on 8/18/11 11:43
// PM
private transient CardFactoryInterface factory;
@@ -53,7 +53,7 @@ public class CardFactoryTest {
* the correct owner.
*/
@Test(enabled = false, timeOut = CardFactoryTest.DEFAULT_TEST_TIMEOUT_MS)
public final void test_getCard_1() { // NOPMD by Braids on 8/18/11 11:39 PM
public final void test_getCard_1() {
final Card card = this.factory.getCard("Arc-Slogger", null);
Assert.assertNotNull(card, "card is not null");
Assert.assertNull(card.getOwner(), "card has correct owner");
@@ -63,27 +63,27 @@ public class CardFactoryTest {
* Make sure the method throws an exception when it's supposed to.
*/
@Test(enabled = false, timeOut = CardFactoryTest.DEFAULT_TEST_TIMEOUT_MS)
public final void test_getRandomCombinationWithoutRepetition_tooLarge() { // NOPMD
// by
// Braids
// on
// 8/18/11
// 11:39
// PM
public final void test_getRandomCombinationWithoutRepetition_tooLarge() {
// by
// Braids
// on
// 8/18/11
// 11:39
// PM
BraidsAssertFunctions.assertThrowsException(IllegalArgumentException.class, new ClumsyRunnable() {
@Override
public void run() throws Exception { // NOPMD by Braids on 8/18/11
// 11:40 PM
public void run() throws Exception {
// 11:40 PM
CardFactoryTest.this.factory.getRandomCombinationWithoutRepetition(CardFactoryTest.this.factory.size());
}
});
BraidsAssertFunctions.assertThrowsException(IllegalArgumentException.class, new ClumsyRunnable() {
@Override
public void run() throws Exception { // NOPMD by Braids on 8/18/11
// 11:40 PM
final int largeDivisorForRandomCombo = 4; // NOPMD by Braids on
// 8/18/11 11:41 PM
public void run() throws Exception {
// 11:40 PM
final int largeDivisorForRandomCombo = 4;
// 8/18/11 11:41 PM
CardFactoryTest.this.factory.getRandomCombinationWithoutRepetition(CardFactoryTest.this.factory.size()
/ largeDivisorForRandomCombo);
}
@@ -97,15 +97,15 @@ public class CardFactoryTest {
* default.
*/
@Test(enabled = false, timeOut = CardFactoryTest.DEFAULT_TEST_TIMEOUT_MS)
public final void test_getRandomCombinationWithoutRepetition_oneTenth() { // NOPMD
// by
// Braids
// on
// 8/18/11
// 11:39
// PM
public final void test_getRandomCombinationWithoutRepetition_oneTenth() {
// by
// Braids
// on
// 8/18/11
// 11:39
// PM
this.factory = new PreloadingCardFactory(ForgeProps.getFile(NewConstants.CARDSFOLDER));
final int divisor = 10; // NOPMD by Braids on 8/18/11 11:41 PM
final int divisor = 10;
final CardList actual = this.factory.getRandomCombinationWithoutRepetition(this.factory.size() / divisor);
final Set<String> cardNames = new TreeSet<String>();

View File

@@ -20,21 +20,22 @@ public class BuildInfoTest {
/** System property name for the class path. */
private static final String JAVA_CLASS_PATH = "java.class.path";
/** Manifest attribute name for the Build ID. */
private static final String MF_ATTR_NAME_BUILD = "Implementation-Build"; // NOPMD
// by
// Braids
// on
// 8/12/11
// 10:29
// AM
private static final String MF_ATTR_NAME_BUILD = "Implementation-Build";
// by
// Braids
// on
// 8/12/11
// 10:29
// AM
/** Manifest attribute name for the version string. */
private static final String MF_ATTR_NAME_VERSION = "Implementation-Version"; // NOPMD
// by
// Braids
// on
// 8/12/11
// 10:29
// AM
private static final String MF_ATTR_NAME_VERSION = "Implementation-Version";
// by
// Braids
// on
// 8/12/11
// 10:29
// AM
/**
* Test BuildInfo using a mock jar file.
@@ -43,10 +44,10 @@ public class BuildInfoTest {
* rarely
*/
@Test(enabled = false)
public final void test_BuildInfo_mockJar() throws IOException { // NOPMD by
// Braids on
// 8/12/11
// 10:26 AM
public final void test_BuildInfo_mockJar() throws IOException {
// Braids on
// 8/12/11
// 10:26 AM
File jarAsFile = null;
try {
jarAsFile = this.makeTmpJarWithManifest("BuildInfoTest-", ".jar", new String[] {
@@ -72,13 +73,13 @@ public class BuildInfoTest {
* indirectly
*/
@Test(enabled = false)
public final void test_BuildInfo_oneJarInCP() throws IOException { // NOPMD
// by
// Braids
// on
// 8/12/11
// 10:26
// AM
public final void test_BuildInfo_oneJarInCP() throws IOException {
// by
// Braids
// on
// 8/12/11
// 10:26
// AM
final String origClassPath = System.getProperty(BuildInfoTest.JAVA_CLASS_PATH);
File jarAsFile = null;
@@ -111,13 +112,13 @@ public class BuildInfoTest {
* indirectly
*/
@Test(enabled = false)
public final void test_BuildInfo_twoJarsInCP() throws IOException { // NOPMD
// by
// Braids
// on
// 8/12/11
// 10:26
// AM
public final void test_BuildInfo_twoJarsInCP() throws IOException {
// by
// Braids
// on
// 8/12/11
// 10:26
// AM
final String origClassPath = System.getProperty(BuildInfoTest.JAVA_CLASS_PATH);
File jarAsFile1 = null;
File jarAsFile2 = null;
@@ -138,8 +139,8 @@ public class BuildInfoTest {
BraidsAssertFunctions.assertThrowsException(MultipleForgeJarsFoundError.class, new ClumsyRunnable() {
@Override
public void run() throws Exception { // NOPMD by Braids on
// 8/12/11 10:29 AM
public void run() throws Exception {
// 8/12/11 10:29 AM
info.getBuildID();
}
});

View File

@@ -51,17 +51,17 @@ public class FModelTest {
* if something is really wrong
*/
@Test
public final void test_ctor_close_ctor() throws FileNotFoundException { // NOPMD
// by
// Braids
// on
// 8/12/11
// 10:36
// AM
public final void test_ctor_close_ctor() throws FileNotFoundException {
// by
// Braids
// on
// 8/12/11
// 10:36
// AM
Assert.assertNotNull(this.model, "model is not null");
this.model.close();
System.err.println("log test"); // NOPMD by Braids on 8/12/11 10:36 AM
System.err.println("log test");
this.model = new FModel(null);
Assert.assertNotNull(this.model, "model is not null");
@@ -87,13 +87,13 @@ public class FModelTest {
* if something is really wrong
*/
@Test
public final void test_getBuildID() throws FileNotFoundException { // NOPMD
// by
// Braids
// on
// 8/12/11
// 10:36
// AM
public final void test_getBuildID() throws FileNotFoundException {
// by
// Braids
// on
// 8/12/11
// 10:36
// AM
// Just test for an unexpected exception.
this.model.getBuildInfo().getBuildID();
}