2
0
mirror of https://github.com/proxiodev/RedisBungee.git synced 2026-04-08 16:10:26 +00:00

config changes

This commit is contained in:
2022-07-22 15:12:32 +04:00
parent 0408e2923b
commit 5c6cf405fa
5 changed files with 205 additions and 169 deletions

View File

@@ -1,14 +1,41 @@
package com.imaginarycode.minecraft.redisbungee.api.config;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.StandardCopyOption;
import java.util.UUID;
public interface ConfigLoader {
void loadConfig() throws IOException;
Path createConfigFile() throws IOException;
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);
}
void handleOldConfig(Path path) throws IOException;
}