Uploaded image for project: 'Spigot'
  1. Spigot
  2. SPIGOT-7466

InventoryCloseEvent fires after PlayerQuitEvent (SPIGOT-5799, again)

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Unresolved
    • Icon: Minor Minor
    • None
    • None
    • CraftBukkit version 3859-Spigot-94e187b-f70a7b6 (MC: 1.20.1)
    • DAMNIT
    • Yes

      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)

            Unassigned Unassigned
            Moterius Moterius Moonbeam
            Votes:
            1 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated: