-
-
Notifications
You must be signed in to change notification settings - Fork 44
/
PatchConfiguration.java
62 lines (51 loc) · 1.64 KB
/
PatchConfiguration.java
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
package nallar.patched.forge;
import cpw.mods.fml.common.FMLLog;
import nallar.patched.annotation.Public;
import net.minecraft.server.MinecraftServer;
import net.minecraftforge.common.Configuration;
import java.io.*;
import java.util.*;
import java.util.logging.*;
@Public
public abstract class PatchConfiguration extends Configuration {
private boolean saveQueued;
@Override
public void save() {
if (PARENT != null && PARENT != this) {
PARENT.save();
return;
}
Set<Configuration> toSaveConfigurationSet = MinecraftServer.toSaveConfigurationSet;
if (toSaveConfigurationSet != null) {
if (!saveQueued) {
toSaveConfigurationSet.add(this);
}
saveQueued = true;
return;
}
try {
File file = this.file;
if (!file.exists() && !file.createNewFile() && ((file.getParentFile() == null || !file.getParentFile().mkdirs() || !file.createNewFile()))) {
return;
}
if (file.canWrite()) {
FileOutputStream fos = new FileOutputStream(file);
BufferedWriter buffer = new BufferedWriter(new OutputStreamWriter(fos, defaultEncoding));
buffer.write("# Configuration file" + NEW_LINE);
if (children.isEmpty()) {
save(buffer);
} else {
for (Map.Entry<String, Configuration> entry : children.entrySet()) {
buffer.write("START: \"" + entry.getKey() + '"' + NEW_LINE);
entry.getValue().save(buffer);
buffer.write("END: \"" + entry.getKey() + '"' + NEW_LINE + NEW_LINE);
}
}
buffer.close();
fos.close();
}
} catch (IOException e) {
FMLLog.log(Level.WARNING, e, "Error saving configuration file " + file);
}
}
}