-
Notifications
You must be signed in to change notification settings - Fork 44
Expand file tree
/
Copy pathImage2MapConfig.java
More file actions
59 lines (46 loc) · 1.77 KB
/
Image2MapConfig.java
File metadata and controls
59 lines (46 loc) · 1.77 KB
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
56
57
58
59
package space.essem.image2map.config;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import net.fabricmc.loader.api.FabricLoader;
import org.apache.commons.io.IOUtils;
import space.essem.image2map.Image2Map;
import java.io.*;
import java.nio.charset.StandardCharsets;
public class Image2MapConfig {
private static final Gson GSON = new GsonBuilder()
.disableHtmlEscaping().setLenient().setPrettyPrinting()
.create();
public boolean allowLocalFiles = false;
public boolean allowBundles = true;
public int minPermLevel = 2;
public static Image2MapConfig loadOrCreateConfig() {
try {
Image2MapConfig config;
File configFile = new File(FabricLoader.getInstance().getConfigDir().toFile(), "image2map.json");
if (configFile.exists()) {
String json = IOUtils.toString(new InputStreamReader(new FileInputStream(configFile), StandardCharsets.UTF_8));
config = GSON.fromJson(json, Image2MapConfig.class);
} else {
config = new Image2MapConfig();
}
saveConfig(config);
return config;
}
catch(IOException exception) {
Image2Map.LOGGER.error("Something went wrong while reading config!");
exception.printStackTrace();
return new Image2MapConfig();
}
}
public static void saveConfig(Image2MapConfig config) {
File configFile = new File(FabricLoader.getInstance().getConfigDir().toFile(), "image2map.json");
try {
BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(configFile), StandardCharsets.UTF_8));
writer.write(GSON.toJson(config));
writer.close();
} catch (Exception e) {
Image2Map.LOGGER.error("Something went wrong while saving config!");
e.printStackTrace();
}
}
}