From 1aa33e87c5433a9ce23dde5d2dcfd7d1bf16cc3d Mon Sep 17 00:00:00 2001 From: EpicKnarvik97 Date: Wed, 10 May 2023 15:37:18 +0200 Subject: [PATCH] Allows using an existing item stack for an item factory --- src/main/java/net/knarcraft/knargui/AbstractGUI.java | 5 +++++ src/main/java/net/knarcraft/knargui/GUIRegistry.java | 1 - src/main/java/net/knarcraft/knargui/KnarGUI.java | 3 +++ .../net/knarcraft/knargui/item/GUIItemFactory.java | 10 ++++++++++ 4 files changed, 18 insertions(+), 1 deletion(-) diff --git a/src/main/java/net/knarcraft/knargui/AbstractGUI.java b/src/main/java/net/knarcraft/knargui/AbstractGUI.java index 526e83e..812b3e7 100644 --- a/src/main/java/net/knarcraft/knargui/AbstractGUI.java +++ b/src/main/java/net/knarcraft/knargui/AbstractGUI.java @@ -47,6 +47,11 @@ public abstract class AbstractGUI { instantiate(inventory); } + /** + * Sets up an abstract GUI using the given inventory + * + * @param inventory

The inventory used for this GUI

+ */ private void instantiate(Inventory inventory) { this.uuid = UUID.randomUUID(); this.inventory = inventory; diff --git a/src/main/java/net/knarcraft/knargui/GUIRegistry.java b/src/main/java/net/knarcraft/knargui/GUIRegistry.java index 94d8d38..623bfa5 100644 --- a/src/main/java/net/knarcraft/knargui/GUIRegistry.java +++ b/src/main/java/net/knarcraft/knargui/GUIRegistry.java @@ -59,7 +59,6 @@ public class GUIRegistry { * @param autoDelete

Whether to immediately delete the closed GUI

*/ public static void closeGUI(Player player, boolean autoDelete) { - //Run the close action if an anvil GUI is used AbstractGUI gui = getOpenGUI(player); //Un-register the player's open GUI openGUIs.remove(player.getUniqueId()); diff --git a/src/main/java/net/knarcraft/knargui/KnarGUI.java b/src/main/java/net/knarcraft/knargui/KnarGUI.java index 9e66306..e319b20 100644 --- a/src/main/java/net/knarcraft/knargui/KnarGUI.java +++ b/src/main/java/net/knarcraft/knargui/KnarGUI.java @@ -1,5 +1,8 @@ package net.knarcraft.knargui; +/** + * Empty main class just in case something runs this directly + */ @SuppressWarnings("unused") public final class KnarGUI { diff --git a/src/main/java/net/knarcraft/knargui/item/GUIItemFactory.java b/src/main/java/net/knarcraft/knargui/item/GUIItemFactory.java index e5925d1..4a8f701 100644 --- a/src/main/java/net/knarcraft/knargui/item/GUIItemFactory.java +++ b/src/main/java/net/knarcraft/knargui/item/GUIItemFactory.java @@ -30,4 +30,14 @@ public class GUIItemFactory extends AbstractGUIItemFactory { setChild(this); } + /** + * Instantiates a new item factory + * + * @param itemStack

The item stack to modify

+ */ + public GUIItemFactory(ItemStack itemStack) { + super(itemStack); + setChild(this); + } + }