// chooses one of them, and the rest are put into their owners' graveyards.
// This is called the "legend rule."
if (legendary.size() > 1) { //don't bother checking if less than 2 legends in play
for (Permanent legend: legendary) {
FilterPermanent filterLegendName = new FilterPermanent();
filterLegendName.add(new SupertypePredicate("Legendary"));
filterLegendName.add(new NamePredicate(legend.getName()));
filterLegendName.add(new ControllerIdPredicate(legend.getControllerId()));
if (getBattlefield().contains(filterLegendName, legend.getControllerId(), this, 2)) {
Player controller = this.getPlayer(legend.getControllerId());
if (controller != null) {
Target targetLegendaryToKeep = new TargetPermanent(filterLegendName);
targetLegendaryToKeep.setTargetName(new StringBuilder(legend.getName()).append(" to keep (Legendary Rule)?").toString());