Skip to content

Commit

Permalink
Add fill-item builder methods
Browse files Browse the repository at this point in the history
  • Loading branch information
Ravis96 committed Jul 1, 2024
1 parent 40059e1 commit 617c02b
Showing 1 changed file with 66 additions and 0 deletions.
66 changes: 66 additions & 0 deletions core/src/main/java/cc/dreamcode/menu/DreamMenuBuilder.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

import java.util.HashMap;
import java.util.Map;
import java.util.stream.Stream;

@Getter
@RequiredArgsConstructor
Expand Down Expand Up @@ -39,6 +40,71 @@ public DreamMenuBuilder<B, T, I> fillBackground(@NonNull I i) {
return this;
}

public DreamMenuBuilder<B, T, I> fillTop(@NonNull I i) {
Stream.of(
MenuUtil.countSlot(1, 1),
MenuUtil.countSlot(1, 2),
MenuUtil.countSlot(1, 3),
MenuUtil.countSlot(1, 4),
MenuUtil.countSlot(1, 5),
MenuUtil.countSlot(1, 6),
MenuUtil.countSlot(1, 7),
MenuUtil.countSlot(1, 8),
MenuUtil.countSlot(1, 9)
).forEach(slot -> {
if (!this.items.containsKey(slot)) {
this.items.put(slot, i);
}
});

return this;
}

public DreamMenuBuilder<B, T, I> fillBottom(@NonNull I i) {
Stream.of(
MenuUtil.countSlot(this.rows, 1),
MenuUtil.countSlot(this.rows, 2),
MenuUtil.countSlot(this.rows, 3),
MenuUtil.countSlot(this.rows, 4),
MenuUtil.countSlot(this.rows, 5),
MenuUtil.countSlot(this.rows, 6),
MenuUtil.countSlot(this.rows, 7),
MenuUtil.countSlot(this.rows, 8),
MenuUtil.countSlot(this.rows, 9)
).forEach(slot -> {
if (!this.items.containsKey(slot)) {
this.items.put(slot, i);
}
});

return this;
}

public DreamMenuBuilder<B, T, I> fillTopAndBottom(@NonNull I i) {
this.fillTop(i);
this.fillBottom(i);

return this;
}

public DreamMenuBuilder<B, T, I> fillMargin(@NonNull I i) {
this.fillTop(i);
this.fillBottom(i);

for (int row = 2; row < this.rows; row++) {
Stream.of(
MenuUtil.countSlot(row, 1),
MenuUtil.countSlot(row, 9)
).forEach(slot -> {
if (!this.items.containsKey(slot)) {
this.items.put(slot, i);
}
});
}

return this;
}

public abstract B buildEmpty();
public abstract B buildEmpty(@NonNull Map<String, Object> replaceMap);
public abstract B buildWithItems();
Expand Down

0 comments on commit 617c02b

Please sign in to comment.