2011-01-04 01:43:23 +01:00
|
|
|
package net.minecraft.server;
|
|
|
|
|
2011-01-29 22:50:29 +01:00
|
|
|
import java.io.File;
|
|
|
|
import java.io.FileInputStream;
|
|
|
|
import java.io.FileOutputStream;
|
2011-01-04 01:43:23 +01:00
|
|
|
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");
|
2011-01-29 22:50:29 +01:00
|
|
|
private Properties b = new Properties();
|
2011-01-04 01:43:23 +01:00
|
|
|
private File c;
|
|
|
|
|
2011-01-29 22:50:29 +01:00
|
|
|
public PropertyManager(File file1) {
|
|
|
|
this.c = file1;
|
|
|
|
if (file1.exists()) {
|
2011-01-04 01:43:23 +01:00
|
|
|
try {
|
2011-01-29 22:50:29 +01:00
|
|
|
this.b.load(new FileInputStream(file1));
|
2011-01-04 01:43:23 +01:00
|
|
|
} catch (Exception exception) {
|
2011-01-29 22:50:29 +01:00
|
|
|
a.log(Level.WARNING, "Failed to load " + file1, exception);
|
|
|
|
this.a();
|
2011-01-04 01:43:23 +01:00
|
|
|
}
|
|
|
|
} else {
|
2011-01-29 22:50:29 +01:00
|
|
|
a.log(Level.WARNING, file1 + " does not exist");
|
|
|
|
this.a();
|
2011-01-04 01:43:23 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-01-29 22:50:29 +01:00
|
|
|
// 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;
|
|
|
|
}
|
2011-01-29 22:50:29 +01:00
|
|
|
// CraftBukkit end
|
2011-01-04 01:43:23 +01:00
|
|
|
|
|
|
|
public void a() {
|
|
|
|
a.log(Level.INFO, "Generating new properties file");
|
2011-01-29 22:50:29 +01:00
|
|
|
this.b();
|
2011-01-04 01:43:23 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
public void b() {
|
|
|
|
try {
|
2011-01-29 22:50:29 +01:00
|
|
|
this.b.store(new FileOutputStream(this.c), "Minecraft server properties");
|
2011-01-04 01:43:23 +01:00
|
|
|
} catch (Exception exception) {
|
2011-01-29 22:50:29 +01:00
|
|
|
a.log(Level.WARNING, "Failed to save " + this.c, exception);
|
|
|
|
this.a();
|
2011-01-04 01:43:23 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public String a(String s, String s1) {
|
2011-01-29 22:50:29 +01:00
|
|
|
if (!this.b.containsKey(s)) {
|
|
|
|
this.b.setProperty(s, getOverride(s, s1)); // CraftBukkit
|
|
|
|
this.b();
|
2011-01-04 01:43:23 +01:00
|
|
|
}
|
2011-01-29 22:50:29 +01:00
|
|
|
|
|
|
|
return getOverride(s, this.b.getProperty(s, s1)); // CraftBukkit
|
2011-01-04 01:43:23 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
public int a(String s, int i) {
|
|
|
|
try {
|
2011-01-29 22:50:29 +01:00
|
|
|
return getOverride(s, Integer.parseInt(this.a(s, "" + i))); // CraftBukkit
|
2011-01-04 01:43:23 +01:00
|
|
|
} catch (Exception exception) {
|
2011-01-29 22:50:29 +01:00
|
|
|
i = getOverride(s, i); // CraftBukkit
|
|
|
|
this.b.setProperty(s, "" + i);
|
|
|
|
return i;
|
2011-01-04 01:43:23 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public boolean a(String s, boolean flag) {
|
|
|
|
try {
|
2011-01-29 22:50:29 +01:00
|
|
|
return getOverride(s, Boolean.parseBoolean(this.a(s, "" + flag))); // CraftBukkit
|
2011-01-04 01:43:23 +01:00
|
|
|
} catch (Exception exception) {
|
2011-01-29 22:50:29 +01:00
|
|
|
flag = getOverride(s, flag); // CraftBukkit
|
|
|
|
this.b.setProperty(s, "" + flag);
|
|
|
|
return flag;
|
2011-01-04 01:43:23 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|