MySQL Problem save data

Discussion in 'Spigot Plugin Development' started by Jose198, Apr 1, 2019.

  1. Hi, so my problem is:

    Im making a skywars plugin, when player join all the data from db are loaded and saved in a HashMap<Player, PlayerData>, and all the changes that the player do in game, kills, select cages, etc changes data from that hashmap, and when he leaves i save all the data to the database (map.get(p).save(true) for example).

    Well, the problem is that when a player leaves an arena (This is bungee-mode), and joins skywars-lobby, when he left, all the data goes to db, but he at the same time is joining skywars-lobby and all the data is beeing loaded, so when he joins back the sw-lobby, the player has old data, not the actual data that has been made in the last match.
  2. And what is your actual Problem then?
    What about loading his Data a Bit later when He joins Back to the Lobby?
  3. Welcome to the largest flaw in bungeecord's design!

    How i solved it on my server:

    On Player login i record a player as online a server in a session table
    on logout, i flush all pending db updates to the db and then remove the session record (this requires binding all sql queries related to a players data to the player so you know when they are all finished)

    on bungee, I have a plugin that hooks server connect event, and disconnects current server, and waits 700ms to give time for quit process to run (could make it poll session to wait until its removed instead though of fixed time)

    once the session is removed, then connect to the next server.

    Downside: if the target server is down, they will be disconnected instead of seeing it in chat - but thats a small price to pay for data integrity.

    this is the only real "simple" (and it's not even that simple) solution to this problem (outside of some even crazier solutions)..... have fun :/

Share This Page