Skip to content
This repository has been archived by the owner on Jul 27, 2019. It is now read-only.

Commit

Permalink
Fix first time config.yml loading.
Browse files Browse the repository at this point in the history
  • Loading branch information
cnaude committed Sep 14, 2014
1 parent 274ead8 commit e69c09b
Showing 1 changed file with 20 additions and 8 deletions.
28 changes: 20 additions & 8 deletions src/main/java/com/cnaude/purpleirc/PurpleIRC.java
Expand Up @@ -175,6 +175,7 @@ public void onEnable() {
pluginFolder = getDataFolder();
botsFolder = new File(pluginFolder + "/bots");
configFile = new File(pluginFolder, "config.yml");
createConfigDirs();
createConfig();
getConfig().options().copyDefaults(true);
saveConfig();
Expand Down Expand Up @@ -540,6 +541,11 @@ public void loadTemplates(YamlConfiguration config, String configName) {
}

private void loadConfig() {
try {
getConfig().load(configFile);
} catch (IOException | InvalidConfigurationException ex) {
logError(ex.getMessage());
}
debugEnabled = getConfig().getBoolean("Debug");
identServerEnabled = getConfig().getBoolean("enable-ident-server");
logDebug("Debug enabled");
Expand Down Expand Up @@ -669,30 +675,36 @@ public void reloadMainConfig(CommandSender sender) {
sender.sendMessage(LOG_HEADER_F + ChatColor.WHITE + " Done.");
}

private void createConfig() {
private void createConfigDirs() {
if (!pluginFolder.exists()) {
try {
logInfo("Creating " + pluginFolder.getAbsolutePath());
pluginFolder.mkdir();
} catch (Exception e) {
logError(e.getMessage());
}
}

if (!configFile.exists()) {
if (!botsFolder.exists()) {
try {
configFile.createNewFile();
} catch (IOException e) {
logInfo("Creating " + botsFolder.getAbsolutePath());
botsFolder.mkdir();
} catch (Exception e) {
logError(e.getMessage());
}
}

if (!botsFolder.exists()) {
}

private void createConfig() {
if (!configFile.exists()) {
try {
botsFolder.mkdir();
} catch (Exception e) {
logInfo("Creating config.yml");
configFile.createNewFile();
} catch (IOException e) {
logError(e.getMessage());
}
}

}

/**
Expand Down

0 comments on commit e69c09b

Please sign in to comment.