}
if (type != null) {
FilterPermanent filter = new FilterControlledPermanent(new StringBuilder("permanent you control of type ").append(type.toString()).toString());
filter.add(new CardTypePredicate(type));
TargetPermanent target = new TargetControlledPermanent(1, 1, filter, false);
target.setNotTarget(true);
// you always go first
if (target.canChoose(you.getId(), game)) {
while (you.isInGame() && !target.isChosen() && target.canChoose(you.getId(), game)) {
you.choose(Outcome.Sacrifice, target, source.getSourceId(), game);
}
Permanent permanent = game.getPermanent(target.getFirstTarget());
if (permanent != null) {
chosen.add(permanent);
}
}
target.clearChosen();
// opponents follow
for (UUID playerId : game.getPlayerList()) {
if (playerId != you.getId()) {
Player player = game.getPlayer(playerId);
if (target.canChoose(playerId, game)) {
while (!target.isChosen() && target.canChoose(playerId, game)) {
player.choose(Outcome.Sacrifice, target, source.getSourceId(), game);
}
Permanent permanent = game.getPermanent(target.getFirstTarget());
if (permanent != null) {
chosen.add(permanent);
}
target.clearChosen();
}
}
}
// all chosen permanents are sacrificed together