From 32fb9bd9c3544cac0603e465dd436aeb109a3fce Mon Sep 17 00:00:00 2001 From: Aquatic Labs <42958451+Snow-Developer@users.noreply.github.com> Date: Fri, 29 Mar 2024 14:00:30 -0500 Subject: [PATCH 1/2] feat: Improve the ModPageGuiSlot to allow for a consumer. --- .../io/fairyproject/bukkit/gui/slot/GuiSlot.java | 12 ++++++------ .../fairyproject/bukkit/gui/slot/ModPageGuiSlot.java | 8 ++++++++ 2 files changed, 14 insertions(+), 6 deletions(-) diff --git a/io.fairyproject.modules/platform.bukkit/bukkit-gui/src/main/java/io/fairyproject/bukkit/gui/slot/GuiSlot.java b/io.fairyproject.modules/platform.bukkit/bukkit-gui/src/main/java/io/fairyproject/bukkit/gui/slot/GuiSlot.java index c1b319c8..6f711a4e 100644 --- a/io.fairyproject.modules/platform.bukkit/bukkit-gui/src/main/java/io/fairyproject/bukkit/gui/slot/GuiSlot.java +++ b/io.fairyproject.modules/platform.bukkit/bukkit-gui/src/main/java/io/fairyproject/bukkit/gui/slot/GuiSlot.java @@ -74,23 +74,23 @@ static ItemSelectorGuiSlot.Builder itemSelector(Pane pane, int x, int y) { } static GuiSlot nextPage(PaginatedPane pane, ItemStack itemStack) { - return new ModPageGuiSlot(pane, itemStack, 1); + return new ModPageGuiSlot(pane, itemStack, 1, null); } static GuiSlot previousPage(PaginatedPane pane, ItemStack itemStack) { - return new ModPageGuiSlot(pane, itemStack, -1); + return new ModPageGuiSlot(pane, itemStack, -1, null); } static GuiSlot nextPage(PaginatedPane pane) { - return new ModPageGuiSlot(pane, ItemBuilder.of(XMaterial.ARROW).name("&aNext Page").build(), 1); + return new ModPageGuiSlot(pane, ItemBuilder.of(XMaterial.ARROW).name("&aNext Page").build(), 1, null); } static GuiSlot previousPage(PaginatedPane pane) { - return new ModPageGuiSlot(pane, ItemBuilder.of(XMaterial.ARROW).name("&aPrevious Page").build(), -1); + return new ModPageGuiSlot(pane, ItemBuilder.of(XMaterial.ARROW).name("&aPrevious Page").build(), -1, null); } - static GuiSlot modPage(PaginatedPane pane, ItemStack itemStack, int mod) { - return new ModPageGuiSlot(pane, itemStack, mod); + static GuiSlot modPage(PaginatedPane pane, ItemStack itemStack, int mod, @Nullable BiConsumer clickCallback) { + return new ModPageGuiSlot(pane, itemStack, mod, clickCallback != null ? event -> clickCallback.accept((Player) event.getWhoClicked(), event.getClick()) : null); } ItemStack getItemStack(@NotNull Player player, @NotNull Gui gui); diff --git a/io.fairyproject.modules/platform.bukkit/bukkit-gui/src/main/java/io/fairyproject/bukkit/gui/slot/ModPageGuiSlot.java b/io.fairyproject.modules/platform.bukkit/bukkit-gui/src/main/java/io/fairyproject/bukkit/gui/slot/ModPageGuiSlot.java index ee936f88..0dcda5ea 100644 --- a/io.fairyproject.modules/platform.bukkit/bukkit-gui/src/main/java/io/fairyproject/bukkit/gui/slot/ModPageGuiSlot.java +++ b/io.fairyproject.modules/platform.bukkit/bukkit-gui/src/main/java/io/fairyproject/bukkit/gui/slot/ModPageGuiSlot.java @@ -8,6 +8,9 @@ import org.bukkit.event.inventory.InventoryClickEvent; import org.bukkit.inventory.ItemStack; import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; + +import java.util.function.Consumer; @RequiredArgsConstructor public class ModPageGuiSlot implements GuiSlot { @@ -15,6 +18,8 @@ public class ModPageGuiSlot implements GuiSlot { private final PaginatedPane pane; private final ItemStack itemStack; private final int mod; + @Nullable + private final Consumer clickCallback; @Override public ItemStack getItemStack(@NotNull Player player, @NotNull Gui gui) { @@ -37,6 +42,9 @@ public void onInventoryClick(@NotNull InventoryClickEvent event, @NotNull Gui gu gui.update(player); XSound.UI_BUTTON_CLICK.play(player); + + if (clickCallback != null) + clickCallback.accept(event); } public void sendCannotPrevious(Player player) { From f26277372a2192d6b69b127362fdd37e2b343b19 Mon Sep 17 00:00:00 2001 From: Aquatic Labs <42958451+snow-developer@users.noreply.github.com> Date: Fri, 29 Mar 2024 14:24:41 -0500 Subject: [PATCH 2/2] fix: Added static methods, bumped version. --- gradle.properties | 2 +- .../io/fairyproject/bukkit/gui/slot/GuiSlot.java | 16 ++++++++++++++++ 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/gradle.properties b/gradle.properties index 1fe7390d..58aa41e3 100644 --- a/gradle.properties +++ b/gradle.properties @@ -23,7 +23,7 @@ # # Fairy -fairy.version = 0.7.1b2-SNAPSHOT +fairy.version = 0.7.1b3-SNAPSHOT gradle-plugin.version = 1.2.0b9 mongojack.version = 4.2.0 diff --git a/io.fairyproject.modules/platform.bukkit/bukkit-gui/src/main/java/io/fairyproject/bukkit/gui/slot/GuiSlot.java b/io.fairyproject.modules/platform.bukkit/bukkit-gui/src/main/java/io/fairyproject/bukkit/gui/slot/GuiSlot.java index 6f711a4e..fa8fee58 100644 --- a/io.fairyproject.modules/platform.bukkit/bukkit-gui/src/main/java/io/fairyproject/bukkit/gui/slot/GuiSlot.java +++ b/io.fairyproject.modules/platform.bukkit/bukkit-gui/src/main/java/io/fairyproject/bukkit/gui/slot/GuiSlot.java @@ -77,18 +77,34 @@ static GuiSlot nextPage(PaginatedPane pane, ItemStack itemStack) { return new ModPageGuiSlot(pane, itemStack, 1, null); } + static GuiSlot nextPage(PaginatedPane pane, ItemStack itemStack, @Nullable BiConsumer clickCallback) { + return new ModPageGuiSlot(pane, itemStack, 1, clickCallback != null ? event -> clickCallback.accept((Player) event.getWhoClicked(), event.getClick()) : null); + } + static GuiSlot previousPage(PaginatedPane pane, ItemStack itemStack) { return new ModPageGuiSlot(pane, itemStack, -1, null); } + static GuiSlot previousPage(PaginatedPane pane, ItemStack itemStack, @Nullable BiConsumer clickCallback) { + return new ModPageGuiSlot(pane, itemStack, -1, clickCallback != null ? event -> clickCallback.accept((Player) event.getWhoClicked(), event.getClick()) : null); + } + static GuiSlot nextPage(PaginatedPane pane) { return new ModPageGuiSlot(pane, ItemBuilder.of(XMaterial.ARROW).name("&aNext Page").build(), 1, null); } + static GuiSlot nextPage(PaginatedPane pane, @Nullable BiConsumer clickCallback) { + return new ModPageGuiSlot(pane, ItemBuilder.of(XMaterial.ARROW).name("&aNext Page").build(), 1, clickCallback != null ? event -> clickCallback.accept((Player) event.getWhoClicked(), event.getClick()) : null); + } + static GuiSlot previousPage(PaginatedPane pane) { return new ModPageGuiSlot(pane, ItemBuilder.of(XMaterial.ARROW).name("&aPrevious Page").build(), -1, null); } + static GuiSlot previousPage(PaginatedPane pane, @Nullable BiConsumer clickCallback) { + return new ModPageGuiSlot(pane, ItemBuilder.of(XMaterial.ARROW).name("&aPrevious Page").build(), -1, clickCallback != null ? event -> clickCallback.accept((Player) event.getWhoClicked(), event.getClick()) : null); + } + static GuiSlot modPage(PaginatedPane pane, ItemStack itemStack, int mod, @Nullable BiConsumer clickCallback) { return new ModPageGuiSlot(pane, itemStack, mod, clickCallback != null ? event -> clickCallback.accept((Player) event.getWhoClicked(), event.getClick()) : null); }