mirror of
https://github.com/mcMMO-Dev/mcMMO.git
synced 2024-11-29 08:36:45 +01:00
Update LoadProperties to use new FileConfiguration
This commit is contained in:
parent
c46d900833
commit
401af172ae
@ -7,7 +7,8 @@ Version 1.2.09-dev
|
|||||||
- Changed timer to be a bit more efficient (Issue #19)
|
- Changed timer to be a bit more efficient (Issue #19)
|
||||||
- Changed to fire EntityDamageEvents for all damage done by mcMMO
|
- Changed to fire EntityDamageEvents for all damage done by mcMMO
|
||||||
- New custom event for developers McMMOPlayerLevelUpEvent
|
- New custom event for developers McMMOPlayerLevelUpEvent
|
||||||
- New custmo event for developers McMMOItemSpawnEvent
|
- New custom event for developers McMMOItemSpawnEvent
|
||||||
|
- Fishing Configuration inclusion (Pull Request #60)
|
||||||
|
|
||||||
Version 1.2.08
|
Version 1.2.08
|
||||||
- Changed Bukkit events to new event system
|
- Changed Bukkit events to new event system
|
||||||
|
@ -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/";
|
public LoadProperties(mcMMO plugin)
|
||||||
|
{
|
||||||
File file = new File(directory + File.separator + "config.yml");
|
this.plugin = plugin;
|
||||||
static Configuration config = null;
|
dataFolder = plugin.getDataFolder();
|
||||||
|
configFile = new File(dataFolder, "config.yml");
|
||||||
|
}
|
||||||
|
|
||||||
public void configCheck()
|
public void configCheck()
|
||||||
{
|
{
|
||||||
new File(directory).mkdir();
|
load();
|
||||||
config = load();
|
if(!configFile.exists())
|
||||||
if(!file.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.set(root, x);
|
||||||
config.save();
|
|
||||||
}
|
}
|
||||||
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);
|
config.load(configFile);
|
||||||
configx.load();
|
return config;
|
||||||
return configx;
|
|
||||||
|
|
||||||
} 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())
|
||||||
{
|
{
|
||||||
|
@ -97,7 +97,7 @@ public class mcMMO extends JavaPlugin
|
|||||||
public Misc misc = new Misc(this);
|
public Misc misc = new Misc(this);
|
||||||
|
|
||||||
//Config file stuff
|
//Config file stuff
|
||||||
LoadProperties config = new LoadProperties();
|
LoadProperties config = new LoadProperties(this);
|
||||||
//Jar stuff
|
//Jar stuff
|
||||||
public static File mcmmo;
|
public static File mcmmo;
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user