Solved Saving and Loading Data

Discussion in 'Plugin Development' started by Nashor, Mar 22, 2013.

Thread Status:
Not open for further replies.
  1. Offline

    Nashor

    Hello. Today I am here to ask about saving and loading data. I am working on a faction like plugin and am using XML (JAXB) to store my data. I am wondering what the best way to save and load my data is. Currently, I have the information loaded from a file onEnable and the information saved onto a file onDisable. However, if the server unexpectedly crashes, I fear the data might all be lost. My question is what is the best way to go around saving/loading my data in a safe but efficient way. Thank you.
     
  2. Offline

    PogoStick29

    Save and load the file every few minutes? Also, you might want to look at my tutorial on custom config files:
     
  3. Offline

    Nashor

    Thanks for the video but JAXB works perfectly for what I am doing.
    I've done some testing and here is what I will probably do. Saving a file is actually pretty quick (though my test was a relatively small amount of information I think even a larger amount will still be fast) ranging at only a few milliseconds. Therefore I will probably load the information onEnable into my storage list. Whenever a change is made, it will affect the loaded storage list variable and also save the file. This ensures that the data is being actively saved and that I also do not have to constantly load the information from the file whenever I want to fetch information.
     
  4. Offline

    PogoStick29

    Sounds good :D
     
  5. Offline

    tom1000o

    when i work with large plugins (like the faction like one you're making) i would usually set a sync repeating timer that saves it every 5 or so minutes, just because you never know how often changes will be made. that's just my preference tho, your way ensures minimal data loss while mine risks a few minutes of data loss for better performance on larger servers. best of luck to you ^.^
     
  6. Offline

    Nashor

    You are probably right. This also seems like a bit less of a hassle than what I planned on doing. Thank you for the input!
     
  7. Offline

    tom1000o

    no problem :)
     
Thread Status:
Not open for further replies.

Share This Page