Advertisement
iSach

Untitled

Feb 6th, 2016
211
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.86 KB | None | 0 0
  1. private static Map loadMap(String name) {
  2.  
  3. File mapFile = new File(TurfWars.instance.getDataFolder(), "maps/" + name + ".json");
  4.  
  5. JsonObject jsonMap = new JsonObject();
  6.  
  7. try {
  8. JsonParser parser = new JsonParser();
  9. JsonElement jsonElement = parser.parse(new FileReader(mapFile));
  10. jsonMap = jsonElement.getAsJsonObject();
  11. } catch (FileNotFoundException e) {
  12. } catch (IOException ioe) {
  13. }
  14.  
  15. Location r1 = ConfigUtils.getLocationFromJson(jsonMap, "R1");
  16. Location r2 = ConfigUtils.getLocationFromJson(jsonMap, "R2");
  17. Location b1 = ConfigUtils.getLocationFromJson(jsonMap, "B1");
  18. Location b2 = ConfigUtils.getLocationFromJson(jsonMap, "B2");
  19. Location specSpawn = ConfigUtils.getLocationFromJson(jsonMap, "spectators");
  20.  
  21. JsonObject blueSpawns = jsonMap.getAsJsonObject("blueSpawns");
  22. JsonObject redSpawns = jsonMap.getAsJsonObject("redSpawns");
  23.  
  24. ArrayList<Location> redList = new ArrayList<>();
  25. ArrayList<Location> blueList = new ArrayList<>();
  26.  
  27. if (blueSpawns != null)
  28. for (java.util.Map.Entry<String, JsonElement> entry : blueSpawns.entrySet())
  29. blueList.add(ConfigUtils.getLocationFromJson(blueSpawns, entry.getKey()));
  30. if (redSpawns != null)
  31. for (java.util.Map.Entry<String, JsonElement> entry : redSpawns.entrySet())
  32. redList.add(ConfigUtils.getLocationFromJson(redSpawns, entry.getKey()));
  33.  
  34. Map map = new Map(name, blueList, redList, specSpawn, r1, r2, b1, b2);
  35.  
  36. if (map.isComplete())
  37. TurfLogger.log(" Registered map: " + name + " (Complete!)");
  38. else
  39. TurfLogger.log(" Registered map but disabled: " + name + " (incomplete!)");
  40.  
  41. maps.put(map, jsonMap);
  42.  
  43. return map;
  44. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement