public static YAMLProcessor getSpoutcraftYML() { updateSpoutcraftYMLCache(); YAMLProcessor config = new YAMLProcessor(spoutcraftYML, false); try { config.load(); } catch (IOException e) { e.printStackTrace(); } return config; }
public static void updateSpoutcraftYMLCache() { if (!updated) { synchronized (key) { String urlName = MirrorUtils.getMirrorUrl("spoutcraft.yml", "http://get.spout.org/spoutcraft.yml", null); if (urlName != null) { try { int selected = -1; if (spoutcraftYML.exists()) { try { YAMLProcessor config = new YAMLProcessor(spoutcraftYML, false); config.load(); selected = config.getInt("current", -1); } catch (Exception ex) { ex.printStackTrace(); } } URL url = new URL(urlName); HttpURLConnection con = (HttpURLConnection) (url.openConnection()); System.setProperty("http.agent", ""); con.setRequestProperty( "User-Agent", "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/534.30 (KHTML, like Gecko) Chrome/12.0.742.100 Safari/534.30"); Utils.copy(con.getInputStream(), new FileOutputStream(spoutcraftYML)); YAMLProcessor config = new YAMLProcessor(spoutcraftYML, false); config.load(); config.setProperty("current", selected); config.setProperty("launcher", Main.getBuild("launcher-version")); config.save(); } catch (IOException e) { e.printStackTrace(); } } updated = true; } } }