mirror of
https://github.com/BentoBoxWorld/BentoBox.git
synced 2024-11-27 21:27:44 +01:00
MAJOR changes to Panel API
All methods in PanelBuilder follow the Builder pattern (no more "set...") nextSlot() now returns the first unoccupied slot
This commit is contained in:
parent
f648c936ad
commit
c60f92b7b3
@ -14,29 +14,71 @@ public class PanelBuilder {
|
||||
private User user;
|
||||
private PanelListener listener;
|
||||
|
||||
public PanelBuilder setName(String name) {
|
||||
public PanelBuilder name(String name) {
|
||||
this.name = name;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Add item to the panel in the last slot.
|
||||
* @param item - Panel item
|
||||
* @return PanelBuilder
|
||||
*/
|
||||
public PanelBuilder item(PanelItem item) {
|
||||
return item(nextSlot(), item);
|
||||
}
|
||||
|
||||
/**
|
||||
* 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) {
|
||||
public PanelBuilder item(int slot, PanelItem item) {
|
||||
items.put(slot, item);
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Forces panel to be a specific number of slots.
|
||||
* @param size
|
||||
* @return PanelBuilder
|
||||
*/
|
||||
public PanelBuilder size(int size) {
|
||||
this.size = size;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the user who will get this panel. This will open it immediately when it is built
|
||||
* @param user - the User
|
||||
* @return PanelBuilder
|
||||
*/
|
||||
public PanelBuilder user(User user) {
|
||||
this.user = user;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets which PanelListener will listen for clicks
|
||||
* @param listener
|
||||
* @return PanelBuilder
|
||||
*/
|
||||
public PanelBuilder listener(PanelListener listener) {
|
||||
this.listener = listener;
|
||||
return this;
|
||||
}
|
||||
|
||||
public int nextSlot() {
|
||||
if (items.isEmpty()) {
|
||||
return 0;
|
||||
} else {
|
||||
return items.lastEntry().getKey() + 1;
|
||||
for (int i = 0; i < 54; i++) {
|
||||
if (!slotOccupied(i)) return i;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if a slot is occupied in the panel or not
|
||||
@ -54,48 +96,4 @@ public class PanelBuilder {
|
||||
public Panel build() {
|
||||
return new Panel(name, items, size, user, listener);
|
||||
}
|
||||
|
||||
/**
|
||||
* Add item to the panel in the last slot.
|
||||
* @param item - Panel item
|
||||
* @return PanelBuilder
|
||||
*/
|
||||
public PanelBuilder addItem(PanelItem item) {
|
||||
if (items.isEmpty()) {
|
||||
items.put(0, item);
|
||||
} else {
|
||||
items.put(items.lastEntry().getKey() + 1, item);
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Forces panel to be a specific number of slots.
|
||||
* @param size
|
||||
* @return PanelBuilder
|
||||
*/
|
||||
public PanelBuilder setSize(int size) {
|
||||
this.size = size;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the user who will get this panel. This will open it immediately when it is built
|
||||
* @param user - the User
|
||||
* @return PanelBuilder
|
||||
*/
|
||||
public PanelBuilder setUser(User user) {
|
||||
this.user = user;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets which PanelListener will listen for clicks
|
||||
* @param listener
|
||||
* @return PanelBuilder
|
||||
*/
|
||||
public PanelBuilder setListener(PanelListener listener) {
|
||||
this.listener = listener;
|
||||
return this;
|
||||
}
|
||||
}
|
||||
|
@ -189,7 +189,6 @@ public class MySQLDatabaseHandler<T> extends AbstractDatabaseHandler<T> {
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* Creates a comma-separated-String with the names of the variables in this
|
||||
* class
|
||||
* Not used in Flat File database.
|
||||
|
@ -18,18 +18,18 @@ public class SettingsPanel {
|
||||
*/
|
||||
public static void openPanel(User user) {
|
||||
PanelBuilder panelBuilder = new PanelBuilder()
|
||||
.setName(user.getTranslation("protection.panel.title"));
|
||||
.name(user.getTranslation("protection.panel.title"));
|
||||
|
||||
PanelItem help = new PanelItemBuilder()
|
||||
.name(user.getTranslation("protection.panel.help-item.name"))
|
||||
.icon("crashdummie99") // Question marks
|
||||
.build();
|
||||
|
||||
panelBuilder.addItem(8, help);
|
||||
panelBuilder.item(8, help);
|
||||
|
||||
for (Flag flag : BSkyBlock.getInstance().getFlagsManager().getFlags()) {
|
||||
PanelItem flagIcon = flag.toPanelItem(user);
|
||||
panelBuilder.addItem(flagIcon);
|
||||
panelBuilder.item(flagIcon);
|
||||
}
|
||||
|
||||
panelBuilder.build().open(user);
|
||||
|
Loading…
Reference in New Issue
Block a user