Skip to content
Browse files

Switched from a Properties based config file to the bukkit FileConfig…

…uration config method. (Issue #16)

Signed-off-by: Schumann2k <schumann2k@googlemail.com>
  • Loading branch information...
1 parent 4f2183a commit 359e6267404a364e8e1d8b11c3d5dafbe15f64cc Schumann2k committed Dec 29, 2011
Showing with 20 additions and 33 deletions.
  1. +20 −33 src/main/java/com/dkhenry/minejmx/MineJMX.java
View
53 src/main/java/com/dkhenry/minejmx/MineJMX.java
@@ -37,6 +37,7 @@
import org.bukkit.event.Event;
import org.bukkit.plugin.PluginManager;
import org.bukkit.plugin.java.JavaPlugin;
+import org.bukkit.configuration.file.FileConfiguration;
import java.sql.* ;
@@ -68,8 +69,6 @@
private int port = 9999 ;
private String ip = "*" ;
private static String dir = "plugins" ;
- private static File Config = new File(dir + File.separator + "MineJMX.properties") ;
- private static Properties prop = new Properties() ;
private static String Persistance = dir + File.separator + "MineJMX.db" ;
@@ -100,37 +99,25 @@ public Subject authenticate(Object credentials) {
*/
private void loadConfig() {
/* Read in the Properties File */
- if(! Config.exists()) {
- try {
- Config.createNewFile() ;
- FileOutputStream out = new FileOutputStream(Config) ;
- prop.put("username","admin") ;
- prop.put("password","passwd") ;
- prop.put("port","9999") ;
- prop.put("ip","") ;
- prop.store(out, "Autogenerated Config File") ;
- out.flush();
- out.close() ;
- } catch (IOException e) {
- e.printStackTrace();
- }
-
- } else {
- FileInputStream in;
- try {
- in = new FileInputStream(Config);
- prop.load(in) ;
- this.username = prop.getProperty("username") ;
- this.passwd = prop.getProperty("password") ;
- this.port = Integer.parseInt(prop.getProperty("port")) ;
- this.ip = prop.getProperty("ip") ;
- } catch (FileNotFoundException e) {
- e.printStackTrace();
- } catch (IOException e) {
- e.printStackTrace();
- }
-
- }
+ FileConfiguration cfg = this.getConfig();
+ cfg.addDefault("username", "admin");
+ cfg.addDefault("password", "passwd123");
+ cfg.addDefault("port", 9999);
+ cfg.addDefault("host", "localhost");
+ cfg.options().copyDefaults(true);
+ this.saveConfig();
+
+ this.username = cfg.getString("username");
+ if(cfg.get("password").getClass().equals(Integer.class)) {
+ // All-numeric password needs to be converted to String.
+ int ipass = cfg.getInt("password");
+ this.passwd = Integer.toString(ipass);
+ }
+ else {
+ this.passwd = cfg.getString("password");
+ }
+ this.port = cfg.getInt("port");
+ this.ip = cfg.getString("host");
}

0 comments on commit 359e626

Please sign in to comment.
Something went wrong with that request. Please try again.