mirror of
https://github.com/BentoBoxWorld/BentoBox.git
synced 2024-12-22 00:58:04 +01:00
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.
This commit is contained in:
parent
0651d7c941
commit
b21e6dbcb0
@ -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<Integer, PanelItem> items = new HashMap<>();
|
||||
private TreeMap<Integer, PanelItem> 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;
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user