Hi, I’m trying to adapt this Bukkit code for Sponge and I can’t get it to work.
private void validateConfig() {
InputStream is = getResource("config.yml");
FileConfiguration configuration = YamlConfiguration.loadConfiguration(new InputStreamReader(is));
Date date = new Date();
SimpleDateFormat format = new SimpleDateFormat("dd-MM-yyyy_HH-mm-ss");
Set<String> pluginKeys = configuration.getKeys(true);
Set<String> configKeys = getConfig().getKeys(true);
for (String s : pluginKeys) {
if (!configKeys.contains(s)) {
System.out.println("You are using an invalid config. Creating a new one...");
File backupFolder = new File("plugins/Core/backup");
if (!backupFolder.exists()) {
backupFolder.mkdir();
}
Path source = (Path) Paths.get("plugins/Core/config.yml");
Path dest = (Path) Paths.get("plugins/Core/backup/config_" + format.format(date) + ".yml");
File source2 = new File("plugins/Core/config.yml");
try {
Files.copy(source, dest);
Bukkit.getConsoleSender().sendMessage("Generating a backup: \\plugins\\Core\\backup\\config_" + format.format(date) + ".yml");
} catch (IOException e) {
e.printStackTrace();
}
Bukkit.getConsoleSender().sendMessage("Deleting file: \\plugins\\Core\\config.yml");
source2.delete();
registerConfig();
return;
}
}
}
It’s a method that checks the YAML configuration for errors and missing things. But I don’t know how to adapt it to HOCON.
Thanks in advance