remove redundant null checks before instanceof

This commit is contained in:
Ingmar Goudt 2018-09-17 21:09:42 +02:00
parent d3aea0270c
commit f04d7c9b03
72 changed files with 184 additions and 186 deletions

View file

@ -538,7 +538,7 @@ public class MageFrame extends javax.swing.JFrame implements MageClient {
// Always hide not hidden popup window or enlarged card view if a frame is set to active
try {
ActionCallback callback = Plugins.instance.getActionCallback();
if (callback != null && callback instanceof MageActionCallback) {
if (callback instanceof MageActionCallback) {
((MageActionCallback) callback).hideEnlargedCard();
}
Component container = MageFrame.getUI().getComponent(MageComponents.POPUP_CONTAINER);

View file

@ -319,7 +319,7 @@ public class DialogManager extends JComponent implements MouseListener,
if (e.getButton() == MouseEvent.BUTTON1) {
j = (JComponent) getComponentAt(e.getX(), e.getY());
if (j != null && j instanceof DialogContainer) {
if (j instanceof DialogContainer) {
rec = j.getBounds();
bDragged = true;
mx = e.getX();

View file

@ -530,7 +530,7 @@ public class MageBook extends JComponent {
Class<?> c = Class.forName(className);
Constructor<?> cons = c.getConstructor();
Object newToken = cons.newInstance();
if (newToken != null && newToken instanceof mage.game.permanent.token.Token) {
if (newToken instanceof Token) {
((Token) newToken).setExpansionSetCodeForImage(set);
((Token) newToken).setOriginalExpansionSetCode(set);
((Token) newToken).setTokenType(token.getType());
@ -580,7 +580,7 @@ public class MageBook extends JComponent {
Class<?> c = Class.forName(className);
Constructor<?> cons = c.getConstructor();
Object newEmblem = cons.newInstance();
if (newEmblem != null && newEmblem instanceof mage.game.command.Emblem) {
if (newEmblem instanceof Emblem) {
((Emblem) newEmblem).setExpansionSetCodeForImage(set);
emblems.add((Emblem) newEmblem);
@ -637,7 +637,7 @@ public class MageBook extends JComponent {
Class<?> c = Class.forName(className);
Constructor<?> cons = c.getConstructor();
Object newPlane = cons.newInstance();
if (newPlane != null && newPlane instanceof mage.game.command.Plane) {
if (newPlane instanceof Plane) {
((Plane) newPlane).setExpansionSetCodeForImage(set);
planes.add((Plane) newPlane);

View file

@ -369,7 +369,7 @@ public class TableModel extends AbstractTableModel implements ICardGrid {
if (!card.getId().equals(bigCard.getCardId())) {
if (!MageFrame.isLite()) {
Image image = Plugins.instance.getOriginalImage(card);
if (image != null && image instanceof BufferedImage) {
if (image instanceof BufferedImage) {
// XXX: scaled to fit width
bigCard.setCard(card.getId(), EnlargeMode.NORMAL, image, new ArrayList<>(), false);
} else {

View file

@ -617,7 +617,7 @@ public class MageActionCallback implements ActionCallback {
}
private void displayCardInfo(MageCard mageCard, Image image, BigCard bigCard) {
if (image != null && image instanceof BufferedImage) {
if (image instanceof BufferedImage) {
// XXX: scaled to fit width
bigCard.setCard(mageCard.getOriginal().getId(), enlargeMode, image, mageCard.getOriginal().getRules(), mageCard.getOriginal().isToRotate());
// if it's an ability, show only the ability text as overlay

View file

@ -47,7 +47,7 @@ public class CountryItemEditor extends BasicComboBoxEditor {
@Override
public void setItem(Object item) {
if (item == null || !(item instanceof String[])) {
if (!(item instanceof String[])) {
return;
}

View file

@ -800,7 +800,7 @@ public abstract class CardPanel extends MagePermanent implements MouseListener,
// this update removes the isChoosable mark from targetCardsInLibrary
// so only done for permanents because it's needed to redraw counters in different size, if window size was changed
// no perfect solution yet (maybe also other not wanted effects for PermanentView objects)
if (updateCard != null && (updateCard instanceof PermanentView)) {
if ((updateCard instanceof PermanentView)) {
update(updateCard);
}
}

View file

@ -225,7 +225,7 @@ public class Connection {
for (InterfaceAddress addr : iface.getInterfaceAddresses()) {
if (addr != null) {
InetAddress iaddr = addr.getAddress();
if (iaddr != null && iaddr instanceof Inet4Address) {
if (iaddr instanceof Inet4Address) {
return iaddr;
}
}

View file

@ -39,7 +39,7 @@ public final class CompressUtil {
* @return Decompressed object
*/
public static Object decompress(Object data) {
if (data == null || !(data instanceof ZippedObject)) {
if (!(data instanceof ZippedObject)) {
return data;
}
return ((ZippedObject) data).unzip();

View file

@ -27,7 +27,7 @@ public class LevelUpOptimizer extends BaseTreeOptimizer {
for (Ability ability : actions) {
if (ability instanceof LevelUpAbility) {
Permanent permanent = game.getPermanent(ability.getSourceId());
if (permanent != null && permanent instanceof PermanentCard) {
if (permanent instanceof PermanentCard) {
PermanentCard leveler = (PermanentCard) permanent;
// check already existing Level counters and compare to maximum that make sense
if (permanent.getCounters(game).getCount(CounterType.LEVEL) >= leveler.getMaxLevelCounters()) {

View file

@ -408,7 +408,7 @@ public final class SystemUtil {
Class<?> c = Class.forName("mage.game.permanent.token." + command.cardName);
Constructor<?> cons = c.getConstructor();
Object token = cons.newInstance();
if (token != null && token instanceof mage.game.permanent.token.Token) {
if (token instanceof mage.game.permanent.token.Token) {
((mage.game.permanent.token.Token) token).putOntoBattlefield(command.Amount, game, null, player.getId(), false, false);
continue;
}
@ -417,7 +417,7 @@ public final class SystemUtil {
Class<?> c = Class.forName("mage.game.command.emblems." + command.cardName);
Constructor<?> cons = c.getConstructor();
Object emblem = cons.newInstance();
if (emblem != null && emblem instanceof mage.game.command.Emblem) {
if (emblem instanceof mage.game.command.Emblem) {
((mage.game.command.Emblem) emblem).setControllerId(player.getId());
game.addEmblem((mage.game.command.Emblem) emblem, null, player.getId());
continue;
@ -427,7 +427,7 @@ public final class SystemUtil {
Class<?> c = Class.forName("mage.game.command.planes." + command.cardName);
Constructor<?> cons = c.getConstructor();
Object plane = cons.newInstance();
if (plane != null && plane instanceof mage.game.command.Plane) {
if (plane instanceof mage.game.command.Plane) {
((mage.game.command.Plane) plane).setControllerId(player.getId());
game.addPlane((mage.game.command.Plane) plane, null, player.getId());
continue;

View file

@ -171,7 +171,7 @@ class BerserkDelayedDestroyEffect extends OneShotEffect {
Permanent permanent = game.getPermanent(this.getTargetPointer().getFirst(game, source));
if (permanent != null) {
Watcher watcher = game.getState().getWatchers().get(AttackedThisTurnWatcher.class.getSimpleName());
if (watcher != null && watcher instanceof AttackedThisTurnWatcher) {
if (watcher instanceof AttackedThisTurnWatcher) {
if (((AttackedThisTurnWatcher) watcher).getAttackedThisTurnCreatures().contains(new MageObjectReference(permanent, game))) {
return permanent.destroy(source.getSourceId(), game, false);
}

View file

@ -136,7 +136,7 @@ class WhackCondition extends IntCompareCondition {
@Override
protected int getInputValue(Game game, Ability source) {
Object object = game.getState().getValue("whack" + source.getSourceId());
if (object != null && object instanceof Boolean && (Boolean) object) {
if (object instanceof Boolean && (Boolean) object) {
return 1;
}
return 0;
@ -157,7 +157,7 @@ class DoodleCondition extends IntCompareCondition {
@Override
protected int getInputValue(Game game, Ability source) {
Object object = game.getState().getValue("doodle" + source.getSourceId());
if (object != null && object instanceof Boolean && (Boolean) object) {
if (object instanceof Boolean && (Boolean) object) {
return 1;
}
return 0;
@ -178,7 +178,7 @@ class BuzzCondition extends IntCompareCondition {
@Override
protected int getInputValue(Game game, Ability source) {
Object object = game.getState().getValue("buzz" + source.getSourceId());
if (object != null && object instanceof Boolean && (Boolean) object) {
if (object instanceof Boolean && (Boolean) object) {
return 1;
}
return 0;

View file

@ -81,7 +81,7 @@ class ChainOfSilenceEffect extends OneShotEffect {
Spell spell = game.getStack().getSpell(source.getSourceId());
if (spell != null) {
StackObject newStackObject = spell.createCopyOnStack(game, source, player.getId(), true);
if (newStackObject != null && newStackObject instanceof Spell) {
if (newStackObject instanceof Spell) {
String activateMessage = ((Spell) newStackObject).getActivatedMessage(game);
if (activateMessage.startsWith(" casts ")) {
activateMessage = activateMessage.substring(6);

View file

@ -78,7 +78,7 @@ class ChainOfVaporEffect extends OneShotEffect {
Spell spell = game.getStack().getSpell(source.getSourceId());
if (spell != null) {
StackObject newStackObject = spell.createCopyOnStack(game, source, player.getId(), true);
if (newStackObject != null && newStackObject instanceof Spell) {
if (newStackObject instanceof Spell) {
String activateMessage = ((Spell) newStackObject).getActivatedMessage(game);
if (activateMessage.startsWith(" casts ")) {
activateMessage = activateMessage.substring(6);

View file

@ -80,7 +80,7 @@ class ChainStasisEffect extends OneShotEffect {
Spell spell = game.getStack().getSpell(source.getSourceId());
if (spell != null) {
StackObject newStackObject = spell.createCopyOnStack(game, source, player.getId(), true);
if (newStackObject != null && newStackObject instanceof Spell) {
if (newStackObject instanceof Spell) {
String activateMessage = ((Spell) newStackObject).getActivatedMessage(game);
if (activateMessage.startsWith(" casts ")) {
activateMessage = activateMessage.substring(6);

View file

@ -98,7 +98,7 @@ class ChorusOfTheConclaveReplacementEffect extends ReplacementEffectImpl {
// save the x value to be available for ETB replacement effect
Object object = game.getState().getValue("spellX" + source.getSourceId());
Map<String, Integer> spellX;
if (object != null && object instanceof Map) {
if (object instanceof Map) {
spellX = (Map<String, Integer>) object;
} else {
spellX = new HashMap<>();

View file

@ -70,7 +70,7 @@ class EngineeredExplosivesEffect extends OneShotEffect {
@Override
public boolean apply(Game game, Ability source) {
MageObject engineeredExplosives = game.getLastKnownInformation(source.getSourceId(), Zone.BATTLEFIELD);
if(engineeredExplosives != null && engineeredExplosives instanceof Permanent){
if(engineeredExplosives instanceof Permanent){
int count = ((Permanent)engineeredExplosives).getCounters(game).getCount(CounterType.CHARGE);
for (Permanent permanent : game.getBattlefield().getActivePermanents(filter, source.getControllerId(), source.getSourceId(), game)) {
if(permanent.getConvertedManaCost() == count){

View file

@ -77,7 +77,7 @@ class EssenceFluxEffect extends OneShotEffect {
cardsToBattlefield.add(targetId);
} else {
Card card = game.getCard(targetId);
if (card != null && card instanceof MeldCard) {
if (card instanceof MeldCard) {
MeldCard meldCard = (MeldCard) card;
Card topCard = meldCard.getTopHalfCard();
Card bottomCard = meldCard.getBottomHalfCard();

View file

@ -87,7 +87,7 @@ class FiresongAndSunspeakerTriggeredAbility extends TriggeredAbilityImpl {
@Override
public boolean checkTrigger(GameEvent event, Game game) {
MageObject object = game.getObject(event.getSourceId());
if (object != null && object instanceof Spell) {
if (object instanceof Spell) {
if (event.getTargetId().equals(this.getControllerId())
&& object.getColor(game).contains(ObjectColor.WHITE)
&& (object.isInstant()

View file

@ -151,7 +151,7 @@ class ForbiddenCryptPutIntoYourGraveyardReplacementEffect extends ReplacementEff
Card card = game.getCard(event.getTargetId());
if (card != null && card.isOwnedBy(source.getControllerId())) {
Permanent permanent = ((ZoneChangeEvent) event).getTarget();
if (permanent == null || !(permanent instanceof PermanentToken)) {
if (!(permanent instanceof PermanentToken)) {
return true;
}
}

View file

@ -73,7 +73,7 @@ class ForsakenWastesTriggeredAbility extends TriggeredAbilityImpl {
@Override
public boolean checkTrigger(GameEvent event, Game game) {
MageObject eventSourceObject = game.getObject(event.getSourceId());
if (eventSourceObject != null && event.getTargetId().equals(this.getSourceId())&& eventSourceObject instanceof Spell ) {
if (event.getTargetId().equals(this.getSourceId()) && eventSourceObject instanceof Spell) {
getEffects().get(0).setTargetPointer(new FixedTarget(event.getPlayerId()));
return true;
}

View file

@ -150,7 +150,7 @@ class GoToJailUpkeepEffect extends OneShotEffect {
Permanent permanent = (Permanent) source.getSourceObjectIfItStillExists(game);
if (sourceObject != null && sourceObject instanceof Permanent && permanent != null) {
if (sourceObject instanceof Permanent && permanent != null) {
UUID opponentId = (UUID) game.getState().getValue(sourceObject.getId().toString() + ChooseOpponentEffect.VALUE_KEY);
Player opponent = game.getPlayer(opponentId);

View file

@ -71,7 +71,7 @@ class GenesisHydraPutOntoBattlefieldEffect extends OneShotEffect {
public boolean apply(Game game, Ability source) {
Player controller = game.getPlayer(source.getControllerId());
Object obj = getValue(CastSourceTriggeredAbility.SOURCE_CAST_SPELL_ABILITY);
if (controller != null && obj != null && obj instanceof SpellAbility) {
if (controller != null && obj instanceof SpellAbility) {
int count = ((SpellAbility) obj).getManaCostsToPay().getX();
if (count > 0) {
Cards cards = new CardsImpl(controller.getLibrary().getTopCards(game, count));

View file

@ -184,7 +184,7 @@ class HopeOfGhirapurCombatDamageWatcher extends Watcher {
public boolean playerGotCombatDamage(UUID objectId, UUID playerId, Game game) {
StackObject stackObject = game.getState().getStack().getStackObject(objectId);
MageObjectReference mor;
if (stackObject != null && stackObject instanceof StackAbility) {
if (stackObject instanceof StackAbility) {
// This is neccessary because the source object was sacrificed as cost and the correct zone change counter for target calid check can only be get from stack
mor = new MageObjectReference(objectId, ((StackAbility) stackObject).getSourceObjectZoneChangeCounter(), game);
} else {

View file

@ -265,7 +265,7 @@ class IceCauldronManaCondition implements Condition {
public boolean apply(Game game, Ability source) {
if (source instanceof SpellAbility) {
Card card = game.getCard(source.getSourceId());
if (card != null && exiledCard != null && card.equals(exiledCard)) {
if (card != null && card.equals(exiledCard)) {
return true;
}
}

View file

@ -74,7 +74,7 @@ class LabyrinthGuardianTriggeredAbility extends TriggeredAbilityImpl {
@Override
public boolean checkTrigger(GameEvent event, Game game) {
MageObject eventSourceObject = game.getObject(event.getSourceId());
if (eventSourceObject != null && event.getTargetId().equals(this.getSourceId()) && eventSourceObject instanceof Spell) {
if (event.getTargetId().equals(this.getSourceId()) && eventSourceObject instanceof Spell) {
getEffects().get(0).setTargetPointer(new FixedTarget(event.getPlayerId()));
return true;
}

View file

@ -71,7 +71,7 @@ class MeletisCharlatanCopyTargetSpellEffect extends OneShotEffect {
if (spell != null) {
StackObject newStackObject = spell.createCopyOnStack(game, source, spell.getControllerId(), true);
Player player = game.getPlayer(spell.getControllerId());
if (player != null && newStackObject != null && newStackObject instanceof Spell) {
if (player != null && newStackObject instanceof Spell) {
String activateMessage = ((Spell) newStackObject).getActivatedMessage(game);
if (activateMessage.startsWith(" casts ")) {
activateMessage = activateMessage.substring(6);

View file

@ -91,7 +91,7 @@ class MetzaliTowerOfTriumphEffect extends OneShotEffect {
@Override
public boolean apply(Game game, Ability source) {
Watcher watcher = game.getState().getWatchers().get(AttackedThisTurnWatcher.class.getSimpleName());
if (watcher != null && watcher instanceof AttackedThisTurnWatcher) {
if (watcher instanceof AttackedThisTurnWatcher) {
Set<MageObjectReference> attackedThisTurn = ((AttackedThisTurnWatcher) watcher).getAttackedThisTurnCreatures();
List<Permanent> available = new ArrayList<>();
for (MageObjectReference mor : attackedThisTurn) {

View file

@ -70,7 +70,7 @@ class PawnOfUlamogTriggeredAbility extends TriggeredAbilityImpl {
public boolean checkTrigger(GameEvent event, Game game) {
UUID targetId = event.getTargetId();
MageObject card = game.getLastKnownInformation(targetId, Zone.BATTLEFIELD);
if (card != null && card instanceof Permanent && !(card instanceof PermanentToken)) {
if (card instanceof Permanent && !(card instanceof PermanentToken)) {
Permanent permanent = (Permanent) card;
ZoneChangeEvent zEvent = (ZoneChangeEvent) event;
if (zEvent.getFromZone() == Zone.BATTLEFIELD && zEvent.getToZone() == Zone.GRAVEYARD

View file

@ -99,7 +99,7 @@ class PhyrexianProcessorCreateTokenEffect extends OneShotEffect {
public boolean apply(Game game, Ability source) {
String key = CardUtil.getCardZoneString("lifePaid", source.getSourceId(), game);
Object object = game.getState().getValue(key);
if(object != null && object instanceof Integer) {
if(object instanceof Integer) {
int lifePaid = (int) object;
MinionToken token = new MinionToken();
token.getPower().modifyBaseValue(lifePaid);

View file

@ -85,7 +85,7 @@ class PsychicRebuttalEffect extends OneShotEffect {
&& controller.chooseUse(Outcome.PlayForFree, "Copy " + spell.getName() + " (you may choose new targets for the copy)?", source, game)) {
StackObject newStackObject = spell.createCopyOnStack(game, source, source.getControllerId(), true);
if (newStackObject != null && newStackObject instanceof Spell) {
if (newStackObject instanceof Spell) {
String activateMessage = ((Spell) newStackObject).getActivatedMessage(game);
if (activateMessage.startsWith(" casts ")) {
activateMessage = activateMessage.substring(6);

View file

@ -62,7 +62,7 @@ class PyromancersGauntletReplacementEffect extends ReplacementEffectImpl {
@Override
public boolean applies(GameEvent event, Ability source, Game game) {
MageObject object = game.getObject(event.getSourceId());
if (object != null && object instanceof Spell) {
if (object instanceof Spell) {
if (((Spell) object).isControlledBy(source.getControllerId())
&& (object.isInstant()
|| object.isSorcery())){

View file

@ -73,7 +73,7 @@ class PyxisOfPandemoniumExileEffect extends OneShotEffect {
Map<String, UUID> exileIds;
String valueKey = CardUtil.getObjectZoneString("exileIds", sourceObject, game);
Object object = game.getState().getValue(valueKey);
if (object != null && object instanceof Map) {
if (object instanceof Map) {
exileIds = (Map<String, UUID>) object;
} else {
exileIds = new HashMap<>();
@ -123,7 +123,7 @@ class PyxisOfPandemoniumPutOntoBattlefieldEffect extends OneShotEffect {
Map<String, UUID> exileIds;
String valueKey = CardUtil.getObjectZoneString("exileIds", sourceObject, game);
Object object = game.getState().getValue(valueKey);
if (object != null && object instanceof Map) {
if (object instanceof Map) {
exileIds = (Map<String, UUID>) object;
} else {
return true;

View file

@ -77,7 +77,7 @@ class CreaturesYouControlBecomesTargetTriggeredAbility extends TriggeredAbilityI
Permanent permanent = game.getPermanent(event.getTargetId());
if (permanent != null && permanent.isControlledBy(this.controllerId) && (permanent.hasSubtype(SubType.WOLF, game) || permanent.hasSubtype(SubType.WEREWOLF, game))) {
MageObject object = game.getObject(event.getSourceId());
if (object != null && object instanceof Spell) {
if (object instanceof Spell) {
Card c = (Spell) object;
if (c.isInstant() || c.isSorcery()) {
if (getTargets().isEmpty()) {

View file

@ -123,7 +123,7 @@ class SolemnityEffect2 extends ReplacementEffectImpl {
Permanent permanent2 = game.getPermanent(event.getTargetId());
Permanent permanent3 = game.getPermanentEntering(event.getTargetId());
if (object != null && object instanceof Permanent) {
if (object instanceof Permanent) {
if (filter.match((Permanent) object, game)) {
return true;
}

View file

@ -111,7 +111,7 @@ class SoulfireGrandMasterCastFromHandReplacementEffect extends ReplacementEffect
@Override
public boolean replaceEvent(GameEvent event, Ability source, Game game) {
MageObject mageObject = game.getObject(spellId);
if (mageObject == null || !(mageObject instanceof Spell) || ((Spell) mageObject).isCopiedSpell()) {
if (!(mageObject instanceof Spell) || ((Spell) mageObject).isCopiedSpell()) {
return false;
} else {
Card sourceCard = game.getCard(spellId);

View file

@ -69,7 +69,7 @@ class SparkFiendEffect extends OneShotEffect {
if (controller != null) {
int roll = controller.rollDice(game, 6) + controller.rollDice(game, 6);
MageObject mageObject = game.getObject(source.getSourceId());
if (mageObject != null && mageObject instanceof Permanent) {
if (mageObject instanceof Permanent) {
Permanent sourcePermanent = (Permanent) mageObject;
if (roll == 2 || roll == 3 || roll == 12) {
// sacrifice
@ -114,7 +114,7 @@ class SparkFiendUpkeepEffect extends OneShotEffect {
&& (Integer) game.getState().getValue("SparkFiend" + source.getSourceId().toString()) != 0) {
int roll = controller.rollDice(game, 6) + controller.rollDice(game, 6);
MageObject mageObject = game.getObject(source.getSourceId());
if (mageObject != null && mageObject instanceof Permanent) {
if (mageObject instanceof Permanent) {
Permanent sourcePermanent = (Permanent) mageObject;
if (roll == 7) {
// sacrifice

View file

@ -80,7 +80,7 @@ class SpectralPrisonAbility extends TriggeredAbilityImpl {
@Override
public boolean checkTrigger(GameEvent event, Game game) {
MageObject eventSourceObject = game.getObject(event.getSourceId());
if (eventSourceObject != null && eventSourceObject instanceof Spell) {
if (eventSourceObject instanceof Spell) {
Permanent enchantment = game.getPermanent(sourceId);
if (enchantment != null && enchantment.getAttachedTo() != null) {
if (event.getTargetId().equals(enchantment.getAttachedTo())) {

View file

@ -66,7 +66,7 @@ class SpellShrivelCounterUnlessPaysEffect extends OneShotEffect {
public boolean apply(Game game, Ability source) {
StackObject spell = game.getStack().getStackObject(targetPointer.getFirst(game, source));
MageObject sourceObject = source.getSourceObject(game);
if (spell != null && (spell instanceof Spell) && sourceObject != null) {
if ((spell instanceof Spell) && sourceObject != null) {
Player controller = game.getPlayer(source.getControllerId());
if (controller != null) {
int amount = 4;

View file

@ -90,8 +90,7 @@ class SummoningTrapWatcher extends Watcher {
if (counteredSpell == null) {
counteredSpell = (StackObject) game.getLastKnownInformation(event.getTargetId(), Zone.STACK);
}
if (counteredSpell != null
&& counteredSpell instanceof Spell
if (counteredSpell instanceof Spell
&& !players.contains(counteredSpell.getControllerId())
&& counteredSpell.isCreature()) {
StackObject counteringStackObject = game.getStack().getStackObject(event.getSourceId());

View file

@ -61,7 +61,7 @@ class SyncopateCounterUnlessPaysEffect extends OneShotEffect {
public boolean apply(Game game, Ability source) {
StackObject spell = game.getStack().getStackObject(targetPointer.getFirst(game, source));
MageObject sourceObject = source.getSourceObject(game);
if (spell != null && (spell instanceof Spell) && sourceObject != null) {
if ((spell instanceof Spell) && sourceObject != null) {
Player controller = game.getPlayer(source.getControllerId());
if (controller != null) {
int amount = source.getManaCostsToPay().getX();

View file

@ -137,7 +137,7 @@ class ThoughtPrisonTriggeredAbility extends TriggeredAbilityImpl {
Spell spell = (Spell) game.getObject(event.getTargetId());
Permanent sourcePermanent = game.getPermanent(this.getSourceId());
if (spell != null && spell instanceof Spell) {
if (spell instanceof Spell) {
if (sourcePermanent == null) {
sourcePermanent = (Permanent) game.getLastKnownInformation(event.getSourceId(), Zone.BATTLEFIELD);
}

View file

@ -102,8 +102,7 @@ class TreacherousPitDwellerEffect extends ContinuousEffectImpl {
public boolean apply(Game game, Ability source) {
MageObject permanent = source.getSourceObjectIfItStillExists(game); // it can also return Card object
Player targetOpponent = game.getPlayer(source.getFirstTarget());
if (permanent != null
&& (permanent instanceof Permanent)
if ((permanent instanceof Permanent)
&& targetOpponent != null) {
return ((Permanent) permanent).changeControllerId(targetOpponent.getId(), game);
} else {

View file

@ -89,7 +89,7 @@ class TritonTacticsUntapTargetEffect extends OneShotEffect {
// save the targets for the watcher in a map with zone change counter (as the card is recast during combat it's neccessary to save with zone change counter)
Map<Integer, Set<String>> targetMap;
Object object = game.getState().getValue("targets" + source.getSourceId());
if (object != null && object instanceof Map) {
if (object instanceof Map) {
targetMap = (Map<Integer, Set<String>>) object;
} else {
targetMap = new HashMap<>();
@ -155,7 +155,7 @@ class TritonTacticsEndOfCombatEffect extends OneShotEffect {
public boolean apply(Game game, Ability source) {
Map<Integer, Set<String>> attackerMap = null;
Object object = game.getState().getValue("blockedAttackers" + source.getSourceId());
if (object != null && object instanceof Map) {
if (object instanceof Map) {
attackerMap = (Map<Integer, Set<String>>) object;
for (Set<String> attackerSet : attackerMap.values()) {
List<Permanent> doNotUntapNextUntapStep = new ArrayList<>();
@ -197,7 +197,7 @@ class BlockedCreaturesWatcher extends Watcher {
if (event.getType() == GameEvent.EventType.BLOCKER_DECLARED) {
Map<Integer, Set<String>> targetMap;
Object object = game.getState().getValue("targets" + this.getSourceId().toString());
if (object != null && object instanceof Map) {
if (object instanceof Map) {
Permanent blocker = game.getPermanent(event.getSourceId());
if (blocker != null) {
targetMap = (Map<Integer, Set<String>>) object;
@ -217,7 +217,7 @@ class BlockedCreaturesWatcher extends Watcher {
Set<String> attackers;
Map<Integer, Set<String>> attackerMap;
Object object = game.getState().getValue("blockedAttackers" + getSourceId());
if (object != null && object instanceof Map) {
if (object instanceof Map) {
attackerMap = (Map<Integer, Set<String>>) object;
} else {
attackerMap = new HashMap<>();

View file

@ -65,7 +65,7 @@ class CreaturesYouControlBecomesTargetTriggeredAbility extends TriggeredAbilityI
Permanent permanent = game.getPermanent(event.getTargetId());
if (permanent != null && permanent.isControlledBy(this.controllerId) && permanent.isCreature()) {
MageObject object = game.getObject(event.getSourceId());
if (object != null && object instanceof Spell) {
if (object instanceof Spell) {
Card c = (Spell) object;
if (c.isInstant() || c.isSorcery()) {
if (getTargets().isEmpty()) {

View file

@ -96,7 +96,7 @@ class WispweaverAngelEffect extends OneShotEffect {
cardsToBattlefield.add(targetId);
} else {
Card card = game.getCard(targetId);
if (card != null && card instanceof MeldCard) {
if (card instanceof MeldCard) {
MeldCard meldCard = (MeldCard) card;
Card topCard = meldCard.getTopHalfCard();
Card bottomCard = meldCard.getBottomHalfCard();

View file

@ -143,7 +143,7 @@ class UntapAttackingThisTurnEffect extends OneShotEffect {
@Override
public boolean apply(Game game, Ability source) {
Watcher watcher = game.getState().getWatchers().get(AttackedThisTurnWatcher.class.getSimpleName());
if (watcher != null && watcher instanceof AttackedThisTurnWatcher) {
if (watcher instanceof AttackedThisTurnWatcher) {
Set<MageObjectReference> attackedThisTurn = ((AttackedThisTurnWatcher) watcher).getAttackedThisTurnCreatures();
for (MageObjectReference mor : attackedThisTurn) {
Permanent permanent = mor.getPermanent(game);

View file

@ -137,7 +137,7 @@ class YawgmothsAgendaReplacementEffect extends ReplacementEffectImpl {
Card card = game.getCard(event.getTargetId());
if (card != null && card.isOwnedBy(source.getControllerId())) {
Permanent permanent = ((ZoneChangeEvent) event).getTarget();
if (permanent == null || !(permanent instanceof PermanentToken)) {
if (!(permanent instanceof PermanentToken)) {
return true;
}
}

View file

@ -127,7 +127,7 @@ class YawgmothsWillReplacementEffect extends ReplacementEffectImpl {
Card card = game.getCard(event.getTargetId());
if (card != null && card.isOwnedBy(source.getControllerId())) {
Permanent permanent = ((ZoneChangeEvent) event).getTarget();
if (permanent == null || !(permanent instanceof PermanentToken)) {
if (!(permanent instanceof PermanentToken)) {
return true;
}
}

View file

@ -31,7 +31,7 @@ public class DealsDamageToOneOrMoreCreaturesTriggeredAbility extends DealsDamage
|| game.getTurn().getStepType() == PhaseStep.FIRST_COMBAT_DAMAGE) {
String stepHash = (String) game.getState().getValue("damageStep" + getOriginalId());
String newStepHash = game.getStep().getType().toString() + game.getTurnNum();
if (stepHash == null || !newStepHash.equals(stepHash)) {
if (!newStepHash.equals(stepHash)) {
// this ability did not trigger during this damage step
game.getState().setValue("damageStep" + getOriginalId(), game.getStep().getType().toString() + game.getTurnNum());
return true;

View file

@ -1,62 +1,62 @@
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package mage.abilities.common;
import mage.abilities.TriggeredAbilityImpl;
import mage.abilities.effects.Effect;
import mage.constants.Zone;
import mage.game.Game;
import mage.game.events.GameEvent;
import mage.game.events.GameEvent.EventType;
import mage.game.stack.Spell;
import mage.game.stack.StackObject;
/**
*
* @author fireshoes
*/
public class SpellCounteredControllerTriggeredAbility extends TriggeredAbilityImpl {
public SpellCounteredControllerTriggeredAbility(Effect effect) {
this(effect, false);
}
public SpellCounteredControllerTriggeredAbility(Effect effect, boolean optional) {
super(Zone.BATTLEFIELD, effect, optional);
}
public SpellCounteredControllerTriggeredAbility(final SpellCounteredControllerTriggeredAbility ability) {
super(ability);
}
@Override
public SpellCounteredControllerTriggeredAbility copy() {
return new SpellCounteredControllerTriggeredAbility(this);
}
@Override
public boolean checkEventType(GameEvent event, Game game) {
return event.getType() == EventType.COUNTERED;
}
@Override
public boolean checkTrigger(GameEvent event, Game game) {
StackObject stackObjectThatCountered = game.getStack().getStackObject(event.getSourceId());
if (stackObjectThatCountered == null) {
stackObjectThatCountered = (StackObject) game.getLastKnownInformation(event.getSourceId(), Zone.STACK);
}
if (stackObjectThatCountered != null && stackObjectThatCountered.isControlledBy(getControllerId())) {
StackObject counteredStackObject = (StackObject) game.getLastKnownInformation(event.getTargetId(), Zone.STACK);
return counteredStackObject != null && (counteredStackObject instanceof Spell);
}
return false;
}
@Override
public String getRule() {
return "Whenever a spell or ability you control counters a spell, " + super.getRule();
}
}
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package mage.abilities.common;
import mage.abilities.TriggeredAbilityImpl;
import mage.abilities.effects.Effect;
import mage.constants.Zone;
import mage.game.Game;
import mage.game.events.GameEvent;
import mage.game.events.GameEvent.EventType;
import mage.game.stack.Spell;
import mage.game.stack.StackObject;
/**
*
* @author fireshoes
*/
public class SpellCounteredControllerTriggeredAbility extends TriggeredAbilityImpl {
public SpellCounteredControllerTriggeredAbility(Effect effect) {
this(effect, false);
}
public SpellCounteredControllerTriggeredAbility(Effect effect, boolean optional) {
super(Zone.BATTLEFIELD, effect, optional);
}
public SpellCounteredControllerTriggeredAbility(final SpellCounteredControllerTriggeredAbility ability) {
super(ability);
}
@Override
public SpellCounteredControllerTriggeredAbility copy() {
return new SpellCounteredControllerTriggeredAbility(this);
}
@Override
public boolean checkEventType(GameEvent event, Game game) {
return event.getType() == EventType.COUNTERED;
}
@Override
public boolean checkTrigger(GameEvent event, Game game) {
StackObject stackObjectThatCountered = game.getStack().getStackObject(event.getSourceId());
if (stackObjectThatCountered == null) {
stackObjectThatCountered = (StackObject) game.getLastKnownInformation(event.getSourceId(), Zone.STACK);
}
if (stackObjectThatCountered != null && stackObjectThatCountered.isControlledBy(getControllerId())) {
StackObject counteredStackObject = (StackObject) game.getLastKnownInformation(event.getTargetId(), Zone.STACK);
return (counteredStackObject instanceof Spell);
}
return false;
}
@Override
public String getRule() {
return "Whenever a spell or ability you control counters a spell, " + super.getRule();
}
}

View file

@ -1,40 +1,40 @@
package mage.abilities.condition.common;
import mage.MageObject;
import mage.abilities.Ability;
import mage.abilities.condition.Condition;
import mage.filter.common.FilterControlledCreaturePermanent;
import mage.filter.predicate.mageobject.NamePredicate;
import mage.filter.predicate.other.OwnerIdPredicate;
import mage.game.Game;
import mage.game.permanent.Permanent;
/**
*
* @author emerald000
*/
public class MeldCondition implements Condition {
private final String meldWithName;
public MeldCondition(String meldWithName) {
this.meldWithName = meldWithName;
}
@Override
public boolean apply(Game game, Ability source) {
MageObject sourceMageObject = source.getSourceObjectIfItStillExists(game);
if (sourceMageObject != null && sourceMageObject instanceof Permanent) {
Permanent sourcePermanent = (Permanent) sourceMageObject;
if (sourcePermanent.isControlledBy(source.getControllerId())
&& sourcePermanent.isOwnedBy(source.getControllerId())) {
FilterControlledCreaturePermanent filter = new FilterControlledCreaturePermanent();
filter.add(new NamePredicate(this.meldWithName));
filter.add(new OwnerIdPredicate(source.getControllerId()));
return game.getBattlefield().count(filter, source.getSourceId(), source.getControllerId(), game) > 0;
}
}
return false;
}
}
package mage.abilities.condition.common;
import mage.MageObject;
import mage.abilities.Ability;
import mage.abilities.condition.Condition;
import mage.filter.common.FilterControlledCreaturePermanent;
import mage.filter.predicate.mageobject.NamePredicate;
import mage.filter.predicate.other.OwnerIdPredicate;
import mage.game.Game;
import mage.game.permanent.Permanent;
/**
*
* @author emerald000
*/
public class MeldCondition implements Condition {
private final String meldWithName;
public MeldCondition(String meldWithName) {
this.meldWithName = meldWithName;
}
@Override
public boolean apply(Game game, Ability source) {
MageObject sourceMageObject = source.getSourceObjectIfItStillExists(game);
if (sourceMageObject instanceof Permanent) {
Permanent sourcePermanent = (Permanent) sourceMageObject;
if (sourcePermanent.isControlledBy(source.getControllerId())
&& sourcePermanent.isOwnedBy(source.getControllerId())) {
FilterControlledCreaturePermanent filter = new FilterControlledCreaturePermanent();
filter.add(new NamePredicate(this.meldWithName));
filter.add(new OwnerIdPredicate(source.getControllerId()));
return game.getBattlefield().count(filter, source.getSourceId(), source.getControllerId(), game) > 0;
}
}
return false;
}
}

View file

@ -24,7 +24,7 @@ public class SunburstCount implements DynamicValue {
int count = 0;
if (!game.getStack().isEmpty()) {
StackObject spell = game.getStack().getFirst();
if (spell != null && spell instanceof Spell && ((Spell) spell).getSourceId().equals(source.getSourceId())) {
if (spell instanceof Spell && ((Spell) spell).getSourceId().equals(source.getSourceId())) {
Mana mana = ((Spell) spell).getSpellAbility().getManaCostsToPay().getPayment();
if (mana.getBlack() > 0) {
count++;

View file

@ -44,7 +44,7 @@ public class CastSourceTriggeredAbility extends TriggeredAbilityImpl {
public boolean checkTrigger(GameEvent event, Game game) {
if (event.getSourceId().equals(this.getSourceId())) {
MageObject spellObject = game.getObject(sourceId);
if (spellObject != null && (spellObject instanceof Spell)) {
if ((spellObject instanceof Spell)) {
Spell spell = (Spell) spellObject;
if (spell.getSpellAbility() != null) {
for (Effect effect : getEffects()) {

View file

@ -54,7 +54,7 @@ public class CopyTargetSpellEffect extends OneShotEffect {
if (spell != null) {
StackObject newStackObject = spell.createCopyOnStack(game, source, useController ? spell.getControllerId() : source.getControllerId(), true);
Player player = game.getPlayer(source.getControllerId());
if (player != null && newStackObject != null && newStackObject instanceof Spell) {
if (player != null && newStackObject instanceof Spell) {
String activateMessage = ((Spell) newStackObject).getActivatedMessage(game);
if (activateMessage.startsWith(" casts ")) {
activateMessage = activateMessage.substring(6);

View file

@ -37,7 +37,7 @@ public class ReturnToBattlefieldUnderOwnerControlAttachedEffect extends OneShotE
return false;
}
Object object = getValue("attachedTo");
if (object != null && object instanceof Permanent) {
if (object instanceof Permanent) {
Card card = game.getCard(((Permanent) object).getId());
if (card != null) {
if (controller.moveCards(card, Zone.BATTLEFIELD, source, game, false, false, true, null)) {

View file

@ -66,7 +66,7 @@ public class ReturnToBattlefieldUnderOwnerControlTargetEffect extends OneShotEff
}
else {
Card card = game.getCard(targetId);
if (card != null && card instanceof MeldCard) {
if (card instanceof MeldCard) {
MeldCard meldCard = (MeldCard) card;
Card topCard = meldCard.getTopHalfCard();
Card bottomCard = meldCard.getBottomHalfCard();

View file

@ -43,7 +43,7 @@ public class ReturnToBattlefieldUnderYourControlAttachedEffect extends OneShotEf
public boolean apply(Game game, Ability source) {
Object object = getValue("attachedTo");
Player controller = game.getPlayer(source.getControllerId());
if (controller != null && object != null && object instanceof Permanent) {
if (controller != null && object instanceof Permanent) {
Card card = game.getCard(((Permanent) object).getId());
// Move the card only, if it is still in the next zone after the battlefield
if (card != null && card.getZoneChangeCounter(game) == ((Permanent) object).getZoneChangeCounter(game) + 1) {

View file

@ -64,7 +64,7 @@ public class ReturnToBattlefieldUnderYourControlTargetEffect extends OneShotEffe
}
else {
Card card = game.getCard(targetId);
if (card != null && card instanceof MeldCard) {
if (card instanceof MeldCard) {
MeldCard meldCard = (MeldCard) card;
Card topCard = meldCard.getTopHalfCard();
Card bottomCard = meldCard.getBottomHalfCard();

View file

@ -33,7 +33,7 @@ public class ReturnToHandAttachedEffect extends OneShotEffect {
@Override
public boolean apply(Game game, Ability source) {
Object object = getValue("attachedTo");
if (object != null && object instanceof Permanent) {
if (object instanceof Permanent) {
Card card = game.getCard(((Permanent)object).getId());
if (card != null) {
if (card.moveToZone(Zone.HAND, source.getSourceId(), game, false)) {

View file

@ -47,7 +47,7 @@ public class TransformSourceEffect extends OneShotEffect {
@Override
public boolean apply(Game game, Ability source) {
MageObject sourceObject = source.getSourceObjectIfItStillExists(game); // Transform only if it's the same object as the effect was put on the stack
if (sourceObject != null && sourceObject instanceof Permanent) {
if (sourceObject instanceof Permanent) {
Permanent sourcePermanent = (Permanent) sourceObject;
if (sourcePermanent.canTransform(source, game)) {
// check not to transform twice the same side

View file

@ -37,7 +37,7 @@ public class UntapAllThatAttackedEffect extends OneShotEffect {
@Override
public boolean apply(Game game, Ability source) {
Watcher watcher = game.getState().getWatchers().get(AttackedThisTurnWatcher.class.getSimpleName());
if (watcher != null && watcher instanceof AttackedThisTurnWatcher) {
if (watcher instanceof AttackedThisTurnWatcher) {
Set<MageObjectReference> attackedThisTurn = ((AttackedThisTurnWatcher) watcher).getAttackedThisTurnCreatures();
for (MageObjectReference mor : attackedThisTurn) {
Permanent permanent = mor.getPermanent(game);

View file

@ -149,7 +149,7 @@ class AftermathExileAsResolvesFromGraveyard extends ReplacementEffectImpl {
// wants to do that in the future.
UUID sourceId = source.getSourceId();
Card sourceCard = game.getCard(source.getSourceId());
if (sourceCard != null && sourceCard instanceof SplitCardHalf) {
if (sourceCard instanceof SplitCardHalf) {
sourceCard = ((SplitCardHalf) sourceCard).getParentCard();
sourceId = sourceCard.getId();
}
@ -170,7 +170,7 @@ class AftermathExileAsResolvesFromGraveyard extends ReplacementEffectImpl {
public boolean replaceEvent(GameEvent event, Ability source, Game game) {
UUID sourceId = source.getSourceId();
Card sourceCard = game.getCard(source.getSourceId());
if (sourceCard != null && sourceCard instanceof SplitCardHalf) {
if (sourceCard instanceof SplitCardHalf) {
sourceCard = ((SplitCardHalf) sourceCard).getParentCard();
sourceId = sourceCard.getId();
}

View file

@ -272,7 +272,7 @@ class ConspireEffect extends OneShotEffect {
Card card = game.getCard(conspiredSpell.getSourceId());
if (card != null) {
StackObject newStackObject = conspiredSpell.createCopyOnStack(game, source, source.getControllerId(), true);
if (newStackObject != null && newStackObject instanceof Spell && !game.isSimulation()) {
if (newStackObject instanceof Spell && !game.isSimulation()) {
game.informPlayers(controller.getLogName() + ((Spell) newStackObject).getActivatedMessage(game));
}
return true;

View file

@ -83,7 +83,7 @@ public class HauntAbility extends TriggeredAbilityImpl {
if (card != null) {
String key = new StringBuilder("Haunting_").append(getSourceId().toString()).append('_').append(card.getZoneChangeCounter(game)).toString();
Object object = game.getState().getValue(key);
if (object != null && object instanceof FixedTarget) {
if (object instanceof FixedTarget) {
FixedTarget target = (FixedTarget) object;
if (target.getTarget() != null && target.getTarget().equals(event.getTargetId())) {
usedFromExile = true;

View file

@ -222,7 +222,7 @@ class ReplicateCopyEffect extends OneShotEffect {
// create the copies
for (int i = 0; i < replicateCount; i++) {
StackObject newStackObject = spell.createCopyOnStack(game, source, source.getControllerId(), true);
if (newStackObject != null && newStackObject instanceof Spell && !game.isSimulation()) {
if (newStackObject instanceof Spell && !game.isSimulation()) {
game.informPlayers(controller.getLogName() + ((Spell) newStackObject).getActivatedMessage(game));
}
}

View file

@ -286,7 +286,7 @@ public class Plane implements CommandObject {
Class<?> c = Class.forName(planeName);
Constructor<?> cons = c.getConstructor();
Object plane = cons.newInstance();
if (plane != null && plane instanceof mage.game.command.Plane) {
if (plane instanceof Plane) {
return (Plane) plane;
}
} catch (Exception ex) {

View file

@ -63,7 +63,7 @@ class IllusionTokenTriggeredAbility extends TriggeredAbilityImpl {
@Override
public boolean checkTrigger(GameEvent event, Game game) {
MageObject eventSourceObject = game.getObject(event.getSourceId());
if (eventSourceObject != null && event.getTargetId().equals(this.getSourceId()) && eventSourceObject instanceof Spell) {
if (event.getTargetId().equals(this.getSourceId()) && eventSourceObject instanceof Spell) {
getEffects().get(0).setTargetPointer(new FixedTarget(event.getPlayerId()));
return true;
}

View file

@ -149,7 +149,7 @@ public abstract class TargetImpl implements Target {
@Override
public boolean isRequired(UUID sourceId, Game game) {
MageObject object = game.getObject(sourceId);
if (!requiredExplicitlySet && object != null && object instanceof Ability) {
if (!requiredExplicitlySet && object instanceof Ability) {
return isRequired((Ability) object);
} else {
return isRequired();

View file

@ -60,7 +60,7 @@ public class TargetSource extends TargetObject {
public void addTarget(UUID id, Ability source, Game game) {
if (targets.size() < maxNumberOfTargets) {
MageObject object = game.getObject(id);
if (object != null && object instanceof StackObject) {
if (object instanceof StackObject) {
addTarget(((StackObject) object).getSourceId(), source, game, notTarget);
}
else {

View file

@ -37,7 +37,7 @@ public class CastSpellYourLastTurnWatcher extends Watcher {
lastActivePlayer = game.getActivePlayerId();
if (event.getType() == GameEvent.EventType.SPELL_CAST) {
UUID playerId = event.getPlayerId();
if (playerId != null && lastActivePlayer != null && playerId.equals(lastActivePlayer)) {
if (playerId != null && playerId.equals(lastActivePlayer)) {
amountOfSpellsCastOnCurrentTurn.putIfAbsent(playerId, 0);
amountOfSpellsCastOnCurrentTurn.compute(playerId, (k, a) -> a + 1);
}