Saves the changes in the world
()
| 237 | * Saves the changes in the world |
| 238 | */ |
| 239 | public void save(){ |
| 240 | if(!worldPanel.isPassive()){ |
| 241 | WorldFile worldFile = getWorld().getWorldFile(); |
| 242 | |
| 243 | if(worldFile == null){ |
| 244 | SaveWorldDialog dlg = new SaveWorldDialog(null, this); |
| 245 | int ret = dlg.showSaveDialog(this); |
| 246 | if(ret == JFileChooser.APPROVE_OPTION){ |
| 247 | getWorld().setWorldFile(dlg.getWorldFile()); |
| 248 | save(); |
| 249 | } |
| 250 | } |
| 251 | |
| 252 | if(worldFile != null){ |
| 253 | // set meta data writer |
| 254 | if(worldFile.getWorldFileType() == WorldFileType.JSON){ |
| 255 | WorldFileJSON wfj = null; |
| 256 | if(worldFile instanceof WorldFileJSON){ |
| 257 | wfj = (WorldFileJSON) worldFile; |
| 258 | } else if(worldFile instanceof WorldFileDefault){ |
| 259 | wfj = (WorldFileJSON) ((WorldFileDefault) worldFile).getWorldFile(); |
| 260 | } |
| 261 | if(wfj != null) wfj.setMetaGetter(this); |
| 262 | } |
| 263 | |
| 264 | // write world file |
| 265 | try { |
| 266 | World world = getWorld(); |
| 267 | worldFile.writeFile(world); |
| 268 | // set world as recently used |
| 269 | WorldFileList.push(new WorldFileList.WorldFileEntry(world.getName(), new File(worldFile.getFilename()))); |
| 270 | |
| 271 | showMessage("World saved"); |
| 272 | } catch (IOException ex) { |
| 273 | Logger.getLogger(WorldTab.class.getName()).log(Level.SEVERE, null, ex); |
| 274 | JOptionPane.showMessageDialog(getParent(), |
| 275 | "Could not save world file " + worldFile.getFilename(), |
| 276 | "Saving world file", |
| 277 | JOptionPane.ERROR_MESSAGE); |
| 278 | } |
| 279 | } |
| 280 | } |
| 281 | } |
| 282 | |
| 283 | /** |
| 284 | * Show message in infobar |