Skip to content

Instantly share code, notes, and snippets.

@MiniDigger
Last active August 15, 2018 19:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save MiniDigger/0a6e5783f2511cc3d07dec45ace48f2c to your computer and use it in GitHub Desktop.
Save MiniDigger/0a6e5783f2511cc3d07dec45ace48f2c to your computer and use it in GitHub Desktop.
UpdateBungeeLanguageProperties
import com.google.gson.Gson;
import java.io.PrintWriter;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.LinkedHashMap;
import java.util.Map;
import java.util.Properties;
class UpdateBungeeLanguageProperties {
public static void main(String[] args) throws Exception {
Path oldPropertiesFile = Paths.get("C:\\Users\\Martin\\Desktop\\en_us.properties.old");
Path newJsonFile = Paths.get("C:\\Users\\Martin\\Desktop\\en_us.json");
Path outputPropertiesFile = Paths.get("C:\\Users\\Martin\\Desktop\\en_us.properties");
Gson gson = new Gson();
Map json = gson.fromJson(Files.newBufferedReader(newJsonFile), Map.class);
LinkedHashMap<Object, Object> newProperties = new LinkedHashMap<>(json);
Properties oldProperties = new Properties();
oldProperties.load(Files.newInputStream(oldPropertiesFile));
newProperties.put("LEGACY_SEPARATOR","------------------- SEPARATING LEGACY STUFF -------------------");
oldProperties.entrySet().stream()
.filter(e -> !newProperties.containsKey(e.getKey()))
.forEach(e -> newProperties.put(e.getKey(), e.getValue()));
PrintWriter writer = new PrintWriter(Files.newBufferedWriter(outputPropertiesFile));
writer.println("# (c) 2018 Mojang AB");
writer.println("# Generated on " + LocalDateTime.now().format(DateTimeFormatter.ISO_DATE_TIME));
writer.println("# Using this gist: https://gist.github.com/MiniDigger/0a6e5783f2511cc3d07dec45ace48f2c");
newProperties.forEach((k, v)->writer.println(k + "=" + v));
writer.close();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment