initial rewrite for copy method

This commit is contained in:
Ingmar Goudt 2019-03-19 23:35:38 +01:00
parent f74e4118e0
commit 75dbdbdd32
12 changed files with 38 additions and 49 deletions

View file

@ -2,6 +2,8 @@
package mage.watchers;
import java.io.Serializable;
import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException;
import java.util.UUID;
import mage.constants.WatcherScope;
import mage.game.Game;
@ -76,6 +78,15 @@ public abstract class Watcher implements Serializable {
public abstract void watch(GameEvent event, Game game);
public abstract Watcher copy();
public <T extends Watcher> T copy(){
try {
Constructor<? extends Watcher> constructor = this.getClass().getDeclaredConstructor(getClass());
constructor.setAccessible(true);
return (T) constructor.newInstance(this);
} catch (InstantiationException | IllegalAccessException | NoSuchMethodException | InvocationTargetException e) {
e.printStackTrace();
}
return null;
}
}

View file

@ -34,10 +34,10 @@ public class BlockedAttackerWatcher extends Watcher {
}
}
@Override
public BlockedAttackerWatcher copy() {
return new BlockedAttackerWatcher(this);
}
// @Override
// public BlockedAttackerWatcher copy() {
// return new BlockedAttackerWatcher(this);
// }
@Override
public void watch(GameEvent event, Game game) {

View file

@ -36,9 +36,4 @@ public class BloodthirstWatcher extends Watcher {
}
}
}
@Override
public BloodthirstWatcher copy() {
return new BloodthirstWatcher(this);
}
}

View file

@ -81,10 +81,10 @@ public class CastSpellLastTurnWatcher extends Watcher {
}
return 0;
}
@Override
public CastSpellLastTurnWatcher copy() {
return new CastSpellLastTurnWatcher(this);
}
//
// @Override
// public CastSpellLastTurnWatcher copy() {
// return new CastSpellLastTurnWatcher(this);
// }
}

View file

@ -60,9 +60,9 @@ public class CastSpellYourLastTurnWatcher extends Watcher {
public Integer getAmountOfSpellsCastOnPlayersTurn(UUID playerId) {
return amountOfSpellsCastOnPrevTurn.getOrDefault(playerId, 0);
}
@Override
public CastSpellYourLastTurnWatcher copy() {
return new CastSpellYourLastTurnWatcher(this);
}
//
// @Override
// public CastSpellYourLastTurnWatcher copy() {
// return new CastSpellYourLastTurnWatcher(this);
// }
}

View file

@ -46,11 +46,6 @@ public class DamageDoneWatcher extends Watcher {
this.damagedObjects = new HashMap<>(watcher.damagedObjects);
}
@Override
public DamageDoneWatcher copy() {
return new DamageDoneWatcher(this);
}
@Override
public void watch(GameEvent event, Game game) {
switch (event.getType()) {

View file

@ -33,9 +33,9 @@ public class MorbidWatcher extends Watcher {
}
}
@Override
public MorbidWatcher copy() {
return new MorbidWatcher(this);
}
// @Override
// public MorbidWatcher copy() {
// return new MorbidWatcher(this);
// }
}

View file

@ -56,8 +56,4 @@ public class PlanarRollWatcher extends Watcher {
numberTimesPlanarDieRolled.clear();
}
@Override
public PlanarRollWatcher copy() {
return new PlanarRollWatcher(this);
}
}

View file

@ -30,10 +30,6 @@ public class PlayerDamagedBySourceWatcher extends Watcher {
this.damageSourceIds.addAll(watcher.damageSourceIds);
}
@Override
public PlayerDamagedBySourceWatcher copy() {
return new PlayerDamagedBySourceWatcher(this);
}
@Override
public void watch(GameEvent event, Game game) {

View file

@ -77,8 +77,8 @@ public class PlayerLostLifeNonCombatWatcher extends Watcher {
amountOfLifeLostThisTurn.clear();
}
@Override
public PlayerLostLifeNonCombatWatcher copy() {
return new PlayerLostLifeNonCombatWatcher(this);
}
// @Override
// public PlayerLostLifeNonCombatWatcher copy() {
// return new PlayerLostLifeNonCombatWatcher(this);
// }
}

View file

@ -75,8 +75,8 @@ public class PlayerLostLifeWatcher extends Watcher {
amountOfLifeLostThisTurn.clear();
}
@Override
public PlayerLostLifeWatcher copy() {
return new PlayerLostLifeWatcher(this);
}
// @Override
// public PlayerLostLifeWatcher copy() {
// return new PlayerLostLifeWatcher(this);
// }
}

View file

@ -35,10 +35,6 @@ public class PlayersAttackedThisTurnWatcher extends Watcher {
}
}
@Override
public PlayersAttackedThisTurnWatcher copy() {
return new PlayersAttackedThisTurnWatcher(this);
}
@Override
public void watch(GameEvent event, Game game) {