Automatically expand menus to accommodate custom inventory/echest sizes, close #45

feat/data-edit-commands
William 2 years ago
parent 43cd367ca3
commit 4fddbc2b32

@ -568,7 +568,7 @@ public class BukkitPlayer extends OnlineUser {
@Override @Override
public CompletableFuture<Optional<ItemData>> showMenu(@NotNull ItemData itemData, boolean editable, public CompletableFuture<Optional<ItemData>> showMenu(@NotNull ItemData itemData, boolean editable,
int rows, @NotNull MineDown title) { int minimumRows, @NotNull MineDown title) {
final CompletableFuture<Optional<ItemData>> updatedData = new CompletableFuture<>(); final CompletableFuture<Optional<ItemData>> updatedData = new CompletableFuture<>();
// Deserialize the item data to be shown and show it in a triumph GUI // Deserialize the item data to be shown and show it in a triumph GUI
@ -576,7 +576,10 @@ public class BukkitPlayer extends OnlineUser {
try { try {
// Build the GUI and populate with items // Build the GUI and populate with items
final int itemCount = items.length; final int itemCount = items.length;
final StorageBuilder guiBuilder = Gui.storage().title(title.toComponent()).rows(rows).disableAllInteractions(); final StorageBuilder guiBuilder = Gui.storage()
.title(title.toComponent())
.rows(Math.max(minimumRows, (int) Math.ceil(itemCount / 9.0)))
.disableAllInteractions();
final StorageGui gui = editable ? guiBuilder.enableAllInteractions().create() : guiBuilder.create(); final StorageGui gui = editable ? guiBuilder.enableAllInteractions().create() : guiBuilder.create();
for (int i = 0; i < itemCount; i++) { for (int i = 0; i < itemCount; i++) {
if (items[i] != null) { if (items[i] != null) {

@ -206,8 +206,18 @@ public abstract class OnlineUser extends User {
*/ */
public abstract boolean hasPermission(@NotNull String node); public abstract boolean hasPermission(@NotNull String node);
/**
* Show a GUI chest menu to the player, containing the given {@link ItemData}
*
* @param itemData Item data to be shown in the GUI
* @param editable If the player should be able to remove, replace and move around the items
* @param minimumRows The minimum number of rows to show in the chest menu
* @param title The title of the chest menu, as a {@link MineDown} locale
* @return A future returning the {@link ItemData} in the chest menu when the player closes it
* @since 2.1
*/
public abstract CompletableFuture<Optional<ItemData>> showMenu(@NotNull ItemData itemData, boolean editable, public abstract CompletableFuture<Optional<ItemData>> showMenu(@NotNull ItemData itemData, boolean editable,
int rows, @NotNull MineDown title); int minimumRows, @NotNull MineDown title);
/** /**
* Returns true if the player is dead * Returns true if the player is dead

@ -149,7 +149,7 @@ public class DummyPlayer extends OnlineUser {
@Override @Override
public CompletableFuture<Optional<ItemData>> showMenu(@NotNull ItemData itemData, boolean editable, public CompletableFuture<Optional<ItemData>> showMenu(@NotNull ItemData itemData, boolean editable,
int rows, @NotNull MineDown title) { int minimumRows, @NotNull MineDown title) {
// do nothing // do nothing
return CompletableFuture.completedFuture(Optional.empty()); return CompletableFuture.completedFuture(Optional.empty());
} }

Loading…
Cancel
Save