From 98201061d3877d81e6b1f60db648f719641a48ac Mon Sep 17 00:00:00 2001 From: Chaoscaot Date: Sat, 12 Nov 2022 08:52:11 +0100 Subject: [PATCH] Add Close Button --- BauSystem_Main/src/BauSystem.properties | 1 + BauSystem_Main/src/BauSystem_de.properties | 1 + .../features/gui/editor/BauGuiEditor.java | 17 +++++++++++++---- 3 files changed, 15 insertions(+), 4 deletions(-) diff --git a/BauSystem_Main/src/BauSystem.properties b/BauSystem_Main/src/BauSystem.properties index 1294e2d9..2b9db940 100644 --- a/BauSystem_Main/src/BauSystem.properties +++ b/BauSystem_Main/src/BauSystem.properties @@ -200,6 +200,7 @@ GUI_EDITOR_ITEM_ROW_M=§e-1 Row GUI_EDITOR_ITEM_TRASH=§cTrashcan GUI_EDITOR_ITEM_TRASH_LORE=§7Drop item here GUI_EDITOR_ITEM_MORE=§eMore items +GUI_EDITOR_ITEM_CLOSE=§eClose GUI_EDITOR_TITLE_MORE=Select item # Script diff --git a/BauSystem_Main/src/BauSystem_de.properties b/BauSystem_Main/src/BauSystem_de.properties index 4936643e..65eb1994 100644 --- a/BauSystem_Main/src/BauSystem_de.properties +++ b/BauSystem_Main/src/BauSystem_de.properties @@ -200,6 +200,7 @@ GUI_EDITOR_ITEM_ROW_M=§e-1 Zeile GUI_EDITOR_ITEM_TRASH=§cTrashcan GUI_EDITOR_ITEM_TRASH_LORE=§7Item hier rein Legen GUI_EDITOR_ITEM_MORE=§eMehr Items +GUI_EDITOR_ITEM_CLOSE=§eSchließen GUI_EDITOR_TITLE_MORE=Item auswählen # Script diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/gui/editor/BauGuiEditor.java b/BauSystem_Main/src/de/steamwar/bausystem/features/gui/editor/BauGuiEditor.java index 06c4a41c..733e7213 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/gui/editor/BauGuiEditor.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/gui/editor/BauGuiEditor.java @@ -39,6 +39,7 @@ import org.bukkit.event.inventory.InventoryDragEvent; import org.bukkit.event.player.PlayerMoveEvent; import org.bukkit.event.player.PlayerQuitEvent; import org.bukkit.inventory.Inventory; +import org.bukkit.inventory.InventoryView; import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.meta.ItemMeta; import org.bukkit.persistence.PersistentDataType; @@ -72,6 +73,7 @@ public class BauGuiEditor implements Listener { inv.setItem(mapping.getSize() + 5, new SWItem(Material.BARRIER, BauSystem.MESSAGE.parse("GUI_EDITOR_ITEM_TRASH", p), Arrays.asList(BauSystem.MESSAGE.parse("GUI_EDITOR_ITEM_TRASH_LORE", p)), false, clickType -> { }).getItemStack()); inv.setItem(mapping.getSize() + 6, new SWItem(Material.SCUTE, BauSystem.MESSAGE.parse("GUI_EDITOR_ITEM_MORE", p)).getItemStack()); + inv.setItem(mapping.getSize() + 8, new SWItem(Material.ARROW, BauSystem.MESSAGE.parse("GUI_EDITOR_ITEM_CLOSE", p)).getItemStack()); p.openInventory(inv); p.getOpenInventory().setCursor(cursor == null ? new SWItem().getItemStack() : cursor); @@ -155,6 +157,10 @@ public class BauGuiEditor implements Listener { }); inv.open(); break; + case 8: + saveMapping(p); + BauGUI.openBauGui(p); + break; default: } } @@ -188,14 +194,17 @@ public class BauGuiEditor implements Listener { } private void saveMapping(Player p) { - BauGuiMapping mapping = BauGuiMapping.getGuiMapping(p); + saveMapping(p.getOpenInventory(), BauGuiMapping.getGuiMapping(p)); + } + + private void saveMapping(InventoryView view, BauGuiMapping mapping) { if (mapping.isSaved()) { return; } HashMap newMapping = new HashMap<>(); - for (int i = 0; i < p.getOpenInventory().getTopInventory().getContents().length; i++) { - ItemStack itemStack = p.getOpenInventory().getTopInventory().getContents()[i]; + for (int i = 0; i < view.getTopInventory().getContents().length; i++) { + ItemStack itemStack = view.getTopInventory().getContents()[i]; if (itemStack == null || itemStack.getType() == Material.AIR || i >= mapping.getSize()) continue; newMapping.put(getId(itemStack), i); } @@ -218,7 +227,7 @@ public class BauGuiEditor implements Listener { Player p = (Player) event.getPlayer(); - saveMapping(p); + saveMapping(event.getView(), BauGuiMapping.getGuiMapping(p)); open_Edits.remove(p); } }