Data Files

Discussion in 'Plugin Development' started by islendingabok_team, Apr 13, 2011.

Thread Status:
Not open for further replies.
  1. Hey, I was wondering what is the best/most standardized way to create a plugin data folder with plugin.yml, etc. Is there an inherited method or a certain class to do this with? I checked the JavaDocs and couldn't find much... Thanks for any help I can get, and I would appreciate an example :)
  2. Offline


    you only have the plugindatafolder variable (or something like that) and then I think it's up to you. I use the File object.
  3. Offline

    Edward Hand

    Are you talking about a config.yml file with settings for people to change?

    If so, there are built in methods for accessing that.
    The file must be called config.yml and stored in a folder with the same name as your plugin.

    You can either include this folder+file along with your jar when you distribute your plugin, or you can make your plugin auto-create it. The code below shows the second approach:
    public void onEnable()
    		try {
    		    //Check that folder exists, and if not create it
    		    File folder = new File("plugins/PLUGINNAME");
    		    //Check that the config file exists, and if not create it
    		    File file = new File(folder,"config.yml");
    		    if (!file.exists())
    		        //set some default properties
    		    	getConfiguration().setProperty("someNumericProperty", 9999);
    		    	getConfiguration().setProperty("someStringProperty", "foo bar");
    		} catch (IOException e) {
    			System.out.println("Plugin could not enable");
    		//retrieve values from config file. (second parameter of getter method is default value if not set)
    		int someNumber = getConfiguration().getInt("someNumericProperty",0);
    		String someString = getConfiguration().getString("someStringProperty","");
    Hopefully that makes sense to you. If not, feel free to ask.
  4. o ok thnx thats exactly what i meant. this is rlly helpful :)
  5. Thnx, this was really helpful, but I have one question... I see how to get the String or int value of a root property, but how do I get the value of a nested sub-property? (as in getting 1 for in the example below)

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

Share This Page