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;
|
2012-07-29 09:33:13 +02:00
|
|
|
import java.io.IOException;
|
2011-01-04 01:43:23 +01:00
|
|
|
import java.util.Properties;
|
|
|
|
import java.util.logging.Level;
|
|
|
|
import java.util.logging.Logger;
|
|
|
|
|
2012-07-22 08:18:00 +02:00
|
|
|
import joptsimple.OptionSet; // CraftBukkit
|
|
|
|
|
2011-01-04 01:43:23 +01:00
|
|
|
public class PropertyManager {
|
|
|
|
|
|
|
|
public static Logger a = Logger.getLogger("Minecraft");
|
2012-07-29 09:33:13 +02:00
|
|
|
public Properties properties = new Properties(); // CraftBukkit - private -> public
|
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()) {
|
2012-07-29 09:33:13 +02:00
|
|
|
FileInputStream fileinputstream = null;
|
|
|
|
|
2011-01-04 01:43:23 +01:00
|
|
|
try {
|
2012-07-29 09:33:13 +02:00
|
|
|
fileinputstream = new FileInputStream(file1);
|
|
|
|
this.properties.load(fileinputstream);
|
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();
|
2012-07-29 09:33:13 +02:00
|
|
|
} finally {
|
|
|
|
if (fileinputstream != null) {
|
|
|
|
try {
|
|
|
|
fileinputstream.close();
|
|
|
|
} catch (IOException ioexception) {
|
|
|
|
;
|
|
|
|
}
|
|
|
|
}
|
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
|
2012-07-22 08:18:00 +02:00
|
|
|
private OptionSet options = null;
|
2011-01-11 09:25:13 +01:00
|
|
|
|
2012-07-22 08:18:00 +02:00
|
|
|
public PropertyManager(final OptionSet options) {
|
2011-02-23 13:56:36 +01:00
|
|
|
this((File) options.valueOf("config"));
|
2011-01-04 01:43:23 +01:00
|
|
|
|
|
|
|
this.options = options;
|
|
|
|
}
|
|
|
|
|
|
|
|
private <T> T getOverride(String name, T value) {
|
2011-06-27 00:25:01 +02:00
|
|
|
if ((this.options != null) && (this.options.has(name))) {
|
|
|
|
return (T) this.options.valueOf(name);
|
2011-01-04 01:43:23 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
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-06-27 00:25:01 +02:00
|
|
|
this.savePropertiesFile();
|
2011-01-04 01:43:23 +01:00
|
|
|
}
|
|
|
|
|
2011-06-27 00:25:01 +02:00
|
|
|
public void savePropertiesFile() {
|
2012-07-29 09:33:13 +02:00
|
|
|
FileOutputStream fileoutputstream = null;
|
|
|
|
|
2011-01-04 01:43:23 +01:00
|
|
|
try {
|
2012-07-29 09:33:13 +02:00
|
|
|
fileoutputstream = new FileOutputStream(this.c);
|
|
|
|
this.properties.store(fileoutputstream, "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();
|
2012-07-29 09:33:13 +02:00
|
|
|
} finally {
|
|
|
|
if (fileoutputstream != null) {
|
|
|
|
try {
|
|
|
|
fileoutputstream.close();
|
|
|
|
} catch (IOException ioexception) {
|
|
|
|
;
|
|
|
|
}
|
|
|
|
}
|
2011-01-04 01:43:23 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-11-20 09:01:14 +01:00
|
|
|
public File c() {
|
|
|
|
return this.c;
|
|
|
|
}
|
|
|
|
|
2011-04-20 19:05:14 +02:00
|
|
|
public String getString(String s, String s1) {
|
|
|
|
if (!this.properties.containsKey(s)) {
|
2011-06-27 00:25:01 +02:00
|
|
|
s1 = this.getOverride(s, s1); // CraftBukkit
|
2011-04-20 19:05:14 +02:00
|
|
|
this.properties.setProperty(s, s1);
|
2011-06-27 00:25:01 +02:00
|
|
|
this.savePropertiesFile();
|
2011-01-04 01:43:23 +01:00
|
|
|
}
|
2011-01-29 22:50:29 +01:00
|
|
|
|
2011-06-27 00:25:01 +02:00
|
|
|
return this.getOverride(s, this.properties.getProperty(s, s1)); // CraftBukkit
|
2011-01-04 01:43:23 +01:00
|
|
|
}
|
|
|
|
|
2011-04-20 19:05:14 +02:00
|
|
|
public int getInt(String s, int i) {
|
2011-01-04 01:43:23 +01:00
|
|
|
try {
|
2011-06-27 00:25:01 +02:00
|
|
|
return this.getOverride(s, Integer.parseInt(this.getString(s, "" + i))); // CraftBukkit
|
2011-01-04 01:43:23 +01:00
|
|
|
} catch (Exception exception) {
|
2011-06-27 00:25:01 +02:00
|
|
|
i = this.getOverride(s, i); // CraftBukkit
|
2011-04-20 19:05:14 +02:00
|
|
|
this.properties.setProperty(s, "" + i);
|
2011-01-29 22:50:29 +01:00
|
|
|
return i;
|
2011-01-04 01:43:23 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-04-20 19:05:14 +02:00
|
|
|
public boolean getBoolean(String s, boolean flag) {
|
2011-01-04 01:43:23 +01:00
|
|
|
try {
|
2011-06-27 00:25:01 +02:00
|
|
|
return this.getOverride(s, Boolean.parseBoolean(this.getString(s, "" + flag))); // CraftBukkit
|
2011-01-04 01:43:23 +01:00
|
|
|
} catch (Exception exception) {
|
2011-06-27 00:25:01 +02:00
|
|
|
flag = this.getOverride(s, flag); // CraftBukkit
|
2011-04-20 19:05:14 +02:00
|
|
|
this.properties.setProperty(s, "" + flag);
|
2011-01-29 22:50:29 +01:00
|
|
|
return flag;
|
2011-01-04 01:43:23 +01:00
|
|
|
}
|
|
|
|
}
|
2011-02-23 03:37:56 +01:00
|
|
|
|
2011-11-20 09:01:14 +01:00
|
|
|
public void a(String s, Object object) {
|
|
|
|
this.properties.setProperty(s, "" + object);
|
|
|
|
}
|
2011-01-04 01:43:23 +01:00
|
|
|
}
|