Solved Performace Question Saving Homes

Discussion in 'Spigot Plugin Development' started by JoeyPlayzTV, Feb 22, 2020.

  1. Hey guys, i write my own essentials and now i'm working on the home system.
    I have only a little question. currently i create a yamlconfig on server start. if a player set a home, the home will saved under players uuid in the homes.yml and the file will be saved. now my question. which method is better. creating a new file on join for each player or save all homes in one file? i will not use a database.

    Here the Fileformat:
    Code (YAML):
    homes:
      5b5e36bf-d9f0-4f39-95cb-e6fe585fb4c5
    :
        Tes
    : world:57.38492475669292:69:203.76977219205642:-103.1037:20.699596
        Test
    : world:39.81657557382226:68:191.68292895776676:-334.70276:7.7997236
        Joey
    : world:51.633534483979815:66:257.50504340736995:-115.714325:-5.850221
      f54fe29c-c234-4191-bce5-a3291f9f9629
    : {}
    The locations are serialized for better performance.


    Thanks for answers
     
  2. Config file per player. Imagine how long it would need to load a file with 1k+ user homes in it.
     
    • Agree Agree x 2
  3. ... and editing it each /sethome.
     
  4. I'll go ahead and add to this. You'd likely want to do the file operations in an async call. Reduce the load of the main thread for file operations

    Additionally if solved please mark this thread accordingly!

    Happy coding! :)
     
    • Like Like x 1
  5. Use PersistantData for mc 1.14+
     
  6. Your question has been answered but I thought I'd just chime in and say you can save location without serialising it yourself with
    Code (Text):
    getConfig().set("path", <location obj>);
    and retrieve it through
    Code (Text):
    Location location = getConfig().getLocation("path");
     
  7. Meeh, that saves stuff like yaw and pitch aswell. Depends if OP wants all that saved.
     
  8. FrostedSnowman

    Resource Staff

    You should note that instead of creating your own mashed-up serialization, which is not really structurally efficient, you can have a Home object that implements ConfigurationSerializable. Here is a basic tutorial someone kindly wrote up: https://www.spigotmc.org/threads/tutorial-bukkit-custom-serialization.148781/--or decompile an object in the api which already has an implementation for this i.e Vector

    Some requirements & prerequisites can also be viewed on the javadoc.
     
    • Like Like x 1
  9. Set the thread to solved if your issue has been solved.
     
  10. Yea, i know how to serialize throught bukkit. But the config looks wierd after it. With the ==bukkit etc. My serialization only gets the most important values from the location object and put it into the config. And my serialization does more than seri and deseri it checks also if the world from the location exists. This is extreme save because i can simple check if deserialize == null to find it out.
     
    #11 JoeyPlayzTV, Feb 23, 2020
    Last edited: Feb 23, 2020
  11. I know it has been already answered & solved, but I want to give another alternative which is json. You can save all the data in just 1 line in the file and it will be much smaller in size compared to yaml no matter how much data you store in it.
     
  12. Yea JSON is a good way and i have already worked with it but i dont like the format. It is so confusing througt the "[] {} , ;" etc.
     
  13. Why do you even need to edit the data thru the file? And why do you even need to make the string manually?
     
  14. If i make the string manually, i can better maintain him and it is more practical for me because i can read my own serialization and iam better understand what my own creations do.
     
  15. Consider taking some tutorials on gson, it may help you not make it hand-by-hand because its hell a pain, believe me.
     
    • Agree Agree x 2