blob: 53b8b3a915ea1cd184a75770497b540816399c42 (
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
|
package luckyblock.configurations;
import com.google.gson.Gson;
import com.google.gson.JsonObject;
import com.google.gson.JsonParser;
import luckyblock.Main;
import luckyblock.action.LuckyActionHolder;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.nio.charset.StandardCharsets;
import java.util.HashMap;
import java.util.Map;
public class Settings {
public String section = "LuckyBlock";
public Map<String, LuckyActionHolder> events = new HashMap<>();
public Settings() {
try (InputStream input = Main.class.getResourceAsStream("/settings.json")) {
if (input != null) {
Gson gson = new Gson();
JsonObject root = JsonParser.parseReader(new InputStreamReader(input, StandardCharsets.UTF_8)).getAsJsonObject();
Main.getLOGGER().info(root.toString());
if (root.has(this.section)) {
JsonObject sectionJson = root.getAsJsonObject(this.section);
for (Map.Entry<String, com.google.gson.JsonElement> entry : sectionJson.entrySet()) {
String k = entry.getKey().replace("-", "_");
LuckyActionHolder holder = gson.fromJson(entry.getValue(), LuckyActionHolder.class);
this.events.put(k, holder);
}
}
}
} catch (Exception e) {
throw new RuntimeException(e);
}
}
}
|