From c6e7cf4982909c8de78f6e593f74e7ceb5b223b4 Mon Sep 17 00:00:00 2001 From: bluefireoly Date: Fri, 30 Oct 2020 16:09:02 +0100 Subject: [PATCH] Update GUI.kt --- src/main/kotlin/net/axay/kspigot/gui/GUI.kt | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/src/main/kotlin/net/axay/kspigot/gui/GUI.kt b/src/main/kotlin/net/axay/kspigot/gui/GUI.kt index 1f0d84f8..f46bccd5 100644 --- a/src/main/kotlin/net/axay/kspigot/gui/GUI.kt +++ b/src/main/kotlin/net/axay/kspigot/gui/GUI.kt @@ -217,8 +217,16 @@ class GUIInstance( * Stops KSpigot from listening to actions in this * GUI anymore. */ - @Suppress("UNCHECKED_CAST") - fun unregister() = GUIHolder.unregister(this as GUIInstance) + fun unregister() { + + @Suppress("UNCHECKED_CAST") + GUIHolder.unregister(this as GUIInstance) + + // unregister this inv from all elements + currentElements.forEach { it.stopUsing(this) } + currentElements.clear() + + } /** * @return True, if the [inventory] belongs to this GUI.