Properties File

Discussion in 'Plugin Development' started by Snowl, Jan 20, 2011.

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


    Hey :D I'm trying to create a properties file but PropertiesFile doesn't do what I'm looking for. I know i'm supposed to use SQLite but the plugin is more better suited to flatfile.

    Anyway, I'm trying to create my first plugin in java and heres how it is supposed to be:

    # Author: Nilaky
    # Preface all commented lines with #
    # All other lines should be in the form:
    # blockID:drop1,drop2,drop3:probability
    # CustomDrops is designed to replace existing drops!
    # For example:
    # 2:295:0.5
    # will make grass(2) drop seeds(295) 50% of the time
    # but this replaces the dirt that would drop
    # To keep the old drops, try something like:
    # 2:295:0.5
    # 2:3:1.0
    # this makes grass(2) always drop dirt(3)
    # but have a 50% chance to ALSO drop seeds(295)
    # Sand

    I currently have properties that are more like
    and I dont know how to read more two variables, and I'd rather have old compatibility with the plugin.

    I have no idea how to create a properties file formatted like that.
    Here's my current reading format:

                    PropertiesFile myPluginSettings = new PropertiesFile( "" );
                    blockddddd = myPluginSettings.getInt( convertSimple(blockid) , blockid );
    Any help would be appreciated. Thanks.
  2. Offline


    You may have to write your own file reader.

    You could then read a line and use the split command.

    BufferedReader in = new BufferedReader(new FileReader(new File(directory, "your_filename.txt"));
    String line;
    while( (line=in.readLine() ) != null ) {
        String lineTrim = line.trim();
        if( lineTrim.startsWith( "#" ) ) {
        String[] split = lineTrim.split(":");
        int blockId = Integer.parseInt(split[0]));
        int dropId = Integer.parseInt(split[1]));
        double p = Double.parseDouble(split[2]));
        <your code>
    try {
    } catch (IOExeception ioe) {
        <give error message that you can't close file>
    This assumes that directory is the folder that you are given as part of the plugin constructor.

    The trim will remove white spaces at the start and end of the line and the split will break it into pieces using : as the split point.

    This does no error checking, so faulty files will throw exceptions. You may also need a try{} catch() {} around the in.close() line.

    I haven't checked the above, so it may not work.
  3. Offline


    Wow, thanks! I'll see if I can get it working tomorow :)
Thread Status:
Not open for further replies.

Share This Page