mirror of
https://github.com/magefree/mage.git
synced 2025-12-26 05:22:02 -08:00
Fixed NPE errors
This commit is contained in:
parent
ca0297d7c8
commit
be6a588a7f
19 changed files with 37 additions and 23 deletions
|
|
@ -9,6 +9,7 @@ import mage.constants.Outcome;
|
|||
import mage.filter.FilterCard;
|
||||
import mage.game.Game;
|
||||
import mage.players.Player;
|
||||
import mage.util.CardUtil;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
|
|
@ -53,7 +54,7 @@ public class PlayTheTopCardEffect extends AsThoughEffectImpl {
|
|||
@Override
|
||||
public boolean applies(UUID objectId, Ability affectedAbility, Ability source, Game game, UUID playerId) {
|
||||
Card cardToCheck = game.getCard(objectId);
|
||||
objectId = game.getCard(objectId).getMainCard().getId(); // for split cards
|
||||
objectId = CardUtil.getMainCardId(game, objectId); // for split cards
|
||||
|
||||
if (cardToCheck != null
|
||||
&& playerId.equals(source.getControllerId())
|
||||
|
|
|
|||
|
|
@ -565,7 +565,7 @@ public final class CardUtil {
|
|||
public static boolean haveSameNames(String name1, String name2, Boolean ignoreMtgRuleForEmptyNames) {
|
||||
if (ignoreMtgRuleForEmptyNames) {
|
||||
// simple compare for tests and engine
|
||||
return name1 != null && name2 != null && name1.equals(name2);
|
||||
return name1 != null && name1.equals(name2);
|
||||
} else {
|
||||
// mtg logic compare for game (empty names can't be same)
|
||||
return !haveEmptyName(name1) && !haveEmptyName(name2) && name1.equals(name2);
|
||||
|
|
@ -587,4 +587,9 @@ public final class CardUtil {
|
|||
public static boolean haveEmptyName(MageObject object) {
|
||||
return object == null || haveEmptyName(object.getName());
|
||||
}
|
||||
|
||||
public static UUID getMainCardId(Game game, UUID objectId) {
|
||||
Card card = game.getCard(objectId);
|
||||
return card != null ? card.getMainCard().getId() : objectId;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue