Do not create yml configuration object on every save/load.

This commit is contained in:
Tobias Ottenweller 2013-02-15 23:38:04 +01:00
parent 56a5f828ee
commit 32f1cba2bd

View File

@ -42,6 +42,9 @@ public class Plugin extends JavaPlugin
public PluginBlockListener blockListener = new PluginBlockListener(); public PluginBlockListener blockListener = new PluginBlockListener();
public PluginPortalListener portalListener = new PluginPortalListener(); public PluginPortalListener portalListener = new PluginPortalListener();
private File gatesConfigFile;
private FileConfiguration gatesConfig;
private String baseCommand; private String baseCommand;
private String gatesPath = "gates"; private String gatesPath = "gates";
@ -85,7 +88,6 @@ public class Plugin extends JavaPlugin
{ {
// Save gates // Save gates
saveGates(); saveGates();
log("Disabled"); log("Disabled");
} }
@ -115,6 +117,19 @@ public class Plugin extends JavaPlugin
pm.registerEvents(this.portalListener, this); pm.registerEvents(this.portalListener, this);
// Load gates // Load gates
this.gatesConfigFile = new File(getDataFolder(), "gates.yml");
if(!this.gatesConfigFile.exists())
{
try {
this.gatesConfigFile.createNewFile();
} catch (IOException e) {
log(Level.SEVERE, "Cannot create gate config file! No gates will be persisted.");
}
}
this.gatesConfig = YamlConfiguration.loadConfiguration(gatesConfigFile);
loadGates(); loadGates();
log("Enabled"); log("Enabled");
@ -198,13 +213,11 @@ public class Plugin extends JavaPlugin
public void saveGates() public void saveGates()
{ {
File gatesFile = new File(getDataFolder(), "gates.yml");
FileConfiguration gatesConfig = YamlConfiguration.loadConfiguration(gatesFile);
gatesConfig.set(gatesPath, new ArrayList<Object>(Gate.getAll())); gatesConfig.set(gatesPath, new ArrayList<Object>(Gate.getAll()));
try { try {
gatesConfig.save(gatesFile); gatesConfig.save(gatesConfigFile);
log("Saved gates to disk.");
} }
catch (IOException e) { catch (IOException e) {
log("ERROR: Could not save gates to disk."); log("ERROR: Could not save gates to disk.");