MCPcopy Create free account
hub / github.com/Neop/mudmap2 / save

Method save

src/main/java/mudmap2/frontend/WorldTab.java:239–281  ·  view source on GitHub ↗

Saves the changes in the world

()

Source from the content-addressed store, hash-verified

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

Callers 4

testSaveMethod · 0.95
actionPerformedMethod · 0.95
dispatchKeyEventMethod · 0.95
closeTabsMethod · 0.45

Calls 14

getWorldMethod · 0.95
getWorldFileMethod · 0.95
getWorldFileTypeMethod · 0.95
setMetaGetterMethod · 0.95
writeFileMethod · 0.95
pushMethod · 0.95
getNameMethod · 0.95
getFilenameMethod · 0.95
showMessageMethod · 0.95
isPassiveMethod · 0.80
getParentMethod · 0.65
getWorldFileMethod · 0.45

Tested by 1

testSaveMethod · 0.76