Merge pull request #2987 from Multiverse/new-config-migrate

Do not migrate if new config file is created
This commit is contained in:
Ben Woo 2023-09-01 23:41:51 +08:00 committed by GitHub
commit adcbcdb7df
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 10 additions and 12 deletions

View File

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