Modifying system.properties

Discussion in 'Plugin Development' started by hockeygoalie5, Jun 8, 2012.

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

    hockeygoalie5

    I am creating a plugin that features a map cycle. After a server restarts, the maps reload to a saved backup, a map is picked from the map list, and that map is (should be) loaded. In order to change the map, I need to edit the system.properties file. Currently, I have everything working, for the most part. The file is read and saved to a temporary file, the level-name line is changed to the chosen map, and then the file replaces the system.properties file. The only problem is that I can't replace the file because the server is preventing it. Is there any way at all to load a different map with a plugin? If not, where do you suggest I go from here?
     
  2. Offline

    stelar7

    playerloginevent->teleport to world
     
  3. Offline

    hockeygoalie5

    I can not get a Location to teleport to because the world would not be loaded unless it's set as the level-name in the properties file.

    EDIT: For some reason, it is working how I had it now. The server will load the modified server.properties when it restarts next, which still maintains the functionality of the map cycle.
     
  4. you can load the world whit methodes
     
  5. Offline

    Firefly

    How did you go about accessing server.properties? I can't seem to access the root folder it's located in. If you could share some code, that would be awesome! :D
     
  6. Offline

    hockeygoalie5

    No problem! The whole plugin is open source: http://dev.bukkit.org/server-mods/easy-lite-survival-games-manager/repositories/mainline/. Here's the code you're looking for:
    Code:
    static File serverProperties = new File("server.properties");
    static File newProperties = new File("newserver.properties");
     
    ...
     
    public static void changeMap(String map) {
        SurvivalGames.log.info("Next level is '"+map+"'.");
        try {
            newProperties.createNewFile();
            Vector<String> lines = new Vector<String>();
            int line = -1;
            BufferedWriter write = new BufferedWriter(new FileWriter(newProperties));
            LineNumberReader read = new LineNumberReader(new FileReader(serverProperties));
            for(int i = 0, ii = getLines(serverProperties); i < ii; i++) {
                String current = read.readLine();
                lines.add(current);
                if(current.contains("level-name")) {
                    line = read.getLineNumber()-1;
                    lines.set(line, "level-name="+map);
                }
            }
            read.close();
            for(int i = 0, ii = lines.size(); i < ii; i++) {
                if(i > 0) {
                    write.append(br);
                }
                write.append(lines.elementAt(i));
            }
            write.close();
            serverProperties.delete();
            newProperties.renameTo(serverProperties);
            newProperties.delete();
        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
    }
    The root directory is the root directory of the server (where the Bukkit jar is). So, to access the server.properties file, the path is just server.properties.
     
  7. Offline

    Firefly

    Ahh! Thanks a bunch :)

    What does the variable "br" represent?

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

    hockeygoalie5

    Sorry for the rather late reply, didn't get a notification. "Br" is a line break and is set to System.getProperty("line.separator").
     
  9. Offline

    Firefly

    Ahh, I figured as much considering it's named like the HTML <br> tag, but I wasn't sure how to do that in Java. Thanks :)
     
Thread Status:
Not open for further replies.

Share This Page