blob: f6e0c8233e8d4d20f9d8e8b03e9202144919777a (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
|
package dev.mayaqq.ygasi.registry;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import net.fabricmc.loader.api.FabricLoader;
import java.io.*;
import java.nio.file.Files;
import java.util.HashMap;
import java.util.Map;
import java.util.UUID;
public class ConfigRegistry {
public static Config CONFIG = new Config();
static File modConfFolder = new File(FabricLoader.getInstance().getConfigDir().toFile(),"ygasi");
private static File configFile = new File(modConfFolder,"config.json");
private static final Gson gson = new GsonBuilder().setPrettyPrinting().create();
public static void load() {
//we do bunch of checking here mainly if the file exists
if (!modConfFolder.exists()) {
modConfFolder.mkdir();
}
if (!configFile.exists()) {
try {
configFile.createNewFile();
saveConfig();
} catch (IOException e) {
throw new RuntimeException(e);
}
} else {
try {
CONFIG = gson.fromJson(new FileReader(configFile), Config.class);
} catch (FileNotFoundException e) {
throw new RuntimeException(e);
}
}
}
public static void saveConfig() throws IOException {
//Write some info into the file under here
var writer = new FileWriter(configFile);
writer.write(gson.toJson(CONFIG));
writer.close();
}
public static class Config {
//the thing to write in the config file
public int pointsRewarded = 1;
public int branchCost = 16;
public Config() {}
}
}
|