Пример #1
0
 private static JsonObject deepCopyObj(JsonObject from) {
   JsonObject result = new JsonObject();
   for (Map.Entry<String, JsonElement> entry : from.entrySet()) {
     result.add(entry.getKey(), deepCopy(entry.getValue()));
   }
   return result;
 }
Пример #2
0
 public static LauncherProfiles load() throws IOException {
   System.out.println("Loading Minecraft profiles from " + DevLauncher.workingDirectory);
   try (FileReader reader = new FileReader(getFile())) {
     LauncherProfiles profiles = new LauncherProfiles();
     JsonObject e = new JsonParser().parse(reader).getAsJsonObject();
     for (Map.Entry<String, JsonElement> entry : e.entrySet()) {
       if (entry.getKey().equals("clientToken")) {
         profiles.clientToken = entry.getValue().getAsString();
       } else if (entry.getKey().equals("authenticationDatabase")) {
         JsonObject o = entry.getValue().getAsJsonObject();
         for (Map.Entry<String, JsonElement> entry1 : o.entrySet()) {
           profiles.authenticationDatabase.profiles.put(
               UUIDTypeAdapter.fromString(entry1.getKey()),
               GSON.fromJson(entry1.getValue(), OnlineProfile.class));
         }
       } else {
         profiles.everythingElse.add(entry.getKey(), entry.getValue());
       }
     }
     INSTANCE = profiles;
     return INSTANCE;
   } finally {
     if (INSTANCE == null) {
       INSTANCE = new LauncherProfiles();
     }
     INSTANCE.markLoaded();
   }
 }
Пример #3
0
 static void modified() {
   try (FileWriter writer = new FileWriter(getFile())) {
     JsonObject obj = deepCopy(INSTANCE.everythingElse);
     obj.addProperty("clientToken", INSTANCE.clientToken);
     obj.add("authenticationDatabase", GSON.toJsonTree(INSTANCE.authenticationDatabase.profiles));
     GSON.toJson(obj, writer);
     System.out.println("Profiles saved");
   } catch (IOException e) {
     e.printStackTrace();
   }
 }