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;
}
}