1.16.1 How to save and read data from file?

Discussion in 'Spigot Plugin Development' started by pixelmate, Aug 2, 2020 at 6:18 PM.

  1. Hi, everybody,

    I'm having a little fun in Java using the Spigot API. I would like to create a ticket system that would save the ticket along with the player's position after using the command /report <message>. Then such requests could be displayed by /reports command.

    Please do not focus on permissions, messages or the commands themselves. I'm just talking about the principle itself, specifically:

    How do you save such tickets/reports? Is it better in a config.yml file or a separate database? I would ask for an example on a code. I'd also like some example of how to display a list of all the tickets/reports directly in the in-game chat when someone uses the /reports command.

    Thank you in advance for any help.
  2. Obviously, how you implement it is up to you, but here is how I do it for a plugin of mine:

    Create an interface with a save/load method, extend it for the different types of storage you support, and add a config option to choose which one the owner wants.

    Example of file saver:
    That should be all you need for saving to a flatfile.
    You can also use a lock system to read/write async, I’d suggest TaskChain by Aikar (The SharedTaskChain feature to be specific)