mirror of
https://github.com/Card-Forge/forge.git
synced 2025-11-19 12:18:00 +00:00
CardRules: fix case with null tokens list (#5395)
* CardRules: fix NPE * clean up --------- Co-authored-by: tool4EvEr <tool4EvEr@192.168.0.60>
This commit is contained in:
@@ -92,6 +92,7 @@ public final class CardRules implements ICardCharacteristics {
|
||||
colorIdentity = newRules.colorIdentity;
|
||||
meldWith = newRules.meldWith;
|
||||
partnerWith = newRules.partnerWith;
|
||||
tokens = newRules.tokens;
|
||||
}
|
||||
|
||||
private static byte calculateColorIdentity(final ICardFace face) {
|
||||
@@ -386,7 +387,7 @@ public final class CardRules implements ICardCharacteristics {
|
||||
private int deltaHand;
|
||||
private int deltaLife;
|
||||
|
||||
private List<String> tokens;
|
||||
private List<String> tokens = Collections.emptyList();
|
||||
|
||||
public List<String> getTokens() {
|
||||
return tokens;
|
||||
@@ -484,7 +485,9 @@ public final class CardRules implements ICardCharacteristics {
|
||||
result.setNormalizedName(this.normalizedName);
|
||||
result.meldWith = this.meldWith;
|
||||
result.partnerWith = this.partnerWith;
|
||||
result.tokens = tokens.isEmpty() ? Collections.emptyList() : tokens;
|
||||
if (!tokens.isEmpty()) {
|
||||
result.tokens = tokens;
|
||||
}
|
||||
if (StringUtils.isNotBlank(handLife))
|
||||
result.setVanguardProperties(handLife);
|
||||
return result;
|
||||
@@ -742,7 +745,10 @@ public final class CardRules implements ICardCharacteristics {
|
||||
}
|
||||
|
||||
public boolean hasStartOfKeyword(final String k) {
|
||||
for (final String inst : mainPart.getKeywords()) {
|
||||
return hasStartOfKeyword(k, mainPart);
|
||||
}
|
||||
public boolean hasStartOfKeyword(final String k, ICardFace cf) {
|
||||
for (final String inst : cf.getKeywords()) {
|
||||
final String[] parts = inst.split(":");
|
||||
if (parts[0].equals(k)) {
|
||||
return true;
|
||||
|
||||
@@ -8,6 +8,7 @@ import org.apache.commons.lang3.StringUtils;
|
||||
|
||||
import com.google.common.base.Predicate;
|
||||
import com.google.common.base.Predicates;
|
||||
import com.google.common.collect.Iterables;
|
||||
|
||||
import forge.util.CardTranslation;
|
||||
import forge.util.ComparableOp;
|
||||
@@ -186,7 +187,7 @@ public final class CardRulesPredicates {
|
||||
return new Predicate<CardRules>() {
|
||||
@Override
|
||||
public boolean apply(final CardRules card) {
|
||||
return card.hasStartOfKeyword(keyword);
|
||||
return Iterables.any(card.getAllFaces(), cf -> cf != null && card.hasStartOfKeyword(keyword, cf));
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user