From 3a4a1c97c2d224a697b848139edd0f2e1e2dc64f Mon Sep 17 00:00:00 2001 From: akastijn Date: Sun, 1 Feb 2026 03:35:17 +0100 Subject: [PATCH] Update version to 1.1.2-SNAPSHOT and add a render method using the HumanEntity that owns the GUI --- build.gradle.kts | 2 +- .../alttd/inventory_gui/gui/GuiListener.java | 2 +- .../alttd/inventory_gui/gui/InventoryGui.java | 18 +++++++++++++++++- 3 files changed, 19 insertions(+), 3 deletions(-) diff --git a/build.gradle.kts b/build.gradle.kts index e7456d9..b138f3a 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -9,7 +9,7 @@ val nexusUser = providers.gradleProperty("alttdSnapshotUsername").orNull ?: Syst val nexusPass = providers.gradleProperty("alttdSnapshotPassword").orNull ?: System.getenv("NEXUS_PASSWORD") group = "com.alttd.inventory_gui" -version = "1.1.1-SNAPSHOT" +version = "1.1.2-SNAPSHOT" repositories { mavenCentral() diff --git a/src/main/java/com/alttd/inventory_gui/gui/GuiListener.java b/src/main/java/com/alttd/inventory_gui/gui/GuiListener.java index e41dace..b7f245f 100644 --- a/src/main/java/com/alttd/inventory_gui/gui/GuiListener.java +++ b/src/main/java/com/alttd/inventory_gui/gui/GuiListener.java @@ -84,7 +84,7 @@ public final class GuiListener implements Listener { if (!entry.ownerPluginName().equals(ownerPluginName)) { return null; } - if (event != entry.inv()) { + if (event != entry.inv()) {//FIXME: does this equality check fail, and is it necessary? return null; } return entry; diff --git a/src/main/java/com/alttd/inventory_gui/gui/InventoryGui.java b/src/main/java/com/alttd/inventory_gui/gui/InventoryGui.java index c0e90d6..ee7198c 100644 --- a/src/main/java/com/alttd/inventory_gui/gui/InventoryGui.java +++ b/src/main/java/com/alttd/inventory_gui/gui/InventoryGui.java @@ -6,6 +6,7 @@ import com.alttd.inventory_gui.pane.SimplePane; import lombok.Builder; import lombok.Getter; import lombok.NonNull; +import lombok.extern.slf4j.Slf4j; import net.kyori.adventure.text.Component; import org.bukkit.Bukkit; import org.bukkit.entity.HumanEntity; @@ -24,6 +25,7 @@ import org.jetbrains.annotations.NotNull; * This class is built with flexibility and ease of use in mind, supporting various * customization options, event handling, and row validation to maintain consistency. */ +@Slf4j @Builder public class InventoryGui { @@ -69,11 +71,25 @@ public class InventoryGui { * Renders the GUI's contents into the specified inventory. * @param inv the inventory into which to render the GUI's contents */ - public void render(Inventory inv) { + protected void render(Inventory inv) { inv.clear(); root.render(inv); } + /** + * Renders the GUI's contents into the open inventory of the specified human entity if it exists. + * @param humanEntity the human entity for which to render the GUI's contents + */ + public void render(HumanEntity humanEntity) { + GuiSession.Entry entry = GuiSession.get(humanEntity.getUniqueId()); + if (entry == null) { + log.warn("No GUI session found for player {} during render", humanEntity.getName()); + return; + } + Inventory inv = entry.inv(); + render(inv); + } + /** * Opens the GUI for the specified human entity. * @param humanEntity the human entity for whom to open the GUI