if (player != null && mageObject != null) {
Cost cost = new DiscardTargetCost(new TargetCardInHand(new FilterNonlandCard()));
String message = "Discard a nonland card to search your library?";
if (cost.canPay(source, source.getSourceId(), source.getControllerId(), game)
&& player.chooseUse(Outcome.Detriment, message, game)) {
if (cost.pay(source, game, source.getSourceId(), source.getControllerId(), false)) {
Card card = game.getCard(cost.getTargets().getFirstTarget());
if (card == null) {
return false;
}
String targetName = new StringBuilder("card with converted mana cost of ").append(card.getManaCost().convertedManaCost()).toString();