From b21e6dbcb03e208e13256d1abe39015d302580ac Mon Sep 17 00:00:00 2001 From: Tastybento Date: Sat, 2 Dec 2017 10:09:45 -0800 Subject: [PATCH] Small change to panel builder Enables items to be added without a slot to the end of the inventory. Also enables slots to be queried. --- .../api/panels/builders/PanelBuilder.java | 43 +++++++++++++++++-- 1 file changed, 39 insertions(+), 4 deletions(-) diff --git a/src/main/java/us/tastybento/bskyblock/api/panels/builders/PanelBuilder.java b/src/main/java/us/tastybento/bskyblock/api/panels/builders/PanelBuilder.java index 3916e5eb8..ce49522c5 100644 --- a/src/main/java/us/tastybento/bskyblock/api/panels/builders/PanelBuilder.java +++ b/src/main/java/us/tastybento/bskyblock/api/panels/builders/PanelBuilder.java @@ -1,26 +1,61 @@ package us.tastybento.bskyblock.api.panels.builders; +import java.util.TreeMap; + import us.tastybento.bskyblock.api.panels.Panel; import us.tastybento.bskyblock.api.panels.PanelItem; -import java.util.HashMap; -import java.util.Map; - public class PanelBuilder { private String name; - private Map items = new HashMap<>(); + private TreeMap items = new TreeMap<>(); public PanelBuilder setName(String name) { this.name = name; return this; } + /** + * Add item into a specific slot. If it is already occupied, it will be replaced. + * @param slot - slot + * @param item - Panel item + * @return PanelBuilder + */ public PanelBuilder addItem(int slot, PanelItem item) { this.items.put(slot, item); return this; } + public int nextSlot() { + if (this.items.isEmpty()) { + return 0; + } else { + return items.lastEntry().getKey() + 1; + } + } + + /** + * Checks if a slot is occupied in the panel or not + * @param slot to check + * @return true or false + */ + public boolean slotOccupied(int slot) { + return this.items.containsKey(slot); + } public Panel build() { return new Panel(name, items); } + + /** + * Add item to the panel in the last slot. + * @param item - Panel item + * @return PanelBuilder + */ + public PanelBuilder addItem(PanelItem item) { + if (items.isEmpty()) { + this.items.put(0, item); + } else { + this.items.put(items.lastEntry().getKey() + 1, item); + } + return this; + } }