use of mudmap2.backend.WorldManager in project mudmap2 by Neop.
the class WorldFileList method writeWorldList.
/**
* Saves the available worlds list
* do this after writing the world files or new places won't appear in list
*/
public static void writeWorldList() {
final String file = Environment.getWorldsDir() + "worlds";
try {
// open file
if (!Environment.isDirectory(Environment.getWorldsDir()))
Environment.createDirectory(Environment.getWorldsDir());
try (PrintWriter outstream = new PrintWriter(new BufferedWriter(new FileWriter(file)))) {
outstream.println("# MUD Map (v2) worlds file");
outstream.println("ver " + META_FILE_VER_MAJOR + "." + META_FILE_VER_MINOR);
for (Map.Entry<String, String> w : availableWorlds.entrySet()) {
// check whether the file name in file equals the name in the list
WorldFileDefault worldFile = new WorldFileDefault(w.getKey());
String fw = null;
try {
if (worldFile.canRead()) {
fw = worldFile.readWorldName();
}
} catch (Exception ex) {
Logger.getLogger(WorldManager.class.getName()).log(Level.SEVERE, null, ex);
}
if (fw != null) {
outstream.println("n " + fw);
String w_file = w.getKey();
outstream.println("f " + w_file);
if (w_file.startsWith(Environment.getWorldsDir())) {
w_file = w_file.substring(Environment.getWorldsDir().length());
outstream.println("g " + w_file);
}
}
}
}
} catch (IOException ex) {
System.out.printf("Couldn't write worlds file " + file);
Logger.getLogger(WorldManager.class.getName()).log(Level.INFO, null, ex);
JOptionPane.showMessageDialog(null, "Could not write worlds list file " + file + ".\nYou might have to open your worlds manually from " + Environment.getWorldsDir(), "WorldManager", JOptionPane.WARNING_MESSAGE);
}
}
Aggregations