38public abstract class ItemBag {
43 this.container = container;
46 public abstract String getItem();
48 public abstract String getName();
50 public abstract Predicate<Item> isAllowed();
52 public abstract String getIndication();
54 public void fill(
Player player) {
55 player.message(
"You search your inventory for "+getItem()+
" to put into the "+getName()+
"...");
57 if (Arrays.stream(player.inventory.
getItems()).noneMatch(isAllowed())) {
58 player.message(
"There "+getIndication()+
" no "+getItem()+
" in your inventory that can be added to the "+getName()+
".");
62 Arrays.stream(player.inventory.
getItems()).filter(isAllowed()).forEach(item -> {
63 player.inventory.
remove(item);
67 player.message(
"You add the "+getItem()+
" to your "+getName()+
".");
71 public void empty(
Player player) {
72 if (container.getFreeSlots() == container.capacity()) {
73 player.message(
"The "+getName()+
" is already empty.");
77 player.message(
"You don't have enough inventory space to empty the contents of this "+getName()+
".");
80 for(Item item : container.getItems()) {
86 if(item ==
null)
continue;
88 int amount = item.getAmount();
90 if(amount > freeSlots)
93 container.remove(
new Item(item.getId(), amount));
94 player.inventory.
add(
new Item(item.getId(), item.getAmount()));
99 public void check(
Player player) {
100 player.message(
"You look in your "+getName()+
" and see:");
102 if (container.getFreeSlots() == container.capacity()) {
103 player.message(
"The "+getName()+
" is empty.");
106 for (Item item : container.getItems()) {
107 if(item ==
null)
continue;