mirror of
https://github.com/correl/mage.git
synced 2024-12-25 11:11:16 +00:00
initial rewrite for copy method
This commit is contained in:
parent
f74e4118e0
commit
75dbdbdd32
12 changed files with 38 additions and 49 deletions
|
@ -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;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -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) {
|
||||
|
|
|
@ -36,9 +36,4 @@ public class BloodthirstWatcher extends Watcher {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public BloodthirstWatcher copy() {
|
||||
return new BloodthirstWatcher(this);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
// }
|
||||
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
// }
|
||||
}
|
||||
|
|
|
@ -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()) {
|
||||
|
|
|
@ -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);
|
||||
// }
|
||||
|
||||
}
|
||||
|
|
|
@ -56,8 +56,4 @@ public class PlanarRollWatcher extends Watcher {
|
|||
numberTimesPlanarDieRolled.clear();
|
||||
}
|
||||
|
||||
@Override
|
||||
public PlanarRollWatcher copy() {
|
||||
return new PlanarRollWatcher(this);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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) {
|
||||
|
|
|
@ -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);
|
||||
// }
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
// }
|
||||
}
|
||||
|
|
|
@ -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) {
|
||||
|
|
Loading…
Reference in a new issue