package com.github.dtschust.zork.repl.actions; import com.github.dtschust.zork.ZorkGame; import com.github.dtschust.zork.repl.Action; import java.util.List; public class PutAction implements Action { @Override public boolean matchesInput(List arguments) { return arguments.get(0).equals("put"); } @Override public int getMinimumArgCount() { return 4; } @Override public boolean run(ZorkGame game, List arguments) { final String what = arguments.get(1); return game.getContainer(arguments.get(3)) .filter(c -> c.isOpen() && game.inventory.contains(what)) .map(tempContainer -> { tempContainer.addItem(what); game.inventory.remove(what); game.stream.println("Item " + what + " added to " + tempContainer.getName() + "."); return true; }).orElse(false); } }