1.17.x Will AsyncPlayerPreLoginEvent always result in PlayerJoinEvent?

Discussion in 'Spigot Plugin Development' started by Nuubles, Oct 20, 2021.

  1. I have a plugin that loads some data in the async method, and assigns it to the player once the player has joined. Is there a possibility that the player decides to disconnect before the PlayerJoinEvent has run, thus resulting in (small) memory leak?

    I'm currently having some problems that once player quits and joins quickly enough, the data gets loaded from the async method, cleared in quit method, and then the plugin attempts to assign the loaded data in the join event, which results in unloaded data although the player can access the server.

    If the prelogin results in join event always, there wouldn't be any need for the quit method to clear "players to be loaded" lists as the join event could clear the load list once the player has joined. Currently the quit method is clearing the data in order to prevent a memory leak,
  2. Afaik no,the player will stay in the "Connecting.." loading screen
  3. f

    this is quite a nasty bug to fix then if that's not possible, it's either a memory leak, an extra thread running to keep the memory in check, or the players will join sometimes without their data being loaded but memory is fine
  4. what is the type of data? where is it used? what is it used for?
  5. Generic player data, such as flight, nicknames, permissions, special plugin attributes, gamemodes etc etc. The data is stored in multiple places of the code and in different plugins, but the problem here is how it is loaded:

    1. Player joins
    2. Successful join
    3. Player quits
    4. Player quit method starts running
    5. Player joins instantly back - async method starts running
    6. async method loads player data to memory
    7. Previously launched quit method clear data from memory
    8. Player joins to the server and launches join event
    9. Join event attempts to assign the loaded data to player but since the data is cleared no permissions, nicknames etc. can be attached to the player

    Permissions and gamemodes etc. must be assigned a few ticks after the join as otherwise they won't be assigned to the player, the problem here is the ordering of those method calls since the async method runs before the quit method has finished execution. This doesn't happen often but a few times a week when a player with weak connection attempts to join and launches the different methods multiple times trying to connect
  6. what about waiting a few seconds before clearing the data? or just loading the data on 1 thread and in 1 event (preferably the player join event)?