diff --git a/common/src/main/kotlin/com/bluedragonmc/server/module/GuiModule.kt b/common/src/main/kotlin/com/bluedragonmc/server/module/GuiModule.kt index fb971ec..e95a394 100644 --- a/common/src/main/kotlin/com/bluedragonmc/server/module/GuiModule.kt +++ b/common/src/main/kotlin/com/bluedragonmc/server/module/GuiModule.kt @@ -1,6 +1,7 @@ package com.bluedragonmc.server.module import com.bluedragonmc.server.Game +import com.bluedragonmc.server.event.PlayerLeaveGameEvent import net.kyori.adventure.text.Component import net.minestom.server.entity.GameMode import net.minestom.server.entity.Player @@ -40,7 +41,15 @@ open class GuiModule : GameModule() { override fun initialize(parent: Game, eventNode: EventNode) { eventNode.addListener(InventoryCloseEvent::class.java) { event -> - inventories[event.inventory?.windowId]?.let { + inventories.remove(event.inventory?.windowId)?.let { + it.destroy(event.player) + it.onClosedAction?.invoke(event.player) + inventories.remove(event.inventory?.windowId) + } + } + eventNode.addListener(PlayerLeaveGameEvent::class.java) { event -> + val openInv = event.player.openInventory?.windowId ?: return@addListener + inventories.remove(openInv)?.let { it.destroy(event.player) it.onClosedAction?.invoke(event.player) }