mirror of
https://github.com/Multiverse/Multiverse-Core.git
synced 2025-01-21 07:41:23 +01:00
Refactoring on the ConfigMigrator
This commit is contained in:
parent
cd7ad37887
commit
48f9226d27
@ -98,7 +98,6 @@ public class MultiverseCore extends JavaPlugin {
|
|||||||
private PurgeWorlds worldPurger;
|
private PurgeWorlds worldPurger;
|
||||||
private GenericBank bank = null;
|
private GenericBank bank = null;
|
||||||
private AllPay banker = new AllPay(this, tag + " ");
|
private AllPay banker = new AllPay(this, tag + " ");
|
||||||
public static boolean defaultConfigsCreated = false;
|
|
||||||
protected MVConfigMigrator migrator = new MVCoreConfigMigrator(this);
|
protected MVConfigMigrator migrator = new MVCoreConfigMigrator(this);
|
||||||
protected int pluginCount;
|
protected int pluginCount;
|
||||||
private DestinationFactory destFactory;
|
private DestinationFactory destFactory;
|
||||||
@ -190,8 +189,8 @@ public class MultiverseCore extends JavaPlugin {
|
|||||||
public void loadConfigs() {
|
public void loadConfigs() {
|
||||||
|
|
||||||
// Call the defaultConfiguration class to create the config files if they don't already exist.
|
// Call the defaultConfiguration class to create the config files if they don't already exist.
|
||||||
new DefaultConfiguration(getDataFolder(), "config.yml", this.migrator, MultiverseCore.defaultConfigsCreated);
|
new DefaultConfiguration(getDataFolder(), "config.yml", this.migrator);
|
||||||
new DefaultConfiguration(getDataFolder(), "worlds.yml", this.migrator, MultiverseCore.defaultConfigsCreated);
|
new DefaultConfiguration(getDataFolder(), "worlds.yml", this.migrator);
|
||||||
|
|
||||||
// Now grab the Configuration Files.
|
// Now grab the Configuration Files.
|
||||||
this.configMV = new Configuration(new File(getDataFolder(), "config.yml"));
|
this.configMV = new Configuration(new File(getDataFolder(), "config.yml"));
|
||||||
|
@ -11,7 +11,7 @@ import java.io.InputStream;
|
|||||||
*/
|
*/
|
||||||
public class DefaultConfiguration {
|
public class DefaultConfiguration {
|
||||||
|
|
||||||
public DefaultConfiguration(File folder, String name, MVConfigMigrator migrator, boolean defaultsCreated) {
|
public DefaultConfiguration(File folder, String name, MVConfigMigrator migrator) {
|
||||||
File actual = new File(folder, name);
|
File actual = new File(folder, name);
|
||||||
// If defaults have been created, and we're being called again, we should try to migrate
|
// If defaults have been created, and we're being called again, we should try to migrate
|
||||||
if (!actual.exists() && !migrator.migrate(name, folder)) {
|
if (!actual.exists() && !migrator.migrate(name, folder)) {
|
||||||
|
@ -4,9 +4,13 @@ import java.io.File;
|
|||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.logging.Level;
|
||||||
|
|
||||||
|
import org.bukkit.plugin.Plugin;
|
||||||
import org.bukkit.util.config.Configuration;
|
import org.bukkit.util.config.Configuration;
|
||||||
|
|
||||||
|
import com.onarandombox.MultiverseCore.MultiverseCore;
|
||||||
|
|
||||||
public abstract class MVConfigMigrator {
|
public abstract class MVConfigMigrator {
|
||||||
|
|
||||||
public abstract boolean migrate(String name, File folder);
|
public abstract boolean migrate(String name, File folder);
|
||||||
@ -20,4 +24,36 @@ public abstract class MVConfigMigrator {
|
|||||||
}
|
}
|
||||||
newConfig.setProperty("worlds." + key + newProperty, list);
|
newConfig.setProperty("worlds." + key + newProperty, list);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected final File detectMultiverseFolders(File folder, MultiverseCore core) {
|
||||||
|
File oldFolder = null;
|
||||||
|
|
||||||
|
// They still have MV 1 installed! Good!
|
||||||
|
if (core.getServer().getPluginManager().getPlugin("MultiVerse") != null) {
|
||||||
|
core.log(Level.INFO, "Found MultiVerse 1. Starting Config Migration...");
|
||||||
|
Plugin plugin = core.getServer().getPluginManager().getPlugin("MultiVerse");
|
||||||
|
// We found MV1, but it's enabled, get the data folder, then disable it!
|
||||||
|
if (!core.getServer().getPluginManager().isPluginEnabled("MultiVerse")) {
|
||||||
|
core.getServer().getPluginManager().disablePlugin(plugin);
|
||||||
|
}
|
||||||
|
oldFolder = plugin.getDataFolder();
|
||||||
|
} else {
|
||||||
|
// They didn't have MV 1 enabled... let's try and find the folder...
|
||||||
|
File[] folders = folder.getParentFile().listFiles();
|
||||||
|
List<File> folderList = Arrays.asList(folders);
|
||||||
|
for (File f : folderList) {
|
||||||
|
if (f.getName().equalsIgnoreCase("MultiVerse")) {
|
||||||
|
core.log(Level.INFO, "Found the MultiVerse 1 config folder. Starting Config Migration...");
|
||||||
|
oldFolder = f;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
if (oldFolder == null) {
|
||||||
|
core.log(Level.INFO, "Did not find the MV1 Folder. If you did not have MultiVerse 1 installed and this is the FIRST time you're running MV2, this message is GOOD. ");
|
||||||
|
core.log(Level.INFO, "If you did, your configs were **NOT** migrated! Go Here: INSERTURLFORHELP");
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return oldFolder;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,11 +1,9 @@
|
|||||||
package com.onarandombox.MultiverseCore.configuration;
|
package com.onarandombox.MultiverseCore.configuration;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.util.Arrays;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.logging.Level;
|
import java.util.logging.Level;
|
||||||
|
|
||||||
import org.bukkit.plugin.Plugin;
|
|
||||||
import org.bukkit.util.config.Configuration;
|
import org.bukkit.util.config.Configuration;
|
||||||
|
|
||||||
import com.onarandombox.MultiverseCore.MultiverseCore;
|
import com.onarandombox.MultiverseCore.MultiverseCore;
|
||||||
@ -18,33 +16,7 @@ public class MVCoreConfigMigrator extends MVConfigMigrator {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public boolean migrate(String name, File folder) {
|
public boolean migrate(String name, File folder) {
|
||||||
File oldFolder = null;
|
File oldFolder = this.detectMultiverseFolders(folder, core);
|
||||||
|
|
||||||
// They still have MV 1 installed! Good!
|
|
||||||
if (this.core.getServer().getPluginManager().getPlugin("MultiVerse") != null) {
|
|
||||||
this.core.log(Level.INFO, "Found MultiVerse 1. Starting Config Migration...");
|
|
||||||
if (!this.core.getServer().getPluginManager().isPluginEnabled("MultiVerse")) {
|
|
||||||
Plugin plugin = this.core.getServer().getPluginManager().getPlugin("MultiVerse");
|
|
||||||
oldFolder = plugin.getDataFolder();
|
|
||||||
this.core.getServer().getPluginManager().disablePlugin(plugin);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
// They didn't have MV 1 enabled... let's try and find the folder...
|
|
||||||
File[] folders = folder.getParentFile().listFiles();
|
|
||||||
List<File> folderList = Arrays.asList(folders);
|
|
||||||
for (File f : folderList) {
|
|
||||||
if (f.getName().equalsIgnoreCase("MultiVerse")) {
|
|
||||||
this.core.log(Level.INFO, "Found the MultiVerse 1 config folder. Starting Config Migration...");
|
|
||||||
oldFolder = f;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
if (oldFolder == null) {
|
|
||||||
this.core.log(Level.INFO, "Did not find the MV1 Folder. If you did not have MultiVerse 1 installed and this is the FIRST time you're running MV2, this message is GOOD. ");
|
|
||||||
this.core.log(Level.INFO, "If you did, your configs were **NOT** migrated! Go Here: INSERTURLFORHELP");
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (name.equalsIgnoreCase("worlds.yml")) {
|
if (name.equalsIgnoreCase("worlds.yml")) {
|
||||||
return this.migrateWorlds(name, oldFolder, folder);
|
return this.migrateWorlds(name, oldFolder, folder);
|
||||||
|
Loading…
Reference in New Issue
Block a user