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.