Player player = game.getPlayer(source.getControllerId());
if (player != null) {
// Discard X cards
int amount = source.getManaCostsToPay().getX();
int discarded = Math.min(amount, player.getHand().size());
player.discard(amount, source, game);
// then return a card from your graveyard to your hand for each card discarded this way
TargetCardInYourGraveyard target = new TargetCardInYourGraveyard(discarded, new FilterCard());
target.choose(Outcome.ReturnToHand, player.getId(), source.getSourceId(), game);
for (UUID targetId : target.getTargets()) {