13
0
geforkt von Mirrors/Paper
Paper/src/main/java/net/minecraft/server/PropertyManager.java

101 Zeilen
2.8 KiB
Java

package net.minecraft.server;
2011-01-29 22:50:29 +01:00
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.util.Properties;
import java.util.logging.Level;
import java.util.logging.Logger;
import joptsimple.OptionSet; // CraftBukkit
public class PropertyManager {
public static Logger a = Logger.getLogger("Minecraft");
public Properties properties = new Properties(); // Craftbukkit - priv to pub
private File c;
2011-01-29 22:50:29 +01:00
public PropertyManager(File file1) {
this.c = file1;
if (file1.exists()) {
try {
this.properties.load(new FileInputStream(file1));
} catch (Exception exception) {
2011-01-29 22:50:29 +01:00
a.log(Level.WARNING, "Failed to load " + file1, exception);
this.a();
}
} else {
2011-01-29 22:50:29 +01:00
a.log(Level.WARNING, file1 + " does not exist");
this.a();
}
}
2011-01-29 22:50:29 +01:00
// CraftBukkit start
private OptionSet options = null;
public PropertyManager(final OptionSet options) {
2011-02-23 13:56:36 +01:00
this((File) options.valueOf("config"));
this.options = options;
}
private <T> T getOverride(String name, T value) {
if ((options != null) && (options.has(name))) {
2011-02-23 13:56:36 +01:00
return (T) options.valueOf(name);
}
return value;
}
2011-01-29 22:50:29 +01:00
// CraftBukkit end
public void a() {
a.log(Level.INFO, "Generating new properties file");
2011-01-29 22:50:29 +01:00
this.b();
}
public void b() {
try {
this.properties.store(new FileOutputStream(this.c), "Minecraft server properties");
} catch (Exception exception) {
2011-01-29 22:50:29 +01:00
a.log(Level.WARNING, "Failed to save " + this.c, exception);
this.a();
}
}
public String getString(String s, String s1) {
if (!this.properties.containsKey(s)) {
s1 = getOverride(s, s1); // CraftBukkit
this.properties.setProperty(s, s1);
2011-01-29 22:50:29 +01:00
this.b();
}
2011-01-29 22:50:29 +01:00
return getOverride(s, this.properties.getProperty(s, s1)); // CraftBukkit
}
public int getInt(String s, int i) {
try {
return getOverride(s, Integer.parseInt(this.getString(s, "" + i))); // CraftBukkit
} catch (Exception exception) {
2011-01-29 22:50:29 +01:00
i = getOverride(s, i); // CraftBukkit
this.properties.setProperty(s, "" + i);
2011-01-29 22:50:29 +01:00
return i;
}
}
public boolean getBoolean(String s, boolean flag) {
try {
return getOverride(s, Boolean.parseBoolean(this.getString(s, "" + flag))); // CraftBukkit
} catch (Exception exception) {
2011-01-29 22:50:29 +01:00
flag = getOverride(s, flag); // CraftBukkit
this.properties.setProperty(s, "" + flag);
2011-01-29 22:50:29 +01:00
return flag;
}
}
2011-02-23 03:37:56 +01:00
public void b(String s, boolean flag) {
flag = getOverride(s, flag); // CraftBukkit
this.properties.setProperty(s, "" + flag);
2011-02-23 03:37:56 +01:00
this.b();
}
}