Skip to content

Commit

Permalink
add config file automatic updating
Browse files Browse the repository at this point in the history
  • Loading branch information
mcmonkey4eva committed Mar 9, 2019
1 parent 7809db9 commit 137452e
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 21 deletions.
34 changes: 22 additions & 12 deletions plugin/src/main/java/net/aufdemrand/denizen/Denizen.java
Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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;

Expand Down Expand Up @@ -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();
Expand Down
12 changes: 4 additions & 8 deletions 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
Expand All @@ -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:
Expand Down Expand Up @@ -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
2 changes: 1 addition & 1 deletion pom.xml
Expand Up @@ -12,7 +12,7 @@
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<craftbukkit.version>1.13.2-R0.1-SNAPSHOT</craftbukkit.version>
<citizens.version>2.0.24-SNAPSHOT</citizens.version>
<dcore.version>1.30</dcore.version>
<dcore.version>1.40</dcore.version>
<BUILD_NUMBER>Unknown</BUILD_NUMBER>
<BUILD_CLASS>CUSTOM</BUILD_CLASS>
<DENIZEN_VERSION>1.0.3</DENIZEN_VERSION>
Expand Down

0 comments on commit 137452e

Please sign in to comment.