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

Method getWorld

src/main/java/mudmap2/backend/WorldManager.java:64–92  ·  view source on GitHub ↗

Load world or get it from loaded worlds list if it is already loaded @param filename world file name @return world or null @throws java.lang.Exception throws Exception if world could not be read

(String filename)

Source from the content-addressed store, hash-verified

62 * @throws java.lang.Exception throws Exception if world could not be read
63 */
64 public static World getWorld(String filename) throws Exception{
65 World ret = null;
66
67 // find world in loaded worlds list
68 for(World world: loadedWorlds){
69 if(world.getWorldFile() != null &&
70 world.getWorldFile().getFilename().equals(filename)){
71 ret = world;
72 break;
73 }
74 }
75
76 // if world not loaded already
77 if(ret == null){
78 /* TODO: find correct file format if a new format gets implemented
79 * in future
80 */
81 WorldFile worldFile = new WorldFileDefault(filename);
82 if(worldFile.canRead()){
83 ret = worldFile.readFile();
84 worldFile.backup();
85 register(ret);
86 } else {
87 throw new Exception("Could not read world file: invalid format");
88 }
89 }
90
91 return ret;
92 }
93
94 /**
95 * Creates and registers a new world

Callers 3

testGetWorldMethod · 0.95
actionPerformedMethod · 0.95
createMethod · 0.95

Calls 6

canReadMethod · 0.95
readFileMethod · 0.95
backupMethod · 0.95
registerMethod · 0.95
getFilenameMethod · 0.80
getWorldFileMethod · 0.45

Tested by 1

testGetWorldMethod · 0.76