forked from External/mage
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
|
|
@ -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);
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue