Merge pull request #2897 from kubikrubikvkube/master

Minor improvements - string+= creation changed to StringBuilder w initial value
This commit is contained in:
ingmargoudt 2017-02-28 15:21:02 +01:00 committed by GitHub
commit df64713cbf
15 changed files with 61 additions and 81 deletions

View file

@ -38,7 +38,7 @@ public class ArrowBuilder {
private int currentHeight; private int currentHeight;
public enum Type { public enum Type {
PAIRED, SOURCE, TARGET, COMBAT, ENCHANT_PLAYERS; PAIRED, SOURCE, TARGET, COMBAT, ENCHANT_PLAYERS
} }
/** /**

View file

@ -27,6 +27,8 @@
*/ */
package mage.server.util; package mage.server.util;
import org.apache.log4j.Logger;
import java.io.File; import java.io.File;
import java.io.FileInputStream; import java.io.FileInputStream;
import java.io.InputStream; import java.io.InputStream;
@ -39,7 +41,6 @@ import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicInteger; import java.util.concurrent.atomic.AtomicInteger;
import java.util.concurrent.locks.ReadWriteLock; import java.util.concurrent.locks.ReadWriteLock;
import java.util.concurrent.locks.ReentrantReadWriteLock; import java.util.concurrent.locks.ReentrantReadWriteLock;
import org.apache.log4j.Logger;
/** /**
* Handles server messages (Messages of the Day). Reloads messages every 5 * Handles server messages (Messages of the Day). Reloads messages every 5
@ -193,7 +194,7 @@ public class ServerMessagesUtil {
// } // }
// }); // });
public void setStartDate(long milliseconds) { public void setStartDate(long milliseconds) {
this.startDate = milliseconds; startDate = milliseconds;
} }
public void incGamesStarted() { public void incGamesStarted() {

View file

@ -27,9 +27,6 @@
*/ */
package mage.cards.b; package mage.cards.b;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.UUID;
import mage.MageInt; import mage.MageInt;
import mage.abilities.Ability; import mage.abilities.Ability;
import mage.abilities.common.SimpleActivatedAbility; import mage.abilities.common.SimpleActivatedAbility;
@ -47,6 +44,10 @@ import mage.game.Game;
import mage.game.permanent.Permanent; import mage.game.permanent.Permanent;
import mage.target.common.TargetCreaturePermanent; import mage.target.common.TargetCreaturePermanent;
import java.util.ArrayList;
import java.util.Collections;
import java.util.UUID;
/** /**
* *
* @author fireshoes * @author fireshoes
@ -64,14 +65,14 @@ public class BoldwyrIntimidator extends CardImpl {
this.addAbility(new SimpleStaticAbility(Zone.BATTLEFIELD, new BoldwyrIntimidatorEffect())); this.addAbility(new SimpleStaticAbility(Zone.BATTLEFIELD, new BoldwyrIntimidatorEffect()));
// {R}: Target creature becomes a Coward until end of turn. // {R}: Target creature becomes a Coward until end of turn.
Effect effect = new BecomesCreatureTypeTargetEffect(Duration.EndOfTurn, new ArrayList<>(Arrays.asList("Coward")), true); Effect effect = new BecomesCreatureTypeTargetEffect(Duration.EndOfTurn, new ArrayList<>(Collections.singletonList("Coward")), true);
effect.setText("Target creature becomes a Coward until end of turn"); effect.setText("Target creature becomes a Coward until end of turn");
Ability ability = new SimpleActivatedAbility(Zone.BATTLEFIELD, effect, new ManaCostsImpl("{R}")); Ability ability = new SimpleActivatedAbility(Zone.BATTLEFIELD, effect, new ManaCostsImpl("{R}"));
ability.addTarget(new TargetCreaturePermanent()); ability.addTarget(new TargetCreaturePermanent());
this.addAbility(ability); this.addAbility(ability);
// {2}{R}: Target creature becomes a Warrior until end of turn. // {2}{R}: Target creature becomes a Warrior until end of turn.
effect = new BecomesCreatureTypeTargetEffect(Duration.EndOfTurn, new ArrayList<>(Arrays.asList("Warrior")), true); effect = new BecomesCreatureTypeTargetEffect(Duration.EndOfTurn, new ArrayList<>(Collections.singletonList("Warrior")), true);
effect.setText("Target creature becomes a Warrior until end of turn"); effect.setText("Target creature becomes a Warrior until end of turn");
ability = new SimpleActivatedAbility(Zone.BATTLEFIELD, effect, new ManaCostsImpl("{2}{R}")); ability = new SimpleActivatedAbility(Zone.BATTLEFIELD, effect, new ManaCostsImpl("{2}{R}"));
ability.addTarget(new TargetCreaturePermanent()); ability.addTarget(new TargetCreaturePermanent());

View file

@ -27,9 +27,6 @@
*/ */
package mage.cards.c; package mage.cards.c;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.UUID;
import mage.MageInt; import mage.MageInt;
import mage.ObjectColor; import mage.ObjectColor;
import mage.abilities.Ability; import mage.abilities.Ability;
@ -61,6 +58,10 @@ import mage.players.Player;
import mage.target.common.TargetCardInGraveyard; import mage.target.common.TargetCardInGraveyard;
import mage.target.targetpointer.FixedTarget; import mage.target.targetpointer.FixedTarget;
import java.util.ArrayList;
import java.util.Collections;
import java.util.UUID;
/** /**
* *
* @author emerald000 * @author emerald000
@ -132,7 +133,7 @@ class ChainerDementiaMasterEffect extends OneShotEffect {
ContinuousEffectImpl effect = new BecomesColorTargetEffect(ObjectColor.BLACK, Duration.WhileOnBattlefield); ContinuousEffectImpl effect = new BecomesColorTargetEffect(ObjectColor.BLACK, Duration.WhileOnBattlefield);
effect.setTargetPointer(new FixedTarget(permanent, game)); effect.setTargetPointer(new FixedTarget(permanent, game));
game.addEffect(effect, source); game.addEffect(effect, source);
effect = new BecomesCreatureTypeTargetEffect(Duration.WhileOnBattlefield, new ArrayList<>(Arrays.asList("Nightmare")), false); effect = new BecomesCreatureTypeTargetEffect(Duration.WhileOnBattlefield, new ArrayList<>(Collections.singletonList("Nightmare")), false);
effect.setTargetPointer(new FixedTarget(permanent, game)); effect.setTargetPointer(new FixedTarget(permanent, game));
game.addEffect(effect, source); game.addEffect(effect, source);
} }

View file

@ -27,7 +27,6 @@
*/ */
package mage.cards.c; package mage.cards.c;
import java.util.UUID;
import mage.abilities.Ability; import mage.abilities.Ability;
import mage.abilities.costs.Cost; import mage.abilities.costs.Cost;
import mage.abilities.costs.common.PayEnergyCost; import mage.abilities.costs.common.PayEnergyCost;
@ -49,6 +48,8 @@ import mage.players.Player;
import mage.target.TargetPermanent; import mage.target.TargetPermanent;
import mage.target.targetpointer.FixedTarget; import mage.target.targetpointer.FixedTarget;
import java.util.UUID;
/** /**
* *
* @author LevelX2 * @author LevelX2
@ -104,9 +105,10 @@ class ConfiscationCoupEffect extends OneShotEffect {
if (targetPermanent != null) { if (targetPermanent != null) {
Cost cost = new PayEnergyCost(targetPermanent.getManaCost().convertedManaCost()); Cost cost = new PayEnergyCost(targetPermanent.getManaCost().convertedManaCost());
if (cost.canPay(source, source.getSourceId(), source.getControllerId(), game)) { if (cost.canPay(source, source.getSourceId(), source.getControllerId(), game)) {
String energy = ""; int convertedManaCost = targetPermanent.getManaCost().convertedManaCost();
for (int i = 0; i < targetPermanent.getManaCost().convertedManaCost(); i++) { StringBuilder energy = new StringBuilder(convertedManaCost);
energy += "{E}"; for (int i = 0; i < convertedManaCost; i++) {
energy.append("{E}");
} }
if (controller.chooseUse(outcome, "Pay " + energy + " to get control of " + targetPermanent.getLogName() + '?', source, game)) { if (controller.chooseUse(outcome, "Pay " + energy + " to get control of " + targetPermanent.getLogName() + '?', source, game)) {
if (cost.pay(source, game, source.getSourceId(), source.getControllerId(), true)) { if (cost.pay(source, game, source.getSourceId(), source.getControllerId(), true)) {

View file

@ -27,10 +27,12 @@
*/ */
package mage.cards.c; package mage.cards.c;
import java.util.UUID;
import mage.abilities.Ability; import mage.abilities.Ability;
import mage.abilities.common.BeginningOfUpkeepTriggeredAbility; import mage.abilities.common.BeginningOfUpkeepTriggeredAbility;
import mage.abilities.costs.Cost;
import mage.abilities.costs.mana.ManaCostsImpl;
import mage.abilities.effects.OneShotEffect; import mage.abilities.effects.OneShotEffect;
import mage.abilities.effects.common.DamageEverythingEffect;
import mage.abilities.effects.common.counter.AddCountersSourceEffect; import mage.abilities.effects.common.counter.AddCountersSourceEffect;
import mage.cards.CardImpl; import mage.cards.CardImpl;
import mage.cards.CardSetInfo; import mage.cards.CardSetInfo;
@ -40,11 +42,9 @@ import mage.constants.TargetController;
import mage.counters.CounterType; import mage.counters.CounterType;
import mage.game.Game; import mage.game.Game;
import mage.game.permanent.Permanent; import mage.game.permanent.Permanent;
import mage.players.Player; import mage.players.Player;
import mage.abilities.costs.Cost;
import mage.abilities.costs.mana.ManaCostsImpl; import java.util.UUID;
import mage.abilities.effects.common.DamageEverythingEffect;
@ -93,14 +93,12 @@ class CycloneEffect extends OneShotEffect {
Player player = game.getPlayer(source.getControllerId()); Player player = game.getPlayer(source.getControllerId());
Permanent permanent = game.getPermanent(source.getSourceId()); Permanent permanent = game.getPermanent(source.getSourceId());
int total = permanent.getCounters(game).getCount(CounterType.WIND); int total = permanent.getCounters(game).getCount(CounterType.WIND);
StringBuilder greens = new StringBuilder(total);
String greens = "";
for (int i=0; i < total; i++){ for (int i=0; i < total; i++){
greens+="{G}"; greens.append("{G}");
} }
if(this.choice(game, source, player, new ManaCostsImpl(greens))){ if(this.choice(game, source, player, new ManaCostsImpl(greens.toString()))){
DamageEverythingEffect dmg = new DamageEverythingEffect(total); DamageEverythingEffect dmg = new DamageEverythingEffect(total);
dmg.apply(game, source); dmg.apply(game, source);
} else { } else {

View file

@ -27,8 +27,6 @@
*/ */
package mage.cards.e; package mage.cards.e;
import java.util.Arrays;
import java.util.UUID;
import mage.MageInt; import mage.MageInt;
import mage.abilities.common.SimpleActivatedAbility; import mage.abilities.common.SimpleActivatedAbility;
import mage.abilities.common.SimpleStaticAbility; import mage.abilities.common.SimpleStaticAbility;
@ -46,6 +44,9 @@ import mage.constants.Zone;
import mage.filter.common.FilterCreatureCard; import mage.filter.common.FilterCreatureCard;
import mage.target.common.TargetCardInHand; import mage.target.common.TargetCardInHand;
import java.util.Collections;
import java.util.UUID;
/** /**
* *
* @author LevelX2 * @author LevelX2
@ -65,7 +66,7 @@ public class ErebossEmissary extends CardImpl {
this.addAbility(new SimpleActivatedAbility(Zone.BATTLEFIELD, new ConditionalContinuousEffect( this.addAbility(new SimpleActivatedAbility(Zone.BATTLEFIELD, new ConditionalContinuousEffect(
new BoostEnchantedEffect(2, 2, Duration.EndOfTurn), new BoostEnchantedEffect(2, 2, Duration.EndOfTurn),
new BoostSourceEffect(2, 2, Duration.EndOfTurn), new BoostSourceEffect(2, 2, Duration.EndOfTurn),
new SourceHasSubtypeCondition(Arrays.asList("Aura")), new SourceHasSubtypeCondition(Collections.singletonList("Aura")),
"{this} gets +2/+2 until end of turn. If Erebos's Emissary is an Aura, enchanted creature gets +2/+2 until end of turn instead"), "{this} gets +2/+2 until end of turn. If Erebos's Emissary is an Aura, enchanted creature gets +2/+2 until end of turn instead"),
new DiscardTargetCost(new TargetCardInHand(new FilterCreatureCard())))); new DiscardTargetCost(new TargetCardInHand(new FilterCreatureCard()))));

View file

@ -27,9 +27,6 @@
*/ */
package mage.cards.o; package mage.cards.o;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.UUID;
import mage.MageInt; import mage.MageInt;
import mage.abilities.common.EntersBattlefieldControlledTriggeredAbility; import mage.abilities.common.EntersBattlefieldControlledTriggeredAbility;
import mage.abilities.costs.common.DiscardCardCost; import mage.abilities.costs.common.DiscardCardCost;
@ -51,6 +48,10 @@ import mage.filter.FilterPermanent;
import mage.filter.common.FilterControlledCreaturePermanent; import mage.filter.common.FilterControlledCreaturePermanent;
import mage.filter.predicate.permanent.AnotherPredicate; import mage.filter.predicate.permanent.AnotherPredicate;
import java.util.ArrayList;
import java.util.Collections;
import java.util.UUID;
/** /**
* *
* @author fireshoes * @author fireshoes
@ -82,7 +83,7 @@ public class OliviaMobilizedForWar extends CardImpl {
effect = new GainAbilityTargetEffect(HasteAbility.getInstance(), Duration.EndOfTurn); effect = new GainAbilityTargetEffect(HasteAbility.getInstance(), Duration.EndOfTurn);
effect.setText(", it gains haste until end of turn,"); effect.setText(", it gains haste until end of turn,");
doIfCostPaid.addEffect(effect); doIfCostPaid.addEffect(effect);
effect = new BecomesCreatureTypeTargetEffect(Duration.WhileOnBattlefield, new ArrayList<>(Arrays.asList("Vampire")), false); effect = new BecomesCreatureTypeTargetEffect(Duration.WhileOnBattlefield, new ArrayList<>(Collections.singletonList("Vampire")), false);
effect.setText("and it becomes a Vampire in addition to its other types"); effect.setText("and it becomes a Vampire in addition to its other types");
doIfCostPaid.addEffect(effect); doIfCostPaid.addEffect(effect);
this.addAbility(new EntersBattlefieldControlledTriggeredAbility(Zone.BATTLEFIELD, doIfCostPaid, filter, false, SetTargetPointer.PERMANENT, null)); this.addAbility(new EntersBattlefieldControlledTriggeredAbility(Zone.BATTLEFIELD, doIfCostPaid, filter, false, SetTargetPointer.PERMANENT, null));

View file

@ -27,20 +27,10 @@
*/ */
package mage.abilities; package mage.abilities;
import java.util.ArrayList;
import java.util.List;
import java.util.UUID;
import mage.MageObject; import mage.MageObject;
import mage.MageObjectReference; import mage.MageObjectReference;
import mage.Mana; import mage.Mana;
import mage.abilities.costs.AdjustingSourceCosts; import mage.abilities.costs.*;
import mage.abilities.costs.AlternativeSourceCosts;
import mage.abilities.costs.Cost;
import mage.abilities.costs.Costs;
import mage.abilities.costs.CostsImpl;
import mage.abilities.costs.OptionalAdditionalModeSourceCosts;
import mage.abilities.costs.OptionalAdditionalSourceCosts;
import mage.abilities.costs.VariableCost;
import mage.abilities.costs.common.TapSourceCost; import mage.abilities.costs.common.TapSourceCost;
import mage.abilities.costs.mana.ManaCost; import mage.abilities.costs.mana.ManaCost;
import mage.abilities.costs.mana.ManaCosts; import mage.abilities.costs.mana.ManaCosts;
@ -55,12 +45,7 @@ import mage.abilities.effects.common.ManaEffect;
import mage.abilities.keyword.FlashbackAbility; import mage.abilities.keyword.FlashbackAbility;
import mage.abilities.mana.ActivatedManaAbilityImpl; import mage.abilities.mana.ActivatedManaAbilityImpl;
import mage.cards.Card; import mage.cards.Card;
import mage.constants.AbilityType; import mage.constants.*;
import mage.constants.AbilityWord;
import mage.constants.EffectType;
import mage.constants.Outcome;
import mage.constants.SpellAbilityType;
import mage.constants.Zone;
import mage.game.Game; import mage.game.Game;
import mage.game.command.Emblem; import mage.game.command.Emblem;
import mage.game.events.GameEvent; import mage.game.events.GameEvent;
@ -76,6 +61,10 @@ import mage.util.ThreadLocalStringBuilder;
import mage.watchers.Watcher; import mage.watchers.Watcher;
import org.apache.log4j.Logger; import org.apache.log4j.Logger;
import java.util.ArrayList;
import java.util.List;
import java.util.UUID;
/** /**
* @author BetaSteward_at_googlemail.com * @author BetaSteward_at_googlemail.com
*/ */
@ -496,7 +485,7 @@ public abstract class AbilityImpl implements Ability {
* @return announce message * @return announce message
*/ */
protected String handleOtherXCosts(Game game, Player controller) { protected String handleOtherXCosts(Game game, Player controller) {
String announceString = null; StringBuilder announceString = new StringBuilder();
for (VariableCost variableCost : this.costs.getVariableCosts()) { for (VariableCost variableCost : this.costs.getVariableCosts()) {
if (!(variableCost instanceof VariableManaCost)) { if (!(variableCost instanceof VariableManaCost)) {
int xValue = variableCost.announceXValue(this, game); int xValue = variableCost.announceXValue(this, game);
@ -508,14 +497,10 @@ public abstract class AbilityImpl implements Ability {
variableCost.setAmount(xValue); variableCost.setAmount(xValue);
((Cost) variableCost).setPaid(); ((Cost) variableCost).setPaid();
String message = controller.getLogName() + " announces a value of " + xValue + " (" + variableCost.getActionText() + ')'; String message = controller.getLogName() + " announces a value of " + xValue + " (" + variableCost.getActionText() + ')';
if (announceString == null) { announceString.append(message);
announceString = message;
} else {
announceString = announceString + ' ' + message;
}
} }
} }
return announceString; return announceString.toString();
} }
/** /**

View file

@ -62,7 +62,7 @@ public class CantHaveMoreThanAmountCountersSourceAbility extends SimpleStaticAbi
@Override @Override
public String getRule() { public String getRule() {
return "Rasputin can't have more than " + CardUtil.numberToText(this.amount) + " " + this.counterType.getName() + " counters on it."; return "Rasputin can't have more than " + CardUtil.numberToText(this.amount) + ' ' + this.counterType.getName() + " counters on it.";
} }
@Override @Override

View file

@ -82,11 +82,11 @@ public class VariableManaCost extends ManaCostImpl implements VariableCost {
@Override @Override
public String getText() { public String getText() {
if (multiplier > 1) { if (multiplier > 1) {
String symbol = ""; StringBuilder symbol = new StringBuilder(multiplier);
for (int i = 0; i < multiplier; i++) { for (int i = 0; i < multiplier; i++) {
symbol += "{X}"; symbol.append("{X}");
} }
return symbol; return symbol.toString();
} else { } else {
return "{X}"; return "{X}";
} }

View file

@ -109,7 +109,7 @@ public class CantBeTargetedAttachedEffect extends ContinuousRuleModifyingEffectI
return staticText; return staticText;
} }
StringBuilder sb = new StringBuilder(); StringBuilder sb = new StringBuilder();
sb.append(attachmentType.verb() + " creature"); sb.append(attachmentType.verb()).append(" creature");
sb.append(" can't be the target of "); sb.append(" can't be the target of ");
sb.append(filterSource.getMessage()); sb.append(filterSource.getMessage());
if (!duration.toString().isEmpty()) { if (!duration.toString().isEmpty()) {

View file

@ -70,8 +70,7 @@ class DredgeEffect extends ReplacementEffectImpl {
public DredgeEffect(int value) { public DredgeEffect(int value) {
super(Duration.WhileInGraveyard, Outcome.ReturnToHand); super(Duration.WhileInGraveyard, Outcome.ReturnToHand);
this.amount = value; this.amount = value;
this.staticText = new StringBuilder("Dredge ").append(Integer.toString(value)) this.staticText = new StringBuilder("Dredge ").append(Integer.toString(value)).append(" <i>(If you would draw a card, instead you may put exactly ").append(value).append(" card(s) from the top of your library into your graveyard. If you do, return this card from your graveyard to your hand. Otherwise, draw a card.)</i>").toString();
.append(" <i>(If you would draw a card, instead you may put exactly " + value + " card(s) from the top of your library into your graveyard. If you do, return this card from your graveyard to your hand. Otherwise, draw a card.)</i>").toString();
} }
public DredgeEffect(final DredgeEffect effect) { public DredgeEffect(final DredgeEffect effect) {

View file

@ -5,8 +5,6 @@
*/ */
package mage.game.stack; package mage.game.stack;
import java.util.Set;
import java.util.UUID;
import mage.MageObject; import mage.MageObject;
import mage.abilities.Abilities; import mage.abilities.Abilities;
import mage.abilities.AbilitiesImpl; import mage.abilities.AbilitiesImpl;
@ -21,6 +19,9 @@ import mage.players.Player;
import mage.target.Target; import mage.target.Target;
import mage.target.TargetAmount; import mage.target.TargetAmount;
import java.util.Set;
import java.util.UUID;
/** /**
* *
* @author LevelX2 * @author LevelX2
@ -135,7 +136,7 @@ public abstract class StackObjImpl implements StackObject {
} }
if (!newTargetDescription.toString().equals(oldTargetDescription.toString()) && !game.isSimulation()) { if (!newTargetDescription.toString().equals(oldTargetDescription.toString()) && !game.isSimulation()) {
game.informPlayers(this.getLogName() + " is now " + newTargetDescription.toString()); game.informPlayers(this.getLogName() + " is now " + newTargetDescription);
} }
return true; return true;
} }

View file

@ -1,10 +1,5 @@
package mage.util; package mage.util;
import java.util.Arrays;
import java.util.HashSet;
import java.util.LinkedHashMap;
import java.util.Set;
import java.util.UUID;
import mage.MageObject; import mage.MageObject;
import mage.Mana; import mage.Mana;
import mage.ManaSymbol; import mage.ManaSymbol;
@ -12,19 +7,14 @@ import mage.abilities.Ability;
import mage.abilities.costs.mana.AlternateManaPaymentAbility; import mage.abilities.costs.mana.AlternateManaPaymentAbility;
import mage.abilities.costs.mana.ManaCost; import mage.abilities.costs.mana.ManaCost;
import mage.abilities.costs.mana.ManaSymbols; import mage.abilities.costs.mana.ManaSymbols;
import mage.abilities.mana.BasicManaAbility; import mage.abilities.mana.*;
import mage.abilities.mana.BlackManaAbility;
import mage.abilities.mana.BlueManaAbility;
import mage.abilities.mana.GreenManaAbility;
import mage.abilities.mana.ActivatedManaAbilityImpl;
import mage.abilities.mana.AnyColorManaAbility;
import mage.abilities.mana.RedManaAbility;
import mage.abilities.mana.WhiteManaAbility;
import mage.cards.Card; import mage.cards.Card;
import mage.choices.Choice; import mage.choices.Choice;
import mage.constants.ColoredManaSymbol; import mage.constants.ColoredManaSymbol;
import mage.game.Game; import mage.game.Game;
import java.util.*;
/** /**
* @author noxx * @author noxx
*/ */
@ -471,7 +461,7 @@ public final class ManaUtil {
// Combine the cost back as a mana string // Combine the cost back as a mana string
StringBuilder sb = new StringBuilder(); StringBuilder sb = new StringBuilder();
for (String s : finalCost) { for (String s : finalCost) {
sb.append('{' + s + '}'); sb.append('{').append(s).append('}');
} }
// Return the condensed string // Return the condensed string
return sb.toString(); return sb.toString();