Saving an playergroup

Discussion in 'Plugin Development' started by DSCxSander, Jul 12, 2017.

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

    DSCxSander

    hey guys!

    Inwant to make a kingdom plugin for my own server.
    Inwant to make an /kingdom command what send you to your kingdom, has some info of the total players in your kingdom, ect.

    Staff can create an kingdom with /kingdom create <naam> <prefix>
    But how can I save all this information in an kingdom.yml file?

    Someone that have an toturial on this?
     
  2. Offline

    Machine Maker

    @DSCxSander
    Do you want a tutorial on how to create a custom YAML file? Or just on how to store stuff in one?

    If it's creating custom confine, there is plenty of tutorials out there.

    For saving stuff, I would create a kingdom class that has a constructor that takes all the things you want stored in the file. Then, on enabling the server, read the config, and add each new Kingdom instance to a List of Kingdom objects.
     
  3. Offline

    Lifeonblack

    To create a file
    Code:java
    1. public void createFile(Plugin plugin) {
    2. File file = new File(plugin.getDataFolder(), "yourfile.yml");
    3. if(!file.exists()) {
    4. try {
    5. file.createNewFile();
    6. }catch(IOException e) {
    7. e.printStackTrace();
    8. }
    9. }


    getting config
    Code:java
    1. public FileConfiguration getConfigByFile(String fileName) {
    2. File file = new File(plugin.getDataFolder(), fileName);
    3. return YamlConfiguration.loadConfiguration(file);
    4. }


    saving
    Code:java
    1. public void save() {
    2. File file = new File(plugin.getDataFolder(), "yourfile.yml");
    3. try {
    4. getConfigByFile("yourfile.yml").save(file);
    5. }catch(IOException e) {
    6. e.printStackTrace();
    7. }
    8. }
     
Thread Status:
Not open for further replies.

Share This Page