diff --git a/plugin/src/main/java/net/aufdemrand/denizen/Denizen.java b/plugin/src/main/java/net/aufdemrand/denizen/Denizen.java index 2f6e195445..8db391d2be 100644 --- a/plugin/src/main/java/net/aufdemrand/denizen/Denizen.java +++ b/plugin/src/main/java/net/aufdemrand/denizen/Denizen.java @@ -73,6 +73,7 @@ import net.aufdemrand.denizencore.utilities.debugging.Debuggable; import net.aufdemrand.denizencore.utilities.debugging.SlowWarning; import net.aufdemrand.denizencore.utilities.debugging.dB.DebugElement; +import net.aufdemrand.denizencore.utilities.text.ConfigUpdater; import net.citizensnpcs.api.CitizensAPI; import net.citizensnpcs.api.trait.TraitInfo; import org.apache.commons.lang.StringUtils; @@ -90,8 +91,7 @@ import org.bukkit.plugin.java.JavaPlugin; import org.bukkit.scheduler.BukkitRunnable; -import java.io.File; -import java.io.IOException; +import java.io.*; import java.net.URLDecoder; import java.util.ArrayList; import java.util.Arrays; @@ -266,7 +266,6 @@ public class Denizen extends JavaPlugin implements DenizenImplementation { - public final static int configVersion = 15; public static String versionTag = null; private boolean startedSuccessful = false; @@ -486,17 +485,28 @@ public void onEnable() { } try { - // Warn if configuration is outdated / too new - if (!getConfig().isSet("Config.Version") || - getConfig().getInt("Config.Version", 0) != configVersion) { - - dB.echoError("Your Denizen config file is from an older version. " + - "Some settings will not be available unless you generate a new one. " + - "This is easily done by stopping the server, deleting the current config.yml file in the Denizen folder " + - "and restarting the server."); + // Automatic config file update + InputStream properConfig = Denizen.class.getResourceAsStream("/config.yml"); + String properConfigString = ScriptHelper.convertStreamToString(properConfig); + properConfig.close(); + FileInputStream currentConfig = new FileInputStream(getDataFolder() + "/config.yml"); + String currentConfigString = ScriptHelper.convertStreamToString(currentConfig); + currentConfig.close(); + String updated = ConfigUpdater.updateConfig(currentConfigString, properConfigString); + if (updated != null) { + dB.log("Your config file is outdated. Automatically updating it..."); + FileOutputStream configOutput = new FileOutputStream(getDataFolder() + "/config.yml"); + OutputStreamWriter writer = new OutputStreamWriter(configOutput); + writer.write(updated); + writer.close(); + configOutput.close(); } + } + catch (Exception e) { + dB.echoError(e); + } - // Create the command script handler for listener + try { ws_helper = new BukkitWorldScriptHelper(); ItemScriptHelper is_helper = new ItemScriptHelper(); InventoryScriptHelper in_helper = new InventoryScriptHelper(); diff --git a/plugin/src/main/resources/config.yml b/plugin/src/main/resources/config.yml index d7c1e007f2..00e8752881 100644 --- a/plugin/src/main/resources/config.yml +++ b/plugin/src/main/resources/config.yml @@ -1,5 +1,6 @@ -# Whether debug information about Denizen should appear in the -# server console +# Denizen config. + +# Whether debug information about Denizen should appear in the server console Debug: Show: true Ex command help: true @@ -13,7 +14,7 @@ Debug: # This is purely to maintain basic information on things like how many servers run any given version of Denizen. # Please do not disable this unless it is throwing errors (Please report any errors you receive as well). Stats: true - # Whether to force the help command to be the default bukkit help. + # Whether to force the help command to be the default bukkit help (required to fix issues with command script help options). Override help: true Scripts: @@ -157,8 +158,3 @@ Packets: # It also enables hiding item script IDs and most likely has no real reason to be disabled. # Note that changing this setting requires a full server restart. Interception: true - -# The version of this configuration file, used to check if your -# configuration file is outdated or too new -Config: - Version: 15 diff --git a/pom.xml b/pom.xml index a88b0fbe75..730c3a0128 100644 --- a/pom.xml +++ b/pom.xml @@ -12,7 +12,7 @@ UTF-8 1.13.2-R0.1-SNAPSHOT 2.0.24-SNAPSHOT - 1.30 + 1.40 Unknown CUSTOM 1.0.3