2011-01-04 01:43:23 +01:00
|
|
|
package net.minecraft.server;
|
|
|
|
|
|
|
|
import java.io.*;
|
|
|
|
import java.util.Properties;
|
|
|
|
import java.util.logging.Level;
|
|
|
|
import java.util.logging.Logger;
|
|
|
|
|
2011-01-11 09:25:13 +01:00
|
|
|
import joptsimple.OptionSet; // CraftBukkit
|
2011-01-04 01:43:23 +01:00
|
|
|
|
|
|
|
public class PropertyManager {
|
|
|
|
|
|
|
|
public static Logger a = Logger.getLogger("Minecraft");
|
|
|
|
private Properties b;
|
|
|
|
private File c;
|
|
|
|
|
|
|
|
public PropertyManager(File file) {
|
|
|
|
b = new Properties();
|
|
|
|
c = file;
|
|
|
|
if (file.exists()) {
|
|
|
|
try {
|
2011-01-11 09:25:13 +01:00
|
|
|
b.load(((java.io.InputStream) (new FileInputStream(file))));
|
2011-01-04 01:43:23 +01:00
|
|
|
} catch (Exception exception) {
|
2011-01-11 09:25:13 +01:00
|
|
|
a.log(Level.WARNING, (new StringBuilder()).append("Failed to load ").append(((file))).toString(), ((Throwable) (exception)));
|
2011-01-04 01:43:23 +01:00
|
|
|
a();
|
|
|
|
}
|
|
|
|
} else {
|
2011-01-11 09:25:13 +01:00
|
|
|
a.log(Level.WARNING, (new StringBuilder()).append(((file))).append(" does not exist").toString());
|
2011-01-04 01:43:23 +01:00
|
|
|
a();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Craftbukkit start
|
2011-01-11 09:25:13 +01:00
|
|
|
private OptionSet options = null;
|
|
|
|
|
2011-01-04 01:43:23 +01:00
|
|
|
public PropertyManager(final OptionSet options) {
|
|
|
|
this((File)options.valueOf("config"));
|
|
|
|
|
|
|
|
this.options = options;
|
|
|
|
}
|
|
|
|
|
|
|
|
private <T> T getOverride(String name, T value) {
|
|
|
|
if ((options != null) && (options.has(name))) {
|
|
|
|
return (T)options.valueOf(name);
|
|
|
|
}
|
|
|
|
|
|
|
|
return value;
|
|
|
|
}
|
|
|
|
// Craftbukkit end
|
|
|
|
|
|
|
|
public void a() {
|
|
|
|
a.log(Level.INFO, "Generating new properties file");
|
|
|
|
b();
|
|
|
|
}
|
|
|
|
|
|
|
|
public void b() {
|
|
|
|
try {
|
2011-01-11 09:25:13 +01:00
|
|
|
b.store(((java.io.OutputStream) (new FileOutputStream(c))), "Minecraft server properties");
|
2011-01-04 01:43:23 +01:00
|
|
|
} catch (Exception exception) {
|
2011-01-11 09:25:13 +01:00
|
|
|
a.log(Level.WARNING, (new StringBuilder()).append("Failed to save ").append(((c))).toString(), ((Throwable) (exception)));
|
2011-01-04 01:43:23 +01:00
|
|
|
a();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public String a(String s, String s1) {
|
2011-01-11 09:25:13 +01:00
|
|
|
if (!b.containsKey(((s)))) {
|
2011-01-04 01:43:23 +01:00
|
|
|
b.setProperty(s, getOverride(s, s1)); // Craftbukkit
|
|
|
|
b();
|
|
|
|
}
|
|
|
|
return getOverride(s, b.getProperty(s, s1)); // Craftbukkit
|
|
|
|
}
|
|
|
|
|
|
|
|
public int a(String s, int i) {
|
|
|
|
try {
|
|
|
|
return getOverride(s, Integer.parseInt(a(s, String.valueOf(i)))); // Craftbukkit
|
|
|
|
} catch (Exception exception) {
|
|
|
|
b.setProperty(s, getOverride(s, i).toString()); // Craftbukkit
|
|
|
|
}
|
|
|
|
return getOverride(s, i); // Craftbukkit
|
|
|
|
}
|
|
|
|
|
|
|
|
public boolean a(String s, boolean flag) {
|
|
|
|
try {
|
|
|
|
return getOverride(s, Boolean.parseBoolean(a(s, String.valueOf(flag)))); // Craftbukkit
|
|
|
|
} catch (Exception exception) {
|
|
|
|
b.setProperty(s, getOverride(s, flag).toString()); // Craftbukkit
|
|
|
|
}
|
|
|
|
return getOverride(s, flag); // Craftbukkit
|
|
|
|
}
|
|
|
|
}
|