Do not migrate if new config file is created

This commit is contained in:
Ben Woo 2023-09-01 00:03:29 +08:00
parent 1e9f19b01f
commit 1b2f8889ce
No known key found for this signature in database
GPG Key ID: FB2A3645536E12C8

View File

@ -34,15 +34,21 @@ abstract class FileConfigHandle<C extends FileConfiguration> extends GenericConf
*/ */
@Override @Override
public boolean load() { public boolean load() {
if (!createConfigFile()) { boolean newFileCreated;
try {
newFileCreated = createConfigFile();
} catch (IOException e) {
Logging.severe("Failed to create config file: %s", configFile.getName()); Logging.severe("Failed to create config file: %s", configFile.getName());
Logging.severe(e.getMessage());
return false; return false;
} }
if (!loadConfigObject()) { if (!loadConfigObject()) {
Logging.severe("Failed to load config file: %s", configFile.getName()); Logging.severe("Failed to load config file: %s", configFile.getName());
return false; return false;
} }
migrateConfig(); if (!newFileCreated) {
migrateConfig();
}
setUpNodes(); setUpNodes();
return true; return true;
} }
@ -52,19 +58,11 @@ abstract class FileConfigHandle<C extends FileConfiguration> extends GenericConf
* *
* @return True if file exist or created successfully, otherwise false. * @return True if file exist or created successfully, otherwise false.
*/ */
protected boolean createConfigFile() { protected boolean createConfigFile() throws IOException {
if (configFile.exists()) { if (configFile.exists()) {
return true;
}
try {
if (!configFile.createNewFile()) {
return false;
}
Logging.info("Created new config file: %s", configFile.getName());
} catch (IOException e) {
return false; return false;
} }
return true; return configFile.createNewFile();
} }
/** /**