Skip to content

Commit

Permalink
Unregister inventories when they're closed and mark inventories as cl…
Browse files Browse the repository at this point in the history
…osed when the player leaves their game or disconnects
  • Loading branch information
FluxCapacitor2 committed Dec 23, 2024
1 parent 02ce762 commit 884479c
Showing 1 changed file with 10 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -40,7 +41,15 @@ open class GuiModule : GameModule() {

override fun initialize(parent: Game, eventNode: EventNode<Event>) {
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)
}
Expand Down

0 comments on commit 884479c

Please sign in to comment.