Fork of Poseidon providing Bukkit #1060 to older Beta versions (b1.0-b1.7.3)
1package net.minecraft.server;
2
3import java.io.File;
4import java.io.FileInputStream;
5import java.io.FileOutputStream;
6import java.util.Properties;
7import java.util.logging.Level;
8import java.util.logging.Logger;
9
10public class PropertyManager {
11
12 public static Logger a = Logger.getLogger("Minecraft");
13 public Properties properties = new Properties(); // CraftBukkit - priv to pub
14 private File c;
15
16 public PropertyManager(File file1) {
17 this.c = file1;
18 if (file1.exists()) {
19 try {
20 this.properties.load(new FileInputStream(file1));
21 } catch (Exception exception) {
22 a.log(Level.WARNING, "Failed to load " + file1, exception);
23 this.a();
24 }
25 } else {
26 a.log(Level.WARNING, file1 + " does not exist");
27 this.a();
28 }
29 }
30
31 // CraftBukkit start
32 private joptsimple.OptionSet options = null;
33
34 public PropertyManager(final joptsimple.OptionSet options) {
35 this((File) options.valueOf("config"));
36
37 this.options = options;
38 }
39
40 private <T> T getOverride(String name, T value) {
41 if ((this.options != null) && (this.options.has(name))) {
42 return (T) this.options.valueOf(name);
43 }
44
45 return value;
46 }
47 // CraftBukkit end
48
49 public void a() {
50 a.log(Level.INFO, "Generating new properties file");
51 this.savePropertiesFile();
52 }
53
54 public void savePropertiesFile() {
55 try {
56 this.properties.store(new FileOutputStream(this.c), "Minecraft server properties");
57 } catch (Exception exception) {
58 a.log(Level.WARNING, "Failed to save " + this.c, exception);
59 this.a();
60 }
61 }
62
63 public String getString(String s, String s1) {
64 if (!this.properties.containsKey(s)) {
65 s1 = this.getOverride(s, s1); // CraftBukkit
66 this.properties.setProperty(s, s1);
67 this.savePropertiesFile();
68 }
69
70 return this.getOverride(s, this.properties.getProperty(s, s1)); // CraftBukkit
71 }
72
73 public int getInt(String s, int i) {
74 try {
75 return this.getOverride(s, Integer.parseInt(this.getString(s, "" + i))); // CraftBukkit
76 } catch (Exception exception) {
77 i = this.getOverride(s, i); // CraftBukkit
78 this.properties.setProperty(s, "" + i);
79 return i;
80 }
81 }
82
83 public boolean getBoolean(String s, boolean flag) {
84 try {
85 return this.getOverride(s, Boolean.parseBoolean(this.getString(s, "" + flag))); // CraftBukkit
86 } catch (Exception exception) {
87 flag = this.getOverride(s, flag); // CraftBukkit
88 this.properties.setProperty(s, "" + flag);
89 return flag;
90 }
91 }
92
93 public void b(String s, boolean flag) {
94 flag = this.getOverride(s, flag); // CraftBukkit
95 this.properties.setProperty(s, "" + flag);
96 this.savePropertiesFile();
97 }
98}