Skip to content

Commit

Permalink
add new methods
Browse files Browse the repository at this point in the history
  • Loading branch information
Snabeldier committed Jan 18, 2025
1 parent c5b8608 commit 8a1055e
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 5 deletions.
10 changes: 6 additions & 4 deletions src/main/java/minevalley/core/api/Core.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import minevalley.core.api.discord.Webhook;
import minevalley.core.api.economy.BankAccount;
import minevalley.core.api.enums.DebugType;
import minevalley.core.api.gui.FillItem;
import minevalley.core.api.gui.InventoryGui;
import minevalley.core.api.gui.MultiPageGui;
import minevalley.core.api.npc.NPC;
Expand Down Expand Up @@ -547,14 +548,15 @@ public static InventoryGui createGui(@Nonnull Component title, @Nonnegative int
* <br>
* {@code %o%} will be replaced with the amount of pages
*
* @param title title of the inventory
* @param size size of the inventory
* @param title title of the inventory
* @param size size of the inventory
* @param fillItems items to fill the inventory with
* @return new gui-builder
* @throws IllegalArgumentException if the size is invalid (negative, higher than 54 or not a multiple of 9 while being higher than 6)
*/
@Nonnull
public static MultiPageGui createMultiPageGui(@Nonnull Component title, @Nonnegative int size) throws IllegalArgumentException {
return server.createMultiPageGui(size);
public static MultiPageGui createMultiPageGui(@Nonnull Component title, @Nonnegative int size, @Nonnull List<FillItem> fillItems) throws IllegalArgumentException {
return server.createMultiPageGui(title, size, fillItems);
}

/**
Expand Down
3 changes: 2 additions & 1 deletion src/main/java/minevalley/core/api/CoreServer.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import minevalley.core.api.discord.Webhook;
import minevalley.core.api.economy.BankAccount;
import minevalley.core.api.enums.DebugType;
import minevalley.core.api.gui.FillItem;
import minevalley.core.api.gui.InventoryGui;
import minevalley.core.api.gui.MultiPageGui;
import minevalley.core.api.npc.NPC;
Expand Down Expand Up @@ -154,7 +155,7 @@ public interface CoreServer {
InventoryGui createGUI(@Nonnull Component title, @Nonnegative int size) throws IllegalArgumentException;

@Nonnull
MultiPageGui createMultiPageGui(@Nonnegative int size) throws IllegalArgumentException;
MultiPageGui createMultiPageGui(@Nonnull Component title, @Nonnegative int size, @Nonnull List<FillItem> fillItems) throws IllegalArgumentException;

@Nonnull
World getMainWorld();
Expand Down
29 changes: 29 additions & 0 deletions src/main/java/minevalley/core/api/gui/FillItem.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package minevalley.core.api.gui;

import minevalley.core.api.Core;
import minevalley.core.api.users.OnlineUser;
import org.bukkit.entity.Player;
import org.bukkit.event.inventory.InventoryClickEvent;
import org.bukkit.inventory.ItemStack;

import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import java.util.function.BiConsumer;
import java.util.function.Consumer;

public record FillItem(@Nonnull ItemStack itemStack,
@Nullable Consumer<OnlineUser> callback,
@Nullable BiConsumer<OnlineUser, InventoryClickEvent> advancedCallback) {

public FillItem {
if (itemStack == null) throw new IllegalArgumentException("ItemStack cannot be null");
}

@SuppressWarnings("unused")
public void accept(final @Nonnull InventoryClickEvent event) {
if (!(event.getWhoClicked() instanceof Player player)) return;
final OnlineUser user = Core.getOnlineUser(player);
if (callback != null) callback.accept(user);
if (advancedCallback != null) advancedCallback.accept(user, event);
}
}

0 comments on commit 8a1055e

Please sign in to comment.