mirror of
https://github.com/correl/mage.git
synced 2024-12-26 19:16:54 +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;
|
package mage.watchers;
|
||||||
|
|
||||||
import java.io.Serializable;
|
import java.io.Serializable;
|
||||||
|
import java.lang.reflect.Constructor;
|
||||||
|
import java.lang.reflect.InvocationTargetException;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
import mage.constants.WatcherScope;
|
import mage.constants.WatcherScope;
|
||||||
import mage.game.Game;
|
import mage.game.Game;
|
||||||
|
@ -76,6 +78,15 @@ public abstract class Watcher implements Serializable {
|
||||||
|
|
||||||
public abstract void watch(GameEvent event, Game game);
|
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
|
// @Override
|
||||||
public BlockedAttackerWatcher copy() {
|
// public BlockedAttackerWatcher copy() {
|
||||||
return new BlockedAttackerWatcher(this);
|
// return new BlockedAttackerWatcher(this);
|
||||||
}
|
// }
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void watch(GameEvent event, Game game) {
|
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;
|
return 0;
|
||||||
}
|
}
|
||||||
|
//
|
||||||
@Override
|
// @Override
|
||||||
public CastSpellLastTurnWatcher copy() {
|
// public CastSpellLastTurnWatcher copy() {
|
||||||
return new CastSpellLastTurnWatcher(this);
|
// return new CastSpellLastTurnWatcher(this);
|
||||||
}
|
// }
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -60,9 +60,9 @@ public class CastSpellYourLastTurnWatcher extends Watcher {
|
||||||
public Integer getAmountOfSpellsCastOnPlayersTurn(UUID playerId) {
|
public Integer getAmountOfSpellsCastOnPlayersTurn(UUID playerId) {
|
||||||
return amountOfSpellsCastOnPrevTurn.getOrDefault(playerId, 0);
|
return amountOfSpellsCastOnPrevTurn.getOrDefault(playerId, 0);
|
||||||
}
|
}
|
||||||
|
//
|
||||||
@Override
|
// @Override
|
||||||
public CastSpellYourLastTurnWatcher copy() {
|
// public CastSpellYourLastTurnWatcher copy() {
|
||||||
return new CastSpellYourLastTurnWatcher(this);
|
// return new CastSpellYourLastTurnWatcher(this);
|
||||||
}
|
// }
|
||||||
}
|
}
|
||||||
|
|
|
@ -46,11 +46,6 @@ public class DamageDoneWatcher extends Watcher {
|
||||||
this.damagedObjects = new HashMap<>(watcher.damagedObjects);
|
this.damagedObjects = new HashMap<>(watcher.damagedObjects);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public DamageDoneWatcher copy() {
|
|
||||||
return new DamageDoneWatcher(this);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void watch(GameEvent event, Game game) {
|
public void watch(GameEvent event, Game game) {
|
||||||
switch (event.getType()) {
|
switch (event.getType()) {
|
||||||
|
|
|
@ -33,9 +33,9 @@ public class MorbidWatcher extends Watcher {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
// @Override
|
||||||
public MorbidWatcher copy() {
|
// public MorbidWatcher copy() {
|
||||||
return new MorbidWatcher(this);
|
// return new MorbidWatcher(this);
|
||||||
}
|
// }
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -56,8 +56,4 @@ public class PlanarRollWatcher extends Watcher {
|
||||||
numberTimesPlanarDieRolled.clear();
|
numberTimesPlanarDieRolled.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public PlanarRollWatcher copy() {
|
|
||||||
return new PlanarRollWatcher(this);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -30,10 +30,6 @@ public class PlayerDamagedBySourceWatcher extends Watcher {
|
||||||
this.damageSourceIds.addAll(watcher.damageSourceIds);
|
this.damageSourceIds.addAll(watcher.damageSourceIds);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public PlayerDamagedBySourceWatcher copy() {
|
|
||||||
return new PlayerDamagedBySourceWatcher(this);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void watch(GameEvent event, Game game) {
|
public void watch(GameEvent event, Game game) {
|
||||||
|
|
|
@ -77,8 +77,8 @@ public class PlayerLostLifeNonCombatWatcher extends Watcher {
|
||||||
amountOfLifeLostThisTurn.clear();
|
amountOfLifeLostThisTurn.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
// @Override
|
||||||
public PlayerLostLifeNonCombatWatcher copy() {
|
// public PlayerLostLifeNonCombatWatcher copy() {
|
||||||
return new PlayerLostLifeNonCombatWatcher(this);
|
// return new PlayerLostLifeNonCombatWatcher(this);
|
||||||
}
|
// }
|
||||||
}
|
}
|
||||||
|
|
|
@ -75,8 +75,8 @@ public class PlayerLostLifeWatcher extends Watcher {
|
||||||
amountOfLifeLostThisTurn.clear();
|
amountOfLifeLostThisTurn.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
// @Override
|
||||||
public PlayerLostLifeWatcher copy() {
|
// public PlayerLostLifeWatcher copy() {
|
||||||
return new PlayerLostLifeWatcher(this);
|
// return new PlayerLostLifeWatcher(this);
|
||||||
}
|
// }
|
||||||
}
|
}
|
||||||
|
|
|
@ -35,10 +35,6 @@ public class PlayersAttackedThisTurnWatcher extends Watcher {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public PlayersAttackedThisTurnWatcher copy() {
|
|
||||||
return new PlayersAttackedThisTurnWatcher(this);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void watch(GameEvent event, Game game) {
|
public void watch(GameEvent event, Game game) {
|
||||||
|
|
Loading…
Reference in a new issue