How to create YML file

Discussion in 'Plugin Development' started by nir, May 18, 2012.

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

    nir

    hello,
    I need a guide to creating YML file.
    I want insert data and find data in this file.
    I want make war plugin and i need save player group, amount of Kills and amount of death.
    To this i need YML file.

    tnx!
     
  2. Offline

    blackwolf12333

  3. Offline

    nir

    I dont want just config.yml,
    I want create others yml,
    I need guide for this.
     
  4. Offline

    r0306

    nir
    Use a filewriter/bufferedwriter to write stuff into the file.
    Code:
    File yml = new File("stuff.yml");
    if (!yml.exists()) {
    yml.createNewFile();
    }
    
     
  5. Offline

    nir

    It's not work: (not create yml)
    Code:
    package me.berkonir.main;
     
    import java.io.File;
    import java.io.IOException;
    import java.util.logging.Logger;
     
    import org.bukkit.plugin.PluginDescriptionFile;
    import org.bukkit.plugin.PluginManager;
    import org.bukkit.plugin.java.JavaPlugin;
     
    public class NiWar extends JavaPlugin
    {
        public static NiWar plugin;
        public final Logger logger = Logger.getLogger("Minecraft");
        public final PlayerListener pl = new PlayerListener();
     
        @Override
        public void onEnable()
        {
            PluginDescriptionFile pdffile = this.getDescription();
            logger.info(pdffile.getName() + " is enabled");
            PluginManager pm = getServer().getPluginManager();
            pm.registerEvents(pl, this);
            PluginFile();
        }
     
        @Override
        public void onDisable()
        {
            PluginDescriptionFile pdffile = this.getDescription();
            logger.info(pdffile.getName() + " is disabled");
        }
     
     
        private void PluginFile() {
            File pluginfile = new File("plugin.yml");
            if (!pluginfile.exists()){
                try {
                    pluginfile.createNewFile();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
        }
    }
     
  6. Offline

    r0306

    nir
    That path I gave you generated the file directly in the server's folder, not your plugins folder. To define the path inside the plugins folder and automatically create a new folder for your plugin, define the path in the name of the File.
    Code:
    File pluginfile = new File("plugins/NiWar/plugin.yml");
     
  7. Offline

    nir

    How i make default file to this?
    And i need a guide to the options for this function (File), you know guide?
    I intend to (Eg):
    pluginfile.getName()

    and all the option after the Pluginfile.
     
  8. Offline

    r0306

  9. Offline

    nir

    Default yml content.
     
  10. Offline

    r0306

  11. Offline

    nir

    Ok, tnx!

    I have a question.
    How i add pach?
    YML file would look like this:
    Code:
    players:
    kills:
      nirbe: 5
    I know how add something (pluginefile.set(player.getName(), "bla")).

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: May 25, 2016
  12. Offline

    colony88

    So you want that as a default added?
     
  13. Offline

    nir

    yes, how i add default content?
     
  14. Offline

    colony88

  15. Offline

    theluckyg

    Should I import the bukkit "file" or the java one?
     
  16. Offline

    iPoke111

Thread Status:
Not open for further replies.

Share This Page