40 lines
855 B
Java
40 lines
855 B
Java
package fi.jonttu.woovelocity.util;
|
|
|
|
import java.io.File;
|
|
import java.io.IOException;
|
|
import java.io.InputStream;
|
|
import java.nio.file.Files;
|
|
|
|
import com.moandjiezana.toml.Toml;
|
|
|
|
import fi.jonttu.woovelocity.WooVelocity;
|
|
|
|
public final class Config {
|
|
|
|
public final static Toml loadConfig() {
|
|
final File file = new File("plugins/WooVelocity/config.toml");
|
|
if (! file.getParentFile().exists()) {
|
|
file.getParentFile().mkdirs();
|
|
}
|
|
|
|
if (! file.exists()) {
|
|
try {
|
|
final InputStream input = WooVelocity.getInstance().getClass().getResourceAsStream("/" + file.getName());
|
|
if (input != null) {
|
|
Files.copy(input, file.toPath());
|
|
} else {
|
|
file.createNewFile();
|
|
}
|
|
} catch (final IOException e) {
|
|
e.printStackTrace();
|
|
return null;
|
|
}
|
|
}
|
|
|
|
final Toml toml = new Toml();
|
|
toml.read(file);
|
|
return toml;
|
|
}
|
|
|
|
}
|