mirror of
https://github.com/correl/mage.git
synced 2025-01-13 11:01:58 +00:00
Fixed NPE errors on empty sourceId in mage reference object;
This commit is contained in:
parent
cb8d4dc340
commit
ff3df35467
5 changed files with 32 additions and 25 deletions
|
@ -1,9 +1,5 @@
|
|||
|
||||
package mage.cards.v;
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
import java.util.UUID;
|
||||
import mage.MageInt;
|
||||
import mage.MageObject;
|
||||
import mage.MageObjectReference;
|
||||
|
@ -26,8 +22,12 @@ import mage.game.permanent.PermanentToken;
|
|||
import mage.util.functions.ApplyToPermanent;
|
||||
import mage.watchers.Watcher;
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.Objects;
|
||||
import java.util.Set;
|
||||
import java.util.UUID;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author LevelX2
|
||||
*/
|
||||
public final class VizierOfManyFaces extends CardImpl {
|
||||
|
@ -75,7 +75,7 @@ class VizierOfManyFacesApplyToPermanent extends ApplyToPermanent {
|
|||
EmbalmedThisTurnWatcher watcher = game.getState().getWatcher(EmbalmedThisTurnWatcher.class);
|
||||
if (watcher != null) {
|
||||
for (MageObjectReference mor : watcher.getEmbalmedThisTurnCards()) {
|
||||
if (mor.getSourceId().equals(originalCardId) && game.getState().getZoneChangeCounter(originalCardId) == mor.getZoneChangeCounter()) {
|
||||
if (Objects.equals(mor.getSourceId(), originalCardId) && game.getState().getZoneChangeCounter(originalCardId) == mor.getZoneChangeCounter()) {
|
||||
permanent.getManaCost().clear();
|
||||
if (!permanent.hasSubtype(SubType.ZOMBIE, game)) {
|
||||
permanent.getSubtype(game).add(SubType.ZOMBIE);
|
||||
|
|
|
@ -9,6 +9,7 @@ import mage.game.stack.StackObject;
|
|||
import org.apache.log4j.Logger;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.Objects;
|
||||
import java.util.UUID;
|
||||
|
||||
/**
|
||||
|
@ -37,7 +38,7 @@ public class MageObjectReference implements Comparable<MageObjectReference>, Ser
|
|||
* That values manually (can be used to let it reference to a Permanent that
|
||||
* is not yet on the battlefield.
|
||||
*
|
||||
* @param sourceId
|
||||
* @param sourceId can be null
|
||||
* @param zoneChangeCounter
|
||||
* @param game
|
||||
*/
|
||||
|
@ -51,10 +52,15 @@ public class MageObjectReference implements Comparable<MageObjectReference>, Ser
|
|||
this.zoneChangeCounter = -1;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param sourceId can be null
|
||||
* @param game
|
||||
*/
|
||||
public MageObjectReference(UUID sourceId, Game game) {
|
||||
this.sourceId = sourceId;
|
||||
if (sourceId == null) {
|
||||
throw new IllegalArgumentException("MageObjectReference contains nullable sourceId");
|
||||
this.zoneChangeCounter = -1;
|
||||
return;
|
||||
}
|
||||
|
||||
MageObject mageObject = game.getObject(sourceId);
|
||||
|
@ -73,8 +79,8 @@ public class MageObjectReference implements Comparable<MageObjectReference>, Ser
|
|||
this.zoneChangeCounter = mageObject.getZoneChangeCounter(game);
|
||||
logger.error("SourceId found in LKI");
|
||||
} else {
|
||||
logger.error("SourceId NOT found in LKI");
|
||||
this.zoneChangeCounter = 0;
|
||||
logger.error("SourceId NOT found in LKI");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -90,7 +96,7 @@ public class MageObjectReference implements Comparable<MageObjectReference>, Ser
|
|||
|
||||
@Override
|
||||
public int compareTo(MageObjectReference o) {
|
||||
if (o.getSourceId().equals(this.sourceId)) {
|
||||
if (o.getSourceId() == null || this.sourceId == null || Objects.equals(o.getSourceId(), this.sourceId)) {
|
||||
return o.getZoneChangeCounter() - this.zoneChangeCounter;
|
||||
}
|
||||
return o.getSourceId().compareTo(sourceId);
|
||||
|
@ -99,7 +105,7 @@ public class MageObjectReference implements Comparable<MageObjectReference>, Ser
|
|||
@Override
|
||||
public boolean equals(Object v) {
|
||||
if (v instanceof MageObjectReference) {
|
||||
if (((MageObjectReference) v).getSourceId().equals(this.sourceId)) {
|
||||
if (Objects.equals(((MageObjectReference) v).getSourceId(), this.sourceId)) {
|
||||
return ((MageObjectReference) v).getZoneChangeCounter() == this.zoneChangeCounter;
|
||||
}
|
||||
}
|
||||
|
@ -120,7 +126,7 @@ public class MageObjectReference implements Comparable<MageObjectReference>, Ser
|
|||
public boolean refersTo(MageObject mageObject, Game game) {
|
||||
if (mageObject != null) {
|
||||
if (mageObject instanceof Spell) {
|
||||
return ((Spell) mageObject).getSourceId().equals(sourceId) && this.zoneChangeCounter == mageObject.getZoneChangeCounter(game);
|
||||
return Objects.equals(((Spell) mageObject).getSourceId(), this.sourceId) && this.zoneChangeCounter == mageObject.getZoneChangeCounter(game);
|
||||
}
|
||||
return mageObject.getId().equals(sourceId) && this.zoneChangeCounter == mageObject.getZoneChangeCounter(game);
|
||||
}
|
||||
|
|
|
@ -1,13 +1,12 @@
|
|||
|
||||
package mage.filter.predicate.mageobject;
|
||||
|
||||
import java.util.UUID;
|
||||
import mage.MageObject;
|
||||
import mage.filter.predicate.Predicate;
|
||||
import mage.game.Game;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author LevelX2
|
||||
*/
|
||||
public class CardIdPredicate implements Predicate<MageObject> {
|
||||
|
@ -25,6 +24,6 @@ public class CardIdPredicate implements Predicate<MageObject> {
|
|||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "CardId(" + cardId.toString() + ')';
|
||||
return "CardId (" + (cardId != null ? cardId.toString() : "null") + ')';
|
||||
}
|
||||
}
|
||||
|
|
|
@ -90,8 +90,10 @@ public class FixedTarget implements TargetPointer {
|
|||
}
|
||||
}
|
||||
|
||||
List<UUID> list = new ArrayList<>(1);
|
||||
list.add(targetId);
|
||||
List<UUID> list = new ArrayList<>();
|
||||
if (targetId != null) {
|
||||
list.add(targetId);
|
||||
}
|
||||
return list;
|
||||
}
|
||||
|
||||
|
|
|
@ -5,10 +5,6 @@
|
|||
*/
|
||||
package mage.target.targetpointer;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
import java.util.UUID;
|
||||
import mage.MageObjectReference;
|
||||
import mage.abilities.Ability;
|
||||
import mage.cards.Card;
|
||||
|
@ -16,8 +12,12 @@ import mage.cards.Cards;
|
|||
import mage.game.Game;
|
||||
import mage.game.permanent.Permanent;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
import java.util.UUID;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author LevelX2
|
||||
*/
|
||||
public class FixedTargets implements TargetPointer {
|
||||
|
@ -75,9 +75,9 @@ public class FixedTargets implements TargetPointer {
|
|||
@Override
|
||||
public List<UUID> getTargets(Game game, Ability source) {
|
||||
// check target not changed zone
|
||||
List<UUID> list = new ArrayList<>(1);
|
||||
List<UUID> list = new ArrayList<>();
|
||||
for (MageObjectReference mor : targets) {
|
||||
if (game.getState().getZoneChangeCounter(mor.getSourceId()) == mor.getZoneChangeCounter()) {
|
||||
if (mor.getSourceId() != null && game.getState().getZoneChangeCounter(mor.getSourceId()) == mor.getZoneChangeCounter()) {
|
||||
list.add(mor.getSourceId());
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue