[SPIGOT-7466] InventoryCloseEvent fires after PlayerQuitEvent (SPIGOT-5799, again) Created: 23/Aug/23  Updated: 25/Dec/24

Status: Open
Project: Spigot
Component/s: None
Affects Version/s: None
Fix Version/s: None

Type: Bug Priority: Minor
Reporter: Moterius Moonbeam Assignee: Unassigned
Resolution: Unresolved Votes: 1
Labels: 1.20.1, spigot

Version: CraftBukkit version 3859-Spigot-94e187b-f70a7b6 (MC: 1.20.1)
Plugin: DAMNIT
Guidelines Read: Yes

 Description   

Same issue, different version: https://hub.spigotmc.org/jira/browse/SPIGOT-5799

Joining, then leaving a server causes a PlayerQuitEvent to be fired, followed by an InventoryQuitEvent no matter if the player has an open inventory or not (see net.minecraft.server.players.PlayerList.java, lines 512 & 532).

Therefore, given the following code, the following logs are produced:

public class Echo extends JavaPlugin implements Listener {
    @EventHandler
    public void onLeave(PlayerQuitEvent event){
        getLogger().info("PLAYER QUIT TIME IS "+System.nanoTime());
    }

    @EventHandler
    public void onInventoryClose(InventoryCloseEvent event){
        getLogger().info("INVENTORY CLOSE TIME IS "+System.nanoTime());
    }

    @Override
    public void onEnable(){
        getServer().getPluginManager().registerEvents(this,this);
    }
} 
[Server thread/INFO]: Moterius lost connection: Disconnected [00:11:32]
[Server thread/INFO]: [DAMNIT] PLAYER QUIT TIME IS 82778734722200 [00:11:32]
[Server thread/INFO]: [DAMNIT] INVENTORY CLOSE TIME IS 82778752101300 [00:11:32]
[Server thread/INFO]: Moterius left the game

(After reading through the methods called in PlayerList, I came to the conclusion that it is nigh impossible to differentiate the InventoryCloseEvent that is fired indiscrimately from the InventoryCloseEvent fired when the player has an inventory open at the time of leaving the server (PlayerList line 508). Currently, my solution is to keep a list of players that have left the server, populated in PlayerQuitEvent, and remove them when they re-join)


Generated at Tue Apr 15 09:10:52 UTC 2025 using Jira 10.3.3#10030003-sha1:d220e3fefc8dfc6d47f522d3b9a20c1455e12b7b.