2022-07-22 08:29:39 +00:00
|
|
|
package com.imaginarycode.minecraft.redisbungee.api.config;
|
|
|
|
|
2022-07-22 11:12:32 +00:00
|
|
|
|
2022-07-22 08:29:39 +00:00
|
|
|
import java.io.IOException;
|
2022-07-22 11:12:32 +00:00
|
|
|
import java.io.InputStream;
|
|
|
|
import java.nio.file.Files;
|
2022-07-22 08:29:39 +00:00
|
|
|
import java.nio.file.Path;
|
2022-07-22 11:12:32 +00:00
|
|
|
import java.nio.file.StandardCopyOption;
|
|
|
|
import java.util.UUID;
|
2022-07-22 08:29:39 +00:00
|
|
|
|
|
|
|
public interface ConfigLoader {
|
|
|
|
void loadConfig() throws IOException;
|
|
|
|
|
2022-07-22 11:12:32 +00:00
|
|
|
default Path createConfigFile(Path dataFolder) throws IOException {
|
|
|
|
if (Files.notExists(dataFolder)) {
|
|
|
|
Files.createDirectory(dataFolder);
|
|
|
|
}
|
|
|
|
Path file = dataFolder.resolve("config.yml");
|
|
|
|
if (Files.notExists(file)) {
|
|
|
|
try (InputStream in = getClass().getClassLoader().getResourceAsStream("config.yml")) {
|
|
|
|
Files.createFile(file);
|
|
|
|
assert in != null;
|
|
|
|
Files.copy(in, file, StandardCopyOption.REPLACE_EXISTING);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return file;
|
|
|
|
}
|
|
|
|
|
|
|
|
default void handleOldConfig(Path dataFolder) throws IOException {
|
|
|
|
Path oldConfigFolder = dataFolder.resolve("old_config");
|
|
|
|
if (Files.notExists(oldConfigFolder)) {
|
|
|
|
Files.createDirectory(oldConfigFolder);
|
|
|
|
}
|
|
|
|
Path oldConfigPath = dataFolder.resolve("config.yml");
|
|
|
|
Files.move(oldConfigPath, oldConfigFolder.resolve(UUID.randomUUID() + "_config.yml"));
|
|
|
|
createConfigFile(dataFolder);
|
|
|
|
|
|
|
|
}
|
2022-07-22 08:29:39 +00:00
|
|
|
|
|
|
|
|
|
|
|
}
|