From 576cf92a862f1af06230921c82b660cefd3c2763 Mon Sep 17 00:00:00 2001
From: Tech <49742865+DebitCardz@users.noreply.github.com>
Date: Sat, 12 Aug 2023 14:42:32 -0400
Subject: [PATCH] fix: unregister GUI a tick later (#8)

---
 build.gradle.kts                         | 2 +-
 src/main/kotlin/me/tech/mcchestui/GUI.kt | 7 +++++--
 2 files changed, 6 insertions(+), 3 deletions(-)

diff --git a/build.gradle.kts b/build.gradle.kts
index 5cd539d..2c6282c 100644
--- a/build.gradle.kts
+++ b/build.gradle.kts
@@ -8,7 +8,7 @@ val githubActor = project.findProperty("gpr.user") as String? ?: System.getenv("
 val githubToken = project.findProperty("gpr.key") as String? ?: System.getenv("GITHUB_TOKEN")
 
 group = "me.tech"
-version = "1.0.3"
+version = "1.0.4"
 
 repositories {
     mavenCentral()
diff --git a/src/main/kotlin/me/tech/mcchestui/GUI.kt b/src/main/kotlin/me/tech/mcchestui/GUI.kt
index ef1f393..14ad901 100644
--- a/src/main/kotlin/me/tech/mcchestui/GUI.kt
+++ b/src/main/kotlin/me/tech/mcchestui/GUI.kt
@@ -7,6 +7,7 @@
 package me.tech.mcchestui
 
 import net.kyori.adventure.text.Component
+import org.bukkit.Bukkit
 import org.bukkit.Material
 import org.bukkit.entity.HumanEntity
 import org.bukkit.entity.Player
@@ -21,7 +22,7 @@ fun toSlot(x: Int, y: Int, type: GUIType) = (x - 1) + ((y - 1) * type.slotsPerRo
 fun fromSlot(s: Int, type: GUIType) = Pair(s % type.slotsPerRow, s / type.slotsPerRow)
 
 class GUI(
-	plugin: JavaPlugin,
+	private val plugin: JavaPlugin,
 	val title: Component,
 	val type: GUIType,
 	private val render: GUI.() -> Unit
@@ -280,7 +281,9 @@ class GUI(
 			return
 		}
 
-		HandlerList.unregisterAll(this)
+		plugin.server.scheduler.runTask(plugin, Runnable {
+			HandlerList.unregisterAll(this)
+		})
 	}
 }