From 5d8833a11c43881ab09bc2988409224c1de50751 Mon Sep 17 00:00:00 2001 From: Nathan Adams Date: Mon, 10 Oct 2011 23:04:01 +0100 Subject: Lazy-load the old and new configs for plugins .getConfig --- .../java/org/bukkit/plugin/java/JavaPlugin.java | 24 +++++++++++++--------- 1 file changed, 14 insertions(+), 10 deletions(-) diff --git a/src/main/java/org/bukkit/plugin/java/JavaPlugin.java b/src/main/java/org/bukkit/plugin/java/JavaPlugin.java index 6eee36eb..f9966ac5 100644 --- a/src/main/java/org/bukkit/plugin/java/JavaPlugin.java +++ b/src/main/java/org/bukkit/plugin/java/JavaPlugin.java @@ -111,10 +111,24 @@ public abstract class JavaPlugin implements Plugin { */ @Deprecated public Configuration getConfiguration() { + if (config == null) { + config = new Configuration(configFile); + config.load(); + } return config; } public FileConfiguration getConfig() { + if (newConfig == null) { + newConfig = YamlConfiguration.loadConfiguration(configFile); + + InputStream defConfigStream = getResource("config.yml"); + if (defConfigStream != null) { + YamlConfiguration defConfig = YamlConfiguration.loadConfiguration(defConfigStream); + + newConfig.setDefaults(defConfig); + } + } return newConfig; } @@ -184,16 +198,6 @@ public abstract class JavaPlugin implements Plugin { this.dataFolder = dataFolder; this.classLoader = classLoader; this.configFile = new File(dataFolder, "config.yml"); - this.config = new Configuration(configFile); - this.config.load(); - this.newConfig = YamlConfiguration.loadConfiguration(configFile); - - InputStream defConfigStream = getResource("config.yml"); - if (defConfigStream != null) { - YamlConfiguration defConfig = YamlConfiguration.loadConfiguration(defConfigStream); - - newConfig.setDefaults(defConfig); - } if (description.isDatabaseEnabled()) { ServerConfig db = new ServerConfig(); -- cgit v1.2.3