How to store data in a separate file?

Discussion in 'Plugin Development' started by WishMachine, Apr 12, 2015.

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

    WishMachine

    Basically, I recently made a plugin that stores position data in an array list that can be accessed by anyone on the server through a command. The problem is that the array lists are reset when the server is reloaded. I'm wondering how I can store the array list data in a separate file? This is a pretty broad question but I've never been good with the part of java that deals with external files and data...

    Thanks in advance
     
  2. Invisible

    nverdier

    @WishMachine
    1) Create a YAML file.
    2) Load a YamlConfiguration
    3) Modify the YamlConfiguration
    4) Save it to the file.
    5) Retrieve it from the file.
     
  3. Offline

    Zombie_Striker

    You can use getConfig() to get the plugin's config.yml, set the things with .set(The path e.g."Plugin.player.X", the value (100 or "String", ect.)), and then get it by using .get(The path).

    Once you're done, do saveConfig(); and will will update the config.yml


    If this fixed your problem, mark as [Solved]
     
    Last edited: Apr 12, 2015
    WishMachine likes this.
  4. Offline

    WishMachine


    Im coming back to the this thread and I noticed you reply again. I'm wondering if you could point me to a tutorial for this?
     
  5. Offline

    meguy26

    @WishMachine
    Alternatively, you could create your own data saving API, use another one such as JSON.
    I would be shamelessly promoting my own data saving API if it was finished, but its not. If you want I could give you a link, but the Bukkit configuration API is probably your best bet.
     
  6. Offline

    WishMachine

    I was looking at that one pretty extensively, but it's not exactly what I'm looking for, unless I'm reading it wrong.
    I just want to have another file where I can input and read data off of. I'm pretty sure I can just us a .dat file instead and I might just do that
     
  7. Offline

    meguy26

    @WishMachine
    Pretty sure that you do want the configuration API, because it is possible to use it to create additional YAMLs. @timtower provided me with this class (http://pastebin.com/aEjiW3Ze) which can be used to create custon YAML files,
     
  8. Offline

    WishMachine

    Alright, I think Ill just look into using a .dat file because that seems easiest. Thanks for your help
     
Thread Status:
Not open for further replies.

Share This Page