title: Create 'Custom' Bukkit Plugin YAML File
body: <p>everyone. I have just recently gotten into writing Bukkit plugins for Minecraft. I've already got dev versions for my first two plugins running fine on my server, and they haven't given me much trouble at all. I'm currently working on a third, and I've run into some trouble.</p>
  
  <p>I am trying to figure out how exactly to create a YAML file and read/write data from/to it. Just to clarify, I am NOT referring to a <code>config.yml</code> file, as I am not having any trouble with that. I know how to create a default <code>config.yml</code> file and read data from it, and all that is just fine and dandy. However, with my third plugin, I need to use a separate YAML file. I've looked around for help, but 95% of the answers I get involve someone telling me something about <code>getConfig()</code>, which is NOT what I'm looking for, or at least I'm 95% sure that's not what I'm looking for. After a few weeks of searching for a clear answer, I've decided to post my question here. As always, thanks in advance for any help!</p>
  
  <p>I think I've figured out how to create a YAML file, but I'm stuck after that. I'll just give an example of my situation.</p>
  
  <p>Let's say I had the following main class:</p>
  
  <pre><code>package ...
  
  import ...
  
  //Here is my main class
  public class MyClass extends JavaPlugin {
  
      //I instantiate my File and FileConfiguration here
      //Should I do this? I need them for my other classes.
      public FileConfiguration myFileConfig = null;
      public File myFile;
  
      //On Enable
      @Override
      public void onEnable() {
  
          //Get/Create File
          myFile = new File(getDataFolder(), "myfile.yml");
          if (!myFile.exists()) {
              try {
                  myFile.createNewFile();
              } catch (IOException e) {
                  e.printStackTrace();
              }
          }
  
              //Load myfily.yml file configuration
          FileConfiguration myFileConfig = YamlConfiguration.loadConfiguration(myFile);
  
              //Register my command executor class
          getCommand("test").setExecutor(new myCommandExecutor());
      }
  
      //On Disable
      @Override
      public void onDisable() {
  
          //Irrelevant stuff here
  
      }
  
  }
  </code></pre>
  
  <p>Now say I also had the following CommandExecutor class (the asterisks mark where important stuff happens. I left out all the nested <code>if</code> functions to save your time):</p>
  
  <pre><code>package ...
  
  import ...
  
  public class myCommandExecutor implements CommandExecutor {
  
      @Override
      public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
  
          if (cmd.getName().equalsIgnoreCase("test")) {
  
              if (args.length &gt; 0) {
  
  ****************//RIGHT HERE I WOULD ADD ALL THE COMMAND ARGUMENTS
  ****************//IMAGINE THE FOLLOWING USAGE FOR THE COMMAND
  ****************//USAGE: /test &lt;add|del&gt; &lt;one|two|three&gt; &lt;name&gt;
  ****************//IF THE USER EXECUTED THE FOLLOWING, THE CODE BELOW WOULD BE THE FINAL RESULT
  ****************//EXECUTED: /test add two hello
                  YamlClass.addToFile(args[1], args[2]);
  
              } else {
  
                  sender.sendMessage("Not enough arguments!");
  
              }
  
          }
  
      }
  
  }
  </code></pre>
  
  <p>In the example above, if a user typed <code>/test add two hello</code>, I would want the last two arguments (two and hello) sent to a method in another class (in this example, <code>addToFile(String a, String b)</code> in the class <code>YamlClass</code>) in which args[1] and args[2] would be used to put a string into a file like this:</p>
  
  <pre><code>test:
    one:
    two:
      - hello
    three:
  </code></pre>
  
  <p>and if the user then ran <code>/test add three goodbye</code> the file would look like this:</p>
  
  <pre><code>test:
    one:
    two:
      - hello
    three:
      - goodbye
  </code></pre>
  
  <p>If a user were to then do <code>/test add three test</code> it would add 'test' to the section without replacing the 'goodbye' that was previously added.
  Could anyone give me some help or tips on how to go about doing this?
  Thanks!</p>
  
  <p>[EDIT] I figured it out last night. I was actually doing everything correctly as far as the File and YamlCinfiguration go, there was something wrong with my CommandExecutor, but I fixed it. Thanks for the responses!</p>