mirror of
https://github.com/Multiverse/Multiverse-Core.git
synced 2024-11-05 10:20:42 +01:00
Force default worlds to be imported, Closes #265
This commit is contained in:
parent
82eff21dbf
commit
0fa8f4e824
@ -145,6 +145,8 @@ public class MultiverseCore extends JavaPlugin implements MVPlugin, Core {
|
||||
// Output a little snippet to show it's enabled.
|
||||
this.log(Level.INFO, "- Version " + this.getDescription().getVersion() + " (API v" + Protocol + ") Enabled - By " + getAuthors());
|
||||
this.checkServerProps();
|
||||
// Load the defaultWorldGenerators
|
||||
this.worldManager.getDefaultWorldGenerators();
|
||||
|
||||
this.registerEvents();
|
||||
// Setup Permissions, we'll do an initial check for the Permissions plugin then fall back on isOP().
|
||||
@ -171,6 +173,7 @@ public class MultiverseCore extends JavaPlugin implements MVPlugin, Core {
|
||||
// Setup & Load our Configuration files.
|
||||
loadConfigs();
|
||||
if (this.multiverseConfig != null) {
|
||||
this.worldManager.loadDefaultWorlds();
|
||||
this.worldManager.loadWorlds(true);
|
||||
} else {
|
||||
this.log(Level.SEVERE, "Your configs were not loaded. Very little will function in Multiverse.");
|
||||
|
@ -22,6 +22,7 @@ import org.bukkit.permissions.Permission;
|
||||
import org.bukkit.plugin.Plugin;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FilenameFilter;
|
||||
import java.io.IOException;
|
||||
import java.util.*;
|
||||
import java.util.logging.Level;
|
||||
@ -37,6 +38,7 @@ public class WorldManager implements MVWorldManager {
|
||||
private Map<String, MultiverseWorld> worlds;
|
||||
private List<String> unloadedWorlds;
|
||||
private FileConfiguration configWorlds = null;
|
||||
private Map<String, String> defaultGens;
|
||||
|
||||
public WorldManager(MultiverseCore core) {
|
||||
this.plugin = core;
|
||||
@ -45,6 +47,22 @@ public class WorldManager implements MVWorldManager {
|
||||
this.worldPurger = new PurgeWorlds(this.plugin);
|
||||
}
|
||||
|
||||
public void getDefaultWorldGenerators() {
|
||||
this.defaultGens = new HashMap<String, String>();
|
||||
File[] files = this.plugin.getServerFolder().listFiles(new FilenameFilter() {
|
||||
@Override
|
||||
public boolean accept(File file, String s) {
|
||||
return s.equalsIgnoreCase("bukkit.yml");
|
||||
}
|
||||
});
|
||||
if (files.length == 1) {
|
||||
FileConfiguration bukkitConfig = YamlConfiguration.loadConfiguration(files[0]);
|
||||
Set<String> keys = bukkitConfig.getConfigurationSection("worlds").getKeys(false);
|
||||
for (String key : keys) {
|
||||
defaultGens.put(key, bukkitConfig.getString("worlds." + key + ".generator", ""));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
@ -64,7 +82,9 @@ public class WorldManager implements MVWorldManager {
|
||||
|
||||
|
||||
// TODO: Use the fancy kind with the commandSender
|
||||
c.generator(generator);
|
||||
if (generator != null && generator.length() != 0) {
|
||||
c.generator(generator);
|
||||
}
|
||||
c.environment(env);
|
||||
|
||||
World world = null;
|
||||
@ -352,13 +372,25 @@ public class WorldManager implements MVWorldManager {
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public void loadWorlds(boolean forceLoad) {
|
||||
// Basic Counter to count how many Worlds we are loading.
|
||||
int count = 0;
|
||||
// Grab all the Worlds from the Config.
|
||||
public void loadDefaultWorlds() {
|
||||
this.ensureConfigIsPrepared();
|
||||
List<World> worlds = this.plugin.getServer().getWorlds();
|
||||
Set<String> worldStrings = this.configWorlds.getConfigurationSection("worlds").getKeys(false);
|
||||
for (World w : worlds) {
|
||||
String name = w.getName();
|
||||
System.out.println(defaultGens);
|
||||
if (!worldStrings.contains(name)) {
|
||||
if (this.defaultGens.containsKey(name)) {
|
||||
this.addWorld(name, w.getEnvironment(), w.getSeed() + "", this.defaultGens.get(name));
|
||||
} else {
|
||||
this.addWorld(name, w.getEnvironment(), w.getSeed() + "", null);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void ensureConfigIsPrepared() {
|
||||
if (this.configWorlds.getConfigurationSection("worlds") == null) {
|
||||
this.configWorlds.createSection("worlds");
|
||||
try {
|
||||
@ -367,6 +399,16 @@ public class WorldManager implements MVWorldManager {
|
||||
this.plugin.log(Level.SEVERE, "Failed to save worlds.yml. Please check your file permissions.");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public void loadWorlds(boolean forceLoad) {
|
||||
// Basic Counter to count how many Worlds we are loading.
|
||||
int count = 0;
|
||||
this.ensureConfigIsPrepared();
|
||||
// Grab all the Worlds from the Config.
|
||||
Set<String> worldKeys = this.configWorlds.getConfigurationSection("worlds").getKeys(false);
|
||||
|
||||
// Force the worlds to be loaded, ie don't just load new worlds.
|
||||
|
@ -151,15 +151,16 @@ public class TestWorldStuff {
|
||||
Command mockCommand = mock(Command.class);
|
||||
when(mockCommand.getName()).thenReturn("mv");
|
||||
|
||||
// Ensure that there are no worlds imported. This is a fresh setup.
|
||||
assertEquals(0, creator.getCore().getMVWorldManager().getMVWorlds().size());
|
||||
// Ensure that there are 3 imported. This is a fresh setup.
|
||||
// As of 11/26/11, MV autodetects all default worlds.
|
||||
assertEquals(3, creator.getCore().getMVWorldManager().getMVWorlds().size());
|
||||
|
||||
// Create the world
|
||||
String[] normalArgs = new String[] { "create", "newworld", "normal" };
|
||||
plugin.onCommand(mockCommandSender, mockCommand, "", normalArgs);
|
||||
|
||||
// We should now have one world!
|
||||
assertEquals(1, creator.getCore().getMVWorldManager().getMVWorlds().size());
|
||||
assertEquals(4, creator.getCore().getMVWorldManager().getMVWorlds().size());
|
||||
|
||||
// Verify
|
||||
verify(mockCommandSender).sendMessage("Starting creation of world 'newworld'...");
|
||||
|
@ -56,7 +56,7 @@ public class TestInstanceCreator {
|
||||
doReturn(pluginDirectory).when(core).getDataFolder();
|
||||
|
||||
// Return a fake PDF file.
|
||||
PluginDescriptionFile pdf = new PluginDescriptionFile("Multiverse-Core", "2.1-Test",
|
||||
PluginDescriptionFile pdf = new PluginDescriptionFile("Multiverse-Core", "2.2-Test",
|
||||
"com.onarandombox.MultiverseCore.MultiverseCore");
|
||||
doReturn(pdf).when(core).getDescription();
|
||||
doReturn(true).when(core).isEnabled();
|
||||
|
Loading…
Reference in New Issue
Block a user