From 884479c7b57658608fceb07711b54f0d41f351e0 Mon Sep 17 00:00:00 2001 From: FluxCapacitor2 <31071265+FluxCapacitor2@users.noreply.github.com> Date: Mon, 23 Dec 2024 00:08:11 -0500 Subject: [PATCH] Unregister inventories when they're closed and mark inventories as closed when the player leaves their game or disconnects --- .../com/bluedragonmc/server/module/GuiModule.kt | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) 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) }