From 82b385e5fff2da5c3b10e93cae5f217db1e43e7d Mon Sep 17 00:00:00 2001 From: yoyosource Date: Sun, 30 Jul 2023 14:22:36 +0200 Subject: [PATCH] Hotfix ScriptGUI removing script on pressing escape when naming Signed-off-by: yoyosource --- .../bausystem/features/script/ScriptGUI.java | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/script/ScriptGUI.java b/BauSystem_Main/src/de/steamwar/bausystem/features/script/ScriptGUI.java index c8098fed..add7ad81 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/script/ScriptGUI.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/script/ScriptGUI.java @@ -20,13 +20,16 @@ package de.steamwar.bausystem.features.script; import de.steamwar.bausystem.BauSystem; +import de.steamwar.bausystem.SWUtils; import de.steamwar.bausystem.features.script.lua.SteamWarPlatform; +import de.steamwar.bausystem.utils.ItemUtils; import de.steamwar.inventory.SWAnvilInv; import de.steamwar.inventory.SWItem; import de.steamwar.inventory.SWListInv; import de.steamwar.linkage.Linked; import de.steamwar.sql.Script; import de.steamwar.sql.SteamwarUser; +import org.bukkit.Bukkit; import org.bukkit.Material; import org.bukkit.entity.Player; import org.bukkit.event.Listener; @@ -39,6 +42,7 @@ import java.util.ArrayList; import java.util.Arrays; import java.util.Collections; import java.util.List; +import java.util.concurrent.atomic.AtomicBoolean; @Linked public class ScriptGUI implements Listener { @@ -119,7 +123,18 @@ public class ScriptGUI implements Listener { open(player); } else { SWAnvilInv inv = new SWAnvilInv(player, BauSystem.MESSAGE.parse("SCRIPT_MENU_GUI_ENTER_NAME", player), name == null ? "" : name); - inv.setCallback(s -> saveWithName(player, meta, s)); + AtomicBoolean saved = new AtomicBoolean(false); + ItemStack itemStack = player.getOpenInventory().getCursor(); + inv.setCallback(s -> { + saveWithName(player, meta, s); + saved.set(true); + }); + inv.addCloseCallback(() -> { + Bukkit.getScheduler().runTaskLater(BauSystem.getInstance(), () -> { + if (saved.get()) return; + SWUtils.giveItemToPlayer(player, itemStack); + }, 1); + }); inv.open(); } }