blob: d3a1707303d9369bebf4b7b8b442a589a975eb48 (
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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
|
package de.hype.bbsentials.client;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import net.fabricmc.loader.api.FabricLoader;
import java.io.File;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.lang.reflect.Field;
public class ToDisplayConfig {
public boolean disableAll = false;
public boolean allChChestItem = true;
public boolean allRoboPart = false;
public boolean customChChestItem = false;
public boolean prehistoricEgg = false;
public boolean pickonimbus2000 = false;
public boolean controlSwitch = false;
public boolean electronTransmitter = false;
public boolean ftx3070 = false;
public boolean robotronReflector = false;
public boolean superliteMotor = false;
public boolean syntheticHeart = false;
public boolean flawlessGemstone = false;
//Mining Events.
public boolean allEvents = true;
public boolean blockChEvents = false;
public String betterTogether = "none";
public String doublePowder = "none";
public String goneWithTheWind = "none";
public boolean goblinRaid = false;
public boolean mithrilGourmand = false;
public boolean raffle = false;
// Serialize the object to JSON and save to file
public void saveToFile() {
File configFile = new File(FabricLoader.getInstance().getConfigDirectory(), "BBsentials_display_Config.json");
Gson gson = new GsonBuilder().setPrettyPrinting().create();
try (FileWriter writer = new FileWriter(configFile)) {
gson.toJson(this, writer);
} catch (IOException e) {
e.printStackTrace();
}
}
// Deserialize the object from JSON file
public static ToDisplayConfig loadFromFile() {
File configFile = new File(FabricLoader.getInstance().getConfigDirectory(), "BBsentials_display_Config.json");
Gson gson = new Gson();
try (FileReader reader = new FileReader(configFile)) {
return gson.fromJson(reader, ToDisplayConfig.class);
} catch (IOException e) {
e.printStackTrace();
}
// If file doesn't exist or there's an error, return a new instance
return new ToDisplayConfig();
}
public void setValueAndSave(String propertyName, Object newValue) {
String lowerCasePropertyName = propertyName.toLowerCase();
try {
Field field = getClass().getDeclaredField(lowerCasePropertyName);
field.setAccessible(true);
field.set(this, newValue);
saveToFile();
} catch (NoSuchFieldException | IllegalAccessException e) {
e.printStackTrace();
}
}
// Method to get a value based on property name
public boolean getValue(String propertyName) {
if (disableAll) return false;
String lowerCasePropertyName = propertyName.toLowerCase();
try {
Field field = getClass().getDeclaredField(lowerCasePropertyName);
field.setAccessible(true);
return field.getBoolean(this);
} catch (NoSuchFieldException | IllegalAccessException e) {
e.printStackTrace();
}
return false;
}
}
|