From ba6ba2d01d55d5d8642b9b53849a57a5c8301064 Mon Sep 17 00:00:00 2001 From: Sefiraat Date: Mon, 5 Jul 2021 16:58:57 +0100 Subject: [PATCH 1/4] Fix Recipe book dupe(s) and Block break dupes --- .../sensibletoolbox/api/items/BaseSTBMachine.java | 7 +++++++ .../sensibletoolbox/core/gui/STBInventoryGUI.java | 10 ++++++---- 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/src/main/java/io/github/thebusybiscuit/sensibletoolbox/api/items/BaseSTBMachine.java b/src/main/java/io/github/thebusybiscuit/sensibletoolbox/api/items/BaseSTBMachine.java index 875474d4..831682cd 100644 --- a/src/main/java/io/github/thebusybiscuit/sensibletoolbox/api/items/BaseSTBMachine.java +++ b/src/main/java/io/github/thebusybiscuit/sensibletoolbox/api/items/BaseSTBMachine.java @@ -584,6 +584,13 @@ public void onBlockRegistered(Location location, boolean isPlacing) { @Override public void onBlockUnregistered(Location loc) { + + // Machines broken while viewed allow items to be taken out. + // We need to close the inventories if opened. + for (HumanEntity h : getGUI().getViewers()) { + h.closeInventory(); + } + getGUI().ejectItems(getInputSlots()); getGUI().ejectItems(getOutputSlots()); getGUI().ejectItems(getUpgradeSlots()); diff --git a/src/main/java/io/github/thebusybiscuit/sensibletoolbox/core/gui/STBInventoryGUI.java b/src/main/java/io/github/thebusybiscuit/sensibletoolbox/core/gui/STBInventoryGUI.java index 9170e8da..ee993bca 100644 --- a/src/main/java/io/github/thebusybiscuit/sensibletoolbox/core/gui/STBInventoryGUI.java +++ b/src/main/java/io/github/thebusybiscuit/sensibletoolbox/core/gui/STBInventoryGUI.java @@ -197,10 +197,12 @@ public void show(Player player) { monitor.doRepaint(); } } - Debugger.getInstance().debug(player.getName() + " opened GUI for " + getOwningItem()); - setOpenGUI(player, this); - listener.onGUIOpened(player); - player.openInventory(inventory); + if (getOpenGUI(player) == null) { + Debugger.getInstance().debug(player.getName() + " opened GUI for " + getOwningItem()); + setOpenGUI(player, this); + listener.onGUIOpened(player); + player.openInventory(inventory); + } } @Override From 5d0d40995b80957691d0a5fc942d2ea8d01ff69d Mon Sep 17 00:00:00 2001 From: Sefiraat Date: Tue, 6 Jul 2021 21:10:45 +0100 Subject: [PATCH 2/4] Applied feedback --- .../sensibletoolbox/api/gui/InventoryGUI.java | 5 +++++ .../sensibletoolbox/api/items/BaseSTBMachine.java | 4 +--- .../sensibletoolbox/core/gui/STBInventoryGUI.java | 13 ++++++++++++- 3 files changed, 18 insertions(+), 4 deletions(-) diff --git a/src/main/java/io/github/thebusybiscuit/sensibletoolbox/api/gui/InventoryGUI.java b/src/main/java/io/github/thebusybiscuit/sensibletoolbox/api/gui/InventoryGUI.java index 3108881b..53e03fb6 100644 --- a/src/main/java/io/github/thebusybiscuit/sensibletoolbox/api/gui/InventoryGUI.java +++ b/src/main/java/io/github/thebusybiscuit/sensibletoolbox/api/gui/InventoryGUI.java @@ -156,6 +156,11 @@ public interface InventoryGUI { */ void show(Player player); + /** + * Hides this GUI from all players + */ + void hideForAll(); + /** * Hide this GUI from the given player (pop it down) * diff --git a/src/main/java/io/github/thebusybiscuit/sensibletoolbox/api/items/BaseSTBMachine.java b/src/main/java/io/github/thebusybiscuit/sensibletoolbox/api/items/BaseSTBMachine.java index 831682cd..f402602a 100644 --- a/src/main/java/io/github/thebusybiscuit/sensibletoolbox/api/items/BaseSTBMachine.java +++ b/src/main/java/io/github/thebusybiscuit/sensibletoolbox/api/items/BaseSTBMachine.java @@ -587,9 +587,7 @@ public void onBlockUnregistered(Location loc) { // Machines broken while viewed allow items to be taken out. // We need to close the inventories if opened. - for (HumanEntity h : getGUI().getViewers()) { - h.closeInventory(); - } + getGUI().hideForAll(); getGUI().ejectItems(getInputSlots()); getGUI().ejectItems(getOutputSlots()); diff --git a/src/main/java/io/github/thebusybiscuit/sensibletoolbox/core/gui/STBInventoryGUI.java b/src/main/java/io/github/thebusybiscuit/sensibletoolbox/core/gui/STBInventoryGUI.java index ee993bca..2ed5313a 100644 --- a/src/main/java/io/github/thebusybiscuit/sensibletoolbox/core/gui/STBInventoryGUI.java +++ b/src/main/java/io/github/thebusybiscuit/sensibletoolbox/core/gui/STBInventoryGUI.java @@ -103,6 +103,10 @@ private static void setOpenGUI(Player player, InventoryGUI gui) { } } + private boolean hasOpenGUI(Player player) { + return getOpenGUI(player) == null; + } + @Override public void addGadget(ClickableGadget gadget) { int slot = gadget.getSlot(); @@ -197,7 +201,7 @@ public void show(Player player) { monitor.doRepaint(); } } - if (getOpenGUI(player) == null) { + if (hasOpenGUI(player)) { Debugger.getInstance().debug(player.getName() + " opened GUI for " + getOwningItem()); setOpenGUI(player, this); listener.onGUIOpened(player); @@ -205,6 +209,13 @@ public void show(Player player) { } } + @Override + public void hideForAll() { + for (HumanEntity player : new ArrayList<>(inventory.getViewers())) { + hide((Player) player); + } + } + @Override public void hide(Player player) { Debugger.getInstance().debug(player.getName() + ": hide GUI"); From 06496d895df248f4def1b87b78361550011000d4 Mon Sep 17 00:00:00 2001 From: Sefiraat Date: Tue, 20 Jul 2021 11:36:37 +0100 Subject: [PATCH 3/4] Nonnull player annotation --- .../sensibletoolbox/core/gui/STBInventoryGUI.java | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/main/java/io/github/thebusybiscuit/sensibletoolbox/core/gui/STBInventoryGUI.java b/src/main/java/io/github/thebusybiscuit/sensibletoolbox/core/gui/STBInventoryGUI.java index 2ed5313a..95faa270 100644 --- a/src/main/java/io/github/thebusybiscuit/sensibletoolbox/core/gui/STBInventoryGUI.java +++ b/src/main/java/io/github/thebusybiscuit/sensibletoolbox/core/gui/STBInventoryGUI.java @@ -37,6 +37,8 @@ import me.desht.dhutils.Debugger; import me.desht.dhutils.text.LogUtils; +import javax.annotation.Nonnull; + public class STBInventoryGUI implements InventoryGUI { // some handy stock textures @@ -103,7 +105,7 @@ private static void setOpenGUI(Player player, InventoryGUI gui) { } } - private boolean hasOpenGUI(Player player) { + private boolean hasOpenGUI(@Nonnull Player player) { return getOpenGUI(player) == null; } From bb6a8b81f7f2ccf19f5a8d84465ab84d144d7b89 Mon Sep 17 00:00:00 2001 From: Sefiraat Date: Fri, 1 Oct 2021 20:50:00 +0100 Subject: [PATCH 4/4] Update src/main/java/io/github/thebusybiscuit/sensibletoolbox/api/items/BaseSTBMachine.java Co-authored-by: Sfiguz7 <37039432+Sfiguz7@users.noreply.github.com> --- .../thebusybiscuit/sensibletoolbox/api/items/BaseSTBMachine.java | 1 - 1 file changed, 1 deletion(-) diff --git a/src/main/java/io/github/thebusybiscuit/sensibletoolbox/api/items/BaseSTBMachine.java b/src/main/java/io/github/thebusybiscuit/sensibletoolbox/api/items/BaseSTBMachine.java index f402602a..92718f27 100644 --- a/src/main/java/io/github/thebusybiscuit/sensibletoolbox/api/items/BaseSTBMachine.java +++ b/src/main/java/io/github/thebusybiscuit/sensibletoolbox/api/items/BaseSTBMachine.java @@ -584,7 +584,6 @@ public void onBlockRegistered(Location location, boolean isPlacing) { @Override public void onBlockUnregistered(Location loc) { - // Machines broken while viewed allow items to be taken out. // We need to close the inventories if opened. getGUI().hideForAll();