JoinEvent called earlier than QuitEvent (Bungee switch)

Discussion in 'Spigot Plugin Development' started by TheMelvin, Jul 29, 2018.

  1. Hey,

    When switching from server on a bungee, the JoinEvent on the target server gets called earlier than the quit event on the server you were.

    Code (Text):
    Server 1
    [14:27:06 INFO]: QUIT

    Server 2
    [14:27:05 INFO]: JOIN
    This causes problems in my spigot plugin with data saving and loading. Any fix for this?
  2. Make a plugin which runs the quit saving code before they actually quit, then send them and load it on the join event?

    As in, don't run the save code in the QuitEvent run it in a custom command etc.
    • Like Like x 1
  3. Probably the server switching process or the logger is asynchronous. Try to make ur plugin thread safe.
  4. RcExtract is right. Not sure about how you save data, but there is a possibility that the data is loaded before even completely saved. If you are saving data with field, try volatile keyword. Try concurrentmap, etc. If you are using some libraries for data storage which is not thread safe, you can use a field as a lock. If the saving starts, assign it to false so loading can be paused with while loop. After saving, assign true.
  5. Just using System.out.println for testing, nothing else in the event.