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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
|
package gregtech.api.util;
import static gregtech.api.enums.GTValues.E;
import net.minecraft.item.ItemStack;
import net.minecraftforge.common.config.Configuration;
import net.minecraftforge.common.config.Property;
import gregtech.api.GregTechAPI;
import gregtech.api.enums.GTValues;
public class GTConfig implements Runnable {
public static boolean troll = false;
public static Configuration sConfigFileIDs;
public static Configuration cleanroomFile;
public static Configuration undergroundFluidsFile;
public final Configuration mConfig;
public GTConfig(Configuration aConfig) {
mConfig = aConfig;
mConfig.load();
mConfig.save();
GregTechAPI.sAfterGTPreload.add(this); // in case of crash on startup
GregTechAPI.sAfterGTLoad.add(this); // in case of crash on startup
GregTechAPI.sAfterGTPostload.add(this);
if (GTValues.lateConfigSave) GregTechAPI.sFirstWorldTick.add(this);
}
private static boolean shouldSave() {
return GTValues.lateConfigSave ? GTValues.worldTickHappened : GregTechAPI.sPostloadFinished;
}
public static int addIDConfig(Object aCategory, String aName, int aDefault) {
if (GTUtility.isStringInvalid(aName)) return aDefault;
Property tProperty = sConfigFileIDs.get(
aCategory.toString()
.replaceAll("\\|", "."),
aName.replaceAll("\\|", "."),
aDefault);
int rResult = tProperty.getInt(aDefault);
sConfigFileIDs.save();
return rResult;
}
public static String getStackConfigName(ItemStack aStack) {
if (GTUtility.isStackInvalid(aStack)) return E;
Object rName = GTOreDictUnificator.getAssociation(aStack);
if (rName != null) return rName.toString();
try {
if (GTUtility.isStringValid(rName = aStack.getUnlocalizedName())) return rName.toString();
} catch (Throwable e) {
/* Do nothing */
}
String sName = aStack.getItem()
.toString();
String[] tmp = sName.split("@");
if (tmp.length > 0) sName = tmp[0];
return sName + "." + aStack.getItemDamage();
}
public boolean get(Object aCategory, ItemStack aStack, boolean aDefault) {
String aName = getStackConfigName(aStack);
return get(aCategory, aName, aDefault);
}
public boolean get(Object aCategory, String aName, boolean aDefault) {
if (GTUtility.isStringInvalid(aName)) return aDefault;
Property tProperty = mConfig.get(
aCategory.toString()
.replaceAll("\\|", "_"),
(aName + "_" + aDefault).replaceAll("\\|", "_"),
aDefault);
boolean rResult = tProperty.getBoolean(aDefault);
if (!tProperty.wasRead() && shouldSave()) mConfig.save();
return rResult;
}
public int get(Object aCategory, ItemStack aStack, int aDefault) {
return get(aCategory, getStackConfigName(aStack), aDefault);
}
public int get(Object aCategory, String aName, int aDefault) {
if (GTUtility.isStringInvalid(aName)) return aDefault;
Property tProperty = mConfig.get(
aCategory.toString()
.replaceAll("\\|", "_"),
(aName + "_" + aDefault).replaceAll("\\|", "_"),
aDefault);
int rResult = tProperty.getInt(aDefault);
if (!tProperty.wasRead() && shouldSave()) mConfig.save();
return rResult;
}
public double get(Object aCategory, ItemStack aStack, double aDefault) {
return get(aCategory, getStackConfigName(aStack), aDefault);
}
public double get(Object aCategory, String aName, double aDefault) {
if (GTUtility.isStringInvalid(aName)) return aDefault;
Property tProperty = mConfig.get(
aCategory.toString()
.replaceAll("\\|", "_"),
(aName + "_" + aDefault).replaceAll("\\|", "_"),
aDefault);
double rResult = tProperty.getDouble(aDefault);
if (!tProperty.wasRead() && shouldSave()) mConfig.save();
return rResult;
}
public String get(Object aCategory, ItemStack aStack, String aDefault) {
return get(aCategory, getStackConfigName(aStack), aDefault);
}
public String get(Object aCategory, String aName, String aDefault) {
if (GTUtility.isStringInvalid(aName)) return aDefault;
Property tProperty = mConfig.get(
aCategory.toString()
.replaceAll("\\|", "_"),
(aName + "_" + aDefault).replaceAll("\\|", "_"),
aDefault);
String rResult = tProperty.getString();
if (!tProperty.wasRead() && shouldSave()) mConfig.save();
return rResult;
}
public String[] get(Object aCategory, ItemStack aStack, String... aDefault) {
return get(aCategory, getStackConfigName(aStack), aDefault);
}
public String[] get(Object aCategory, String aName, String... aDefault) {
if (GTUtility.isStringInvalid(aName)) return aDefault;
Property tProperty = mConfig.get(
aCategory.toString()
.replaceAll("\\|", "_"),
aName.replaceAll("\\|", "_"),
aDefault);
String[] rResult = tProperty.getStringList();
if (!tProperty.wasRead() && GregTechAPI.sPostloadFinished) mConfig.save();
return rResult;
}
public String getWithValidValues(Object aCategory, String aName, String[] validValues, String aDefault) {
if (GTUtility.isStringInvalid(aName)) return aDefault;
Property tProperty = mConfig.get(
aCategory.toString()
.replaceAll("\\|", "_"),
aName.replaceAll("\\|", "_"),
aDefault,
null,
validValues);
String rResult = tProperty.getString();
if (!tProperty.wasRead() && GregTechAPI.sPostloadFinished) mConfig.save();
return rResult;
}
@Override
public void run() {
mConfig.save();
}
}
|