|
@@ -16,8 +16,11 @@
|
|
*/
|
|
*/
|
|
package com.gmail.nossr50.config;
|
|
package com.gmail.nossr50.config;
|
|
|
|
|
|
|
|
+import com.gmail.nossr50.mcMMO;
|
|
import java.io.File;
|
|
import java.io.File;
|
|
-import org.bukkit.util.config.Configuration;
|
|
|
|
|
|
+import java.io.IOException;
|
|
|
|
+
|
|
|
|
+import org.bukkit.configuration.file.FileConfiguration;
|
|
|
|
|
|
import com.gmail.nossr50.datatypes.HUDType;
|
|
import com.gmail.nossr50.datatypes.HUDType;
|
|
|
|
|
|
@@ -53,21 +56,27 @@ public class LoadProperties
|
|
archeryxpmodifier, swordsxpmodifier, axesxpmodifier, acrobaticsxpmodifier;
|
|
archeryxpmodifier, swordsxpmodifier, axesxpmodifier, acrobaticsxpmodifier;
|
|
|
|
|
|
public static HUDType defaulthud;
|
|
public static HUDType defaulthud;
|
|
|
|
+ protected static File configFile;
|
|
|
|
+ protected static File dataFolder;
|
|
|
|
+ protected final mcMMO plugin;
|
|
|
|
+ protected static FileConfiguration config;
|
|
|
|
|
|
- public String directory = "plugins/mcMMO/";
|
|
|
|
-
|
|
|
|
- File file = new File(directory + File.separator + "config.yml");
|
|
|
|
- static Configuration config = null;
|
|
|
|
|
|
+ public LoadProperties(mcMMO plugin)
|
|
|
|
+ {
|
|
|
|
+ this.plugin = plugin;
|
|
|
|
+ dataFolder = plugin.getDataFolder();
|
|
|
|
+ configFile = new File(dataFolder, "config.yml");
|
|
|
|
+ }
|
|
|
|
|
|
public void configCheck()
|
|
public void configCheck()
|
|
{
|
|
{
|
|
- new File(directory).mkdir();
|
|
|
|
- config = load();
|
|
|
|
- if(!file.exists())
|
|
|
|
|
|
+ load();
|
|
|
|
+ if(!configFile.exists())
|
|
{
|
|
{
|
|
try
|
|
try
|
|
{
|
|
{
|
|
- file.createNewFile();
|
|
|
|
|
|
+ configFile.getParentFile().mkdir();
|
|
|
|
+ configFile.createNewFile();
|
|
addDefaults();
|
|
addDefaults();
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
catch (Exception ex)
|
|
@@ -83,27 +92,26 @@ public class LoadProperties
|
|
private void write(String root, Object x)
|
|
private void write(String root, Object x)
|
|
{
|
|
{
|
|
//Configuration config = load();
|
|
//Configuration config = load();
|
|
- config.setProperty(root, x);
|
|
|
|
- config.save();
|
|
|
|
|
|
+ config.set(root, x);
|
|
}
|
|
}
|
|
private Boolean readBoolean(String root, Boolean def)
|
|
private Boolean readBoolean(String root, Boolean def)
|
|
{
|
|
{
|
|
//Configuration config = load();
|
|
//Configuration config = load();
|
|
Boolean result = config.getBoolean(root, def);
|
|
Boolean result = config.getBoolean(root, def);
|
|
- config.save();
|
|
|
|
|
|
+ saveConfig();
|
|
return result;
|
|
return result;
|
|
}
|
|
}
|
|
private Double readDouble(String root, Double def)
|
|
private Double readDouble(String root, Double def)
|
|
{
|
|
{
|
|
Double result = config.getDouble(root, def);
|
|
Double result = config.getDouble(root, def);
|
|
- config.save();
|
|
|
|
|
|
+ saveConfig();
|
|
return result;
|
|
return result;
|
|
}
|
|
}
|
|
private Integer readInteger(String root, Integer def)
|
|
private Integer readInteger(String root, Integer def)
|
|
{
|
|
{
|
|
//Configuration config = load();
|
|
//Configuration config = load();
|
|
Integer result = config.getInt(root, def);
|
|
Integer result = config.getInt(root, def);
|
|
- config.save();
|
|
|
|
|
|
+ saveConfig();
|
|
return result;
|
|
return result;
|
|
}
|
|
}
|
|
|
|
|
|
@@ -111,22 +119,31 @@ public class LoadProperties
|
|
{
|
|
{
|
|
//Configuration config = load();
|
|
//Configuration config = load();
|
|
String result = config.getString(root, def);
|
|
String result = config.getString(root, def);
|
|
- config.save();
|
|
|
|
|
|
+ saveConfig();
|
|
return result;
|
|
return result;
|
|
}
|
|
}
|
|
|
|
|
|
- private Configuration load()
|
|
|
|
|
|
+ private FileConfiguration load()
|
|
{
|
|
{
|
|
try {
|
|
try {
|
|
- Configuration configx = new Configuration(file);
|
|
|
|
- configx.load();
|
|
|
|
- return configx;
|
|
|
|
|
|
+ config.load(configFile);
|
|
|
|
+ return config;
|
|
|
|
|
|
} catch (Exception e) {
|
|
} catch (Exception e) {
|
|
e.printStackTrace();
|
|
e.printStackTrace();
|
|
}
|
|
}
|
|
return null;
|
|
return null;
|
|
}
|
|
}
|
|
|
|
+
|
|
|
|
+ private static void saveConfig()
|
|
|
|
+ {
|
|
|
|
+ try {
|
|
|
|
+ config.save(configFile);
|
|
|
|
+ } catch (IOException e) {
|
|
|
|
+ e.printStackTrace();
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
private void addDefaults()
|
|
private void addDefaults()
|
|
{
|
|
{
|
|
System.out.println("Generating Config File...");
|
|
System.out.println("Generating Config File...");
|
|
@@ -389,6 +406,7 @@ public class LoadProperties
|
|
write("Fishing.Drops.Glowstone_Dust", true);
|
|
write("Fishing.Drops.Glowstone_Dust", true);
|
|
write("Fishing.Drops.Diamonds", true);
|
|
write("Fishing.Drops.Diamonds", true);
|
|
|
|
|
|
|
|
+ saveConfig();
|
|
loadkeys();
|
|
loadkeys();
|
|
}
|
|
}
|
|
private void loadkeys()
|
|
private void loadkeys()
|
|
@@ -396,6 +414,7 @@ public class LoadProperties
|
|
System.out.println("Loading Config File...");
|
|
System.out.println("Loading Config File...");
|
|
|
|
|
|
//Setup default HUD
|
|
//Setup default HUD
|
|
|
|
+ load();
|
|
String temp = readString("Spout.HUD.Default", "STANDARD");
|
|
String temp = readString("Spout.HUD.Default", "STANDARD");
|
|
for(HUDType x : HUDType.values())
|
|
for(HUDType x : HUDType.values())
|
|
{
|
|
{
|