mirror of
https://github.com/BentoBoxWorld/BentoBox.git
synced 2024-08-19 20:02:52 +02:00
Added various new panel types (#917)
* Add multiple different types of panel. - Inventory panel -> current - Hooper panel -> 5 slot panel - Dropper panel -> 9 slot in 3 rows * code formatting and javadoc improvements in Panel * renamed PanelType to Type * updated to new enum name + javadoc
This commit is contained in:
parent
b9f7d42afa
commit
ead0b02454
|
@ -7,6 +7,7 @@ import java.util.stream.Collectors;
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.Material;
|
import org.bukkit.Material;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
|
import org.bukkit.event.inventory.InventoryType;
|
||||||
import org.bukkit.inventory.Inventory;
|
import org.bukkit.inventory.Inventory;
|
||||||
import org.bukkit.inventory.InventoryHolder;
|
import org.bukkit.inventory.InventoryHolder;
|
||||||
import org.bukkit.inventory.ItemStack;
|
import org.bukkit.inventory.ItemStack;
|
||||||
|
@ -31,19 +32,55 @@ public class Panel implements HeadRequester, InventoryHolder {
|
||||||
private User user;
|
private User user;
|
||||||
private String name;
|
private String name;
|
||||||
|
|
||||||
public Panel(String name, Map<Integer, PanelItem> items, int size, User user, PanelListener listener) {
|
/**
|
||||||
makePanel(name, items, size, user, listener);
|
* Various types of Panel that can be created.
|
||||||
|
* @since 1.7.0
|
||||||
|
*/
|
||||||
|
public enum Type {
|
||||||
|
INVENTORY,
|
||||||
|
HOPPER,
|
||||||
|
DROPPER
|
||||||
}
|
}
|
||||||
|
|
||||||
public Panel() {}
|
public Panel() {}
|
||||||
|
|
||||||
|
public Panel(String name, Map<Integer, PanelItem> items, int size, User user, PanelListener listener) {
|
||||||
|
this(name, items, size, user, listener, Type.INVENTORY);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @since 1.7.0
|
||||||
|
*/
|
||||||
|
public Panel(String name, Map<Integer, PanelItem> items, int size, User user, PanelListener listener, Type type) {
|
||||||
|
makePanel(name, items, size, user, listener, type);
|
||||||
|
}
|
||||||
|
|
||||||
protected void makePanel(String name, Map<Integer, PanelItem> items, int size, User user,
|
protected void makePanel(String name, Map<Integer, PanelItem> items, int size, User user,
|
||||||
PanelListener listener) {
|
PanelListener listener) {
|
||||||
|
this.makePanel(name, items, size, user, listener, Type.INVENTORY);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @since 1.7.0
|
||||||
|
*/
|
||||||
|
protected void makePanel(String name, Map<Integer, PanelItem> items, int size, User user,
|
||||||
|
PanelListener listener, Type type) {
|
||||||
this.name = name;
|
this.name = name;
|
||||||
this.items = items;
|
this.items = items;
|
||||||
size = fixSize(size);
|
|
||||||
// Create panel
|
// Create panel
|
||||||
inventory = Bukkit.createInventory(null, size, name);
|
switch (type) {
|
||||||
|
case INVENTORY:
|
||||||
|
inventory = Bukkit.createInventory(null, fixSize(size), name);
|
||||||
|
break;
|
||||||
|
case HOPPER:
|
||||||
|
inventory = Bukkit.createInventory(null, InventoryType.HOPPER, name);
|
||||||
|
break;
|
||||||
|
case DROPPER:
|
||||||
|
inventory = Bukkit.createInventory(null, InventoryType.DROPPER, name);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
// Fill the inventory and return
|
// Fill the inventory and return
|
||||||
for (Map.Entry<Integer, PanelItem> en: items.entrySet()) {
|
for (Map.Entry<Integer, PanelItem> en: items.entrySet()) {
|
||||||
if (en.getKey() < 54) {
|
if (en.getKey() < 54) {
|
||||||
|
|
|
@ -21,6 +21,7 @@ public class PanelBuilder {
|
||||||
private int size;
|
private int size;
|
||||||
private User user;
|
private User user;
|
||||||
private PanelListener listener;
|
private PanelListener listener;
|
||||||
|
private Panel.Type type = Panel.Type.INVENTORY;
|
||||||
|
|
||||||
public PanelBuilder name(String name) {
|
public PanelBuilder name(String name) {
|
||||||
this.name = ChatColor.translateAlternateColorCodes('&', name);
|
this.name = ChatColor.translateAlternateColorCodes('&', name);
|
||||||
|
@ -85,6 +86,18 @@ public class PanelBuilder {
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets which Panel.Type will be used.
|
||||||
|
* Defaults to {@link Panel.Type#INVENTORY}.
|
||||||
|
* @param type - Panel.Type for this panel.
|
||||||
|
* @return PanelBuilder
|
||||||
|
* @since 1.7.0
|
||||||
|
*/
|
||||||
|
public PanelBuilder type(Panel.Type type) {
|
||||||
|
this.type = type;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the next free slot number after the largest slot.
|
* Get the next free slot number after the largest slot.
|
||||||
* @return next slot number, or -1 in case none has been found.
|
* @return next slot number, or -1 in case none has been found.
|
||||||
|
@ -108,7 +121,7 @@ public class PanelBuilder {
|
||||||
*/
|
*/
|
||||||
public Panel build() {
|
public Panel build() {
|
||||||
// items.lastKey() is a slot position, so the panel size is this value + 1
|
// items.lastKey() is a slot position, so the panel size is this value + 1
|
||||||
return new Panel(name, items, Math.max(size, items.isEmpty() ? size : items.lastKey() + 1), user, listener);
|
return new Panel(name, items, Math.max(size, items.isEmpty() ? size : items.lastKey() + 1), user, listener, type);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -145,4 +158,13 @@ public class PanelBuilder {
|
||||||
public PanelListener getListener() {
|
public PanelListener getListener() {
|
||||||
return listener;
|
return listener;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return the panelType
|
||||||
|
* @since 1.7.0
|
||||||
|
*/
|
||||||
|
public Panel.Type getPanelType() {
|
||||||
|
return type;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user