Skip to content

Commit 08be775

Browse files
authored
Merge branch 'master' into cleanup-lobbyplayer
2 parents 92fdf75 + 954aa7e commit 08be775

38 files changed

+305
-356
lines changed

forge-ai/src/main/java/forge/ai/AiCostDecision.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818
import forge.util.Aggregates;
1919
import forge.util.TextUtil;
2020
import forge.util.collect.FCollectionView;
21-
import org.apache.commons.lang3.ObjectUtils;
2221

2322
import java.util.*;
2423

@@ -583,7 +582,7 @@ protected int removeCounter(GameEntityCounterTable table, List<Card> prefs, Coun
583582
@Override
584583
public PaymentDecision visit(CostRemoveAnyCounter cost) {
585584
final int c = cost.getAbilityAmount(ability);
586-
final Card originalHost = ObjectUtils.getIfNull(ability.getOriginalHost(), source);
585+
final Card originalHost = Objects.requireNonNullElse(ability.getOriginalHost(), source);
587586

588587
if (c <= 0) {
589588
return null;

forge-ai/src/main/java/forge/ai/ComputerUtil.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2422,7 +2422,7 @@ public static String chooseSomeType(Player ai, String kindOfType, SpellAbility s
24222422
chosen = ComputerUtilCard.getMostProminentType(list, validTypes);
24232423
} else if (logic.equals("MostNeededType")) {
24242424
// Choose a type that is in the deck, but not in hand or on the battlefield
2425-
final List<String> basics = new ArrayList<>(CardType.Constant.BASIC_TYPES);
2425+
final Collection<String> basics = CardType.getBasicTypes();
24262426
CardCollectionView presentCards = CardCollection.combine(ai.getCardsIn(ZoneType.Battlefield), ai.getCardsIn(ZoneType.Hand));
24272427
CardCollectionView possibleCards = ai.getAllCards();
24282428

forge-ai/src/main/java/forge/ai/ComputerUtilMana.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1299,7 +1299,7 @@ private static ListMultimap<ManaCostShard, SpellAbility> groupAndOrderToPayShard
12991299
if (ai.getManaPool().canPayForShardWithColor(shard, colorint.byteValue())) {
13001300
for (SpellAbility sa : manaAbilityMap.get(colorint)) {
13011301
if (!res.get(shard).contains(sa)) {
1302-
res.get(shard).add(sa);
1302+
res.put(shard, sa);
13031303
}
13041304
}
13051305
}
@@ -1627,7 +1627,7 @@ private static ListMultimap<Integer, SpellAbility> groupSourcesByManaColor(final
16271627
continue;
16281628
}
16291629

1630-
manaMap.get(ManaAtom.GENERIC).add(m); // add to generic source list
1630+
manaMap.put(ManaAtom.GENERIC, m); // add to generic source list
16311631

16321632
SpellAbility tail = m;
16331633
while (tail != null) {

forge-core/src/main/java/forge/card/MagicColor.java

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -135,8 +135,8 @@ public static final class Constant {
135135
/** The Basic lands. */
136136
public static final ImmutableList<String> BASIC_LANDS = ImmutableList.of("Plains", "Island", "Swamp", "Mountain", "Forest");
137137
public static final ImmutableList<String> SNOW_LANDS = ImmutableList.of("Snow-Covered Plains", "Snow-Covered Island", "Snow-Covered Swamp", "Snow-Covered Mountain", "Snow-Covered Forest");
138-
public static final String ANY_COLOR_CONVERSION = "AnyType->AnyColor";
139138

139+
public static final String ANY_COLOR_CONVERSION = "AnyType->AnyColor";
140140
public static final String ANY_TYPE_CONVERSION = "AnyType->AnyType";
141141
/**
142142
* Private constructor to prevent instantiation.
@@ -146,22 +146,24 @@ private Constant() {
146146
}
147147

148148
public enum Color implements ITranslatable {
149-
WHITE(Constant.WHITE, MagicColor.WHITE, "W", "lblWhite"),
150-
BLUE(Constant.BLUE, MagicColor.BLUE, "U", "lblBlue"),
151-
BLACK(Constant.BLACK, MagicColor.BLACK, "B", "lblBlack"),
152-
RED(Constant.RED, MagicColor.RED, "R", "lblRed"),
153-
GREEN(Constant.GREEN, MagicColor.GREEN, "G", "lblGreen"),
154-
COLORLESS(Constant.COLORLESS, MagicColor.COLORLESS, "C", "lblColorless");
149+
WHITE(Constant.WHITE, MagicColor.WHITE, "W", "Plains", "lblWhite"),
150+
BLUE(Constant.BLUE, MagicColor.BLUE, "U", "Island", "lblBlue"),
151+
BLACK(Constant.BLACK, MagicColor.BLACK, "B", "Swamp", "lblBlack"),
152+
RED(Constant.RED, MagicColor.RED, "R", "Mountain", "lblRed"),
153+
GREEN(Constant.GREEN, MagicColor.GREEN, "G", "Forest", "lblGreen"),
154+
COLORLESS(Constant.COLORLESS, MagicColor.COLORLESS, "C", null, "lblColorless");
155155

156156
private final String name, shortName, symbol;
157+
private final String basicLandType;
157158
private final String label;
158159
private final byte colormask;
159160

160-
Color(String name0, byte colormask0, String shortName, String label) {
161+
Color(String name0, byte colormask0, String shortName, String basicLandType, String label) {
161162
name = name0;
162163
colormask = colormask0;
163164
this.shortName = shortName;
164165
symbol = "{" + shortName + "}";
166+
this.basicLandType = basicLandType;
165167
this.label = label;
166168
}
167169

@@ -193,6 +195,9 @@ public String getName() {
193195
public String getShortName() {
194196
return shortName;
195197
}
198+
public String getBasicLandType() {
199+
return basicLandType;
200+
}
196201

197202
@Override
198203
public String getTranslatedName() {

forge-game/src/main/java/forge/game/Game.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,6 @@
4949
import forge.trackable.Tracker;
5050
import forge.util.*;
5151
import forge.util.collect.FCollection;
52-
import org.apache.commons.lang3.ObjectUtils;
5352
import org.apache.commons.lang3.tuple.Pair;
5453

5554
import java.util.*;
@@ -277,7 +276,7 @@ public final Card getChangeZoneLKIInfo(Card c) {
277276
if (c == null) {
278277
return null;
279278
}
280-
return ObjectUtils.defaultIfNull(changeZoneLKIInfo.get(c.getId(), c.getGameTimestamp()), c);
279+
return Objects.requireNonNullElse(changeZoneLKIInfo.get(c.getId(), c.getGameTimestamp()), c);
281280
}
282281
public final void clearChangeZoneLKIInfo() {
283282
changeZoneLKIInfo.clear();

forge-game/src/main/java/forge/game/GameEntityCounterTable.java

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
11
package forge.game;
22

33
import java.util.Map;
4+
import java.util.Objects;
45
import java.util.Optional;
56

6-
import org.apache.commons.lang3.ObjectUtils;
7-
87
import com.google.common.collect.ForwardingTable;
98
import com.google.common.collect.HashBasedTable;
109
import com.google.common.collect.Maps;
@@ -45,7 +44,7 @@ public Integer put(Player putter, GameEntity object, CounterType type, Integer v
4544
map = Maps.newHashMap();
4645
put(o, object, map);
4746
}
48-
return map.put(type, ObjectUtils.firstNonNull(map.get(type), 0) + value);
47+
return map.put(type, Objects.requireNonNullElse(map.get(type), 0) + value);
4948
}
5049

5150
public int get(Player putter, GameEntity object, CounterType type) {
@@ -54,7 +53,7 @@ public int get(Player putter, GameEntity object, CounterType type) {
5453
if (map == null || !map.containsKey(type)) {
5554
return 0;
5655
}
57-
return ObjectUtils.firstNonNull(map.get(type), 0);
56+
return Objects.requireNonNullElse(map.get(type), 0);
5857
}
5958

6059
public int totalValues() {
@@ -92,8 +91,8 @@ public Map<GameEntity, Integer> filterTable(CounterType type, String valid, Card
9291
for (Map.Entry<GameEntity, Map<Optional<Player>, Map<CounterType, Integer>>> gm : columnMap().entrySet()) {
9392
if (gm.getKey().isValid(valid, host.getController(), host, sa)) {
9493
for (Map<CounterType, Integer> cm : gm.getValue().values()) {
95-
Integer old = ObjectUtils.firstNonNull(result.get(gm.getKey()), 0);
96-
Integer v = ObjectUtils.firstNonNull(cm.get(type), 0);
94+
Integer old = Objects.requireNonNullElse(result.get(gm.getKey()), 0);
95+
Integer v = Objects.requireNonNullElse(cm.get(type), 0);
9796
if (old + v > 0) {
9897
result.put(gm.getKey(), old + v);
9998
}

forge-game/src/main/java/forge/game/StaticEffect.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -265,17 +265,17 @@ final CardCollectionView remove(Map<StaticAbilityLayer, Set<Card>> affectedPerLa
265265
if (layers.contains(StaticAbilityLayer.ABILITIES)) {
266266
// remove keywords
267267
boolean abilitiesChanged = false;
268-
if (hasParam("AddKeyword") || hasParam("RemoveKeyword") || hasParam("RemoveLandTypes")
269-
|| hasParam("ShareRememberedKeywords") || hasParam("RemoveAllAbilities")) {
268+
if (hasParam("AddKeyword") || hasParam("RemoveKeyword")
269+
|| hasParam("ShareRememberedKeywords") || hasParam("RemoveAllAbilities") || hasParam("RemoveNonManaAbilities")) {
270270
abilitiesChanged |= affectedCard.removeChangedCardKeywords(getTimestamp(), ability.getId(), false);
271271
}
272272

273273
// remove abilities
274274
if (hasParam("AddAbility") || hasParam("GainsAbilitiesOf")
275275
|| hasParam("GainsAbilitiesOfDefined") || hasParam("GainsTriggerAbsOf")
276276
|| hasParam("AddTrigger") || hasParam("AddStaticAbility")
277-
|| hasParam("AddReplacementEffect") || hasParam("RemoveAllAbilities")
278-
|| hasParam("RemoveLandTypes")) {
277+
|| hasParam("AddReplacementEffect") || hasParam("RemoveAllAbilities") || hasParam("RemoveNonManaAbilities")
278+
) {
279279
abilitiesChanged |= affectedCard.removeChangedCardTraits(getTimestamp(), ability.getId());
280280
}
281281

forge-game/src/main/java/forge/game/ability/AbilityUtils.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,6 @@
3838
import forge.util.collect.FCollectionView;
3939
import io.sentry.Breadcrumb;
4040
import io.sentry.Sentry;
41-
import org.apache.commons.lang3.ObjectUtils;
4241
import org.apache.commons.lang3.StringUtils;
4342
import org.apache.commons.lang3.tuple.Pair;
4443

@@ -665,7 +664,7 @@ else if (calcX[0].startsWith("TriggerCount")) {
665664
count = (Integer) to;
666665
}
667666

668-
val = doXMath(ObjectUtils.firstNonNull(count, 0), m, card, ability);
667+
val = doXMath(Objects.requireNonNullElse(count, 0), m, card, ability);
669668
}
670669
else if (calcX[0].startsWith("ReplaceCount")) {
671670
// ReplaceCount is similar to a regular Count, but just
@@ -675,7 +674,7 @@ else if (calcX[0].startsWith("ReplaceCount")) {
675674
final String m = CardFactoryUtil.extractOperators(calcX[1]);
676675
final Integer count = (Integer) root.getReplacingObject(AbilityKey.fromString(l[0]));
677676

678-
val = doXMath(ObjectUtils.firstNonNull(count, 0), m, card, ability);
677+
val = doXMath(Objects.requireNonNullElse(count, 0), m, card, ability);
679678
} else { // these ones only for handling lists
680679
Iterable<Card> list = null;
681680
if (calcX[0].startsWith("Targeted")) {

forge-game/src/main/java/forge/game/ability/effects/AnimateEffectBase.java

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
import java.util.EnumSet;
2121
import java.util.List;
2222
import java.util.Set;
23+
import java.util.function.Predicate;
2324

2425
import com.google.common.collect.Lists;
2526

@@ -29,6 +30,7 @@
2930
import forge.card.RemoveType;
3031
import forge.card.mana.ManaCost;
3132
import forge.card.mana.ManaCostParser;
33+
import forge.game.CardTraitBase;
3234
import forge.game.Game;
3335
import forge.game.ability.AbilityFactory;
3436
import forge.game.ability.AbilityUtils;
@@ -74,8 +76,12 @@ public static void doAnimate(final Card c, final SpellAbility sa, final Integer
7476
if (sa.hasParam("RemoveEnchantmentTypes"))
7577
remove.add(RemoveType.EnchantmentTypes);
7678

77-
boolean removeNonManaAbilities = sa.hasParam("RemoveNonManaAbilities");
78-
boolean removeAll = sa.hasParam("RemoveAllAbilities");
79+
Predicate<CardTraitBase> removeAbilities = null;
80+
if (sa.hasParam("RemoveAllAbilities")) {
81+
removeAbilities = e -> true;
82+
} else if (sa.hasParam("RemoveNonManaAbilities")) {
83+
removeAbilities = Predicate.not(CardTraitBase::isManaAbility);
84+
}
7985

8086
if (sa.hasParam("RememberAnimated")) {
8187
source.addRemembered(c);
@@ -106,11 +112,11 @@ public static void doAnimate(final Card c, final SpellAbility sa, final Integer
106112
c.addChangedCardTypes(addType, removeType, addAllCreatureTypes, remove, timestamp, 0, true, false);
107113
}
108114

109-
if (!keywords.isEmpty() || !removeKeywords.isEmpty() || removeAll) {
115+
if (!keywords.isEmpty() || !removeKeywords.isEmpty() || removeAbilities != null) {
110116
if (perpetual) {
111-
c.addPerpetual(new PerpetualKeywords(timestamp, keywords, removeKeywords, removeAll));
117+
c.addPerpetual(new PerpetualKeywords(timestamp, keywords, removeKeywords, removeAbilities != null));
112118
}
113-
c.addChangedCardKeywords(keywords, removeKeywords, removeAll, timestamp, null);
119+
c.addChangedCardKeywords(keywords, removeKeywords, removeAbilities != null, timestamp, null);
114120
}
115121

116122
// do this after changing types in case it wasn't a creature before
@@ -213,11 +219,11 @@ public String getDescription() {
213219
}
214220

215221
// after unanimate to add RevertCost
216-
if (removeAll || removeNonManaAbilities
222+
if (removeAbilities != null
217223
|| !addedAbilities.isEmpty() || !removedAbilities.isEmpty() || !addedTriggers.isEmpty()
218224
|| !addedReplacements.isEmpty() || !addedStaticAbilities.isEmpty()) {
219225
CardTraitChanges changes = c.addChangedCardTraits(addedAbilities, removedAbilities, addedTriggers, addedReplacements,
220-
addedStaticAbilities, removeAll, removeNonManaAbilities, timestamp, 0);
226+
addedStaticAbilities, removeAbilities, timestamp, 0);
221227
if (perpetual) {
222228
c.addPerpetual(new PerpetualAbilities(timestamp, changes));
223229
}

forge-game/src/main/java/forge/game/ability/effects/ChangeZoneEffect.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,13 +24,13 @@
2424
import forge.game.zone.ZoneType;
2525
import forge.util.*;
2626
import forge.util.collect.FCollectionView;
27-
import org.apache.commons.lang3.ObjectUtils;
2827
import org.apache.commons.lang3.StringUtils;
2928
import org.apache.commons.lang3.tuple.Pair;
3029

3130
import java.util.Arrays;
3231
import java.util.List;
3332
import java.util.Map;
33+
import java.util.Objects;
3434
import java.util.Set;
3535

3636
public class ChangeZoneEffect extends SpellAbilityEffect {
@@ -1296,7 +1296,7 @@ else if (!origin.contains(ZoneType.Library) && !origin.contains(ZoneType.Hand)
12961296
List<ZoneType> origin = HiddenOriginChoicesMap.get(player).origin;
12971297
ZoneType destination = HiddenOriginChoicesMap.get(player).destination;
12981298
CardCollection movedCards = new CardCollection();
1299-
Player decider = ObjectUtils.firstNonNull(chooser, player);
1299+
Player decider = Objects.requireNonNullElse(chooser, player);
13001300

13011301
for (final Card c : chosenCards) {
13021302
Card movedCard;

0 commit comments

Comments
 (0)