Saving Data with a file

Discussion in 'Spigot Plugin Development' started by bman7842, Jun 9, 2015.

  1. I'm working on a scoreboard plugin that needs to save special local scores and player data. I'm making this plugin for someone else and I need a way to store the data locally onto a config. Instead of it being stored in the actual config, I want to create a separate file that is locked or protected so that the user is unable to edit it. Also, when creating this file what would be a good way of storing the data, should I do something like UUID:Data and then separate it when loading the data or is there a better way. I'm more of an SQL developer so Files in Java is new territory for me. Any help and advice would be great! Thanks!
  2. Anything stored locally is vulnerable.
  3. Okay still, an example or suggestion of the best way to do it would be nice.
  4. If you are storing a lot of information I'd recommend using sql - otherwise you can use java's PrintWriter class to write to a .txt file. If you use PrintWriter with FileWriter in the right way, you can append to a file; otherwise normally it will just overwrite.

    You can also use a FileOutputStream object in a DataOutputStream's constructor to then write data to a .dat file.
  5. You mentioned sql, and most scrubs don't know sql, use sqlite with JDBC :)
  6. You could just save the objects directly to a file. Make it a .dat file extension and when they try to open it they just see funky characters, nothing useful at all for editing.
    • Like Like x 1
  7. SQLite Is just like SQL but it is local on a file. It uses pretty much the same commands and methods :p
  8. that me all put together
  9. I know you can serialize an object to a file with a .ser extension (assuming it implements Serializable) - the same goes with .dat too?