Fixed #918, Update to RB

Also added a test for #918, I probably need one more (to test that generators DO work) but I just tested that ingame this time.
This commit is contained in:
Eric Stokes 2012-10-21 13:38:36 -06:00
parent 19fb9df5cf
commit 009ceeeede
4 changed files with 45 additions and 93 deletions

View File

@ -230,7 +230,7 @@
<dependency> <dependency>
<groupId>org.bukkit</groupId> <groupId>org.bukkit</groupId>
<artifactId>bukkit</artifactId> <artifactId>bukkit</artifactId>
<version>1.3.1-R2.1-SNAPSHOT</version> <version>1.3.2-R2.1-SNAPSHOT</version>
<!-- If you want the lates, use this --> <!-- If you want the lates, use this -->
<!-- <version>LATEST</version> --> <!-- <version>LATEST</version> -->
<type>jar</type> <type>jar</type>

View File

@ -18,6 +18,8 @@ import org.bukkit.command.CommandSender;
import org.bukkit.permissions.PermissionDefault; import org.bukkit.permissions.PermissionDefault;
import java.io.File; import java.io.File;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List; import java.util.List;
/** /**
@ -88,7 +90,19 @@ public class CreateCommand extends MultiverseCommand {
EnvironmentCommand.showWorldTypes(sender); EnvironmentCommand.showWorldTypes(sender);
return; return;
} }
// Determine if the generator is valid. #918
if (generator != null) {
List<String> genarray = new ArrayList<String>(Arrays.asList(generator.split(":")));
if (genarray.size() < 2) {
// If there was only one arg specified, pad with another empty one.
genarray.add("");
}
if (this.worldManager.getChunkGenerator(genarray.get(0), genarray.get(1), "test") == null) {
// We have an invalid generator.
Command.broadcastCommandMessage(sender, "Invalid generator! '" + generator + "'. " + ChatColor.RED + "Aborting world creation.");
return;
}
}
Command.broadcastCommandMessage(sender, "Starting creation of world '" + worldName + "'..."); Command.broadcastCommandMessage(sender, "Starting creation of world '" + worldName + "'...");
if (this.worldManager.addWorld(worldName, environment, seed, type, allowStructures, generator, useSpawnAdjust)) { if (this.worldManager.addWorld(worldName, environment, seed, type, allowStructures, generator, useSpawnAdjust)) {

View File

@ -1,91 +0,0 @@
package com.onarandombox.MultiverseCore.test;
import com.onarandombox.MultiverseCore.MultiverseCore;
import com.onarandombox.MultiverseCore.test.utils.TestInstanceCreator;
import com.onarandombox.MultiverseCore.utils.WorldManager;
import org.bukkit.ChatColor;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.configuration.Configuration;
import org.bukkit.configuration.ConfigurationSection;
import org.bukkit.plugin.PluginDescriptionFile;
import org.junit.After;
import org.junit.Before;
import org.junit.Ignore;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.internal.verification.VerificationModeFactory;
import org.powermock.core.classloader.annotations.PrepareForTest;
import org.powermock.modules.junit4.PowerMockRunner;
import java.lang.reflect.Field;
import static org.junit.Assert.*;
import static org.mockito.Mockito.*;
@RunWith(PowerMockRunner.class)
@PrepareForTest({ MultiverseCore.class, PluginDescriptionFile.class })
public class TestWorldCreation {
private TestInstanceCreator creator;
private MultiverseCore core;
private CommandSender mockCommandSender;
@Before
public void setUp() throws Exception {
this.creator = new TestInstanceCreator();
assertTrue(this.creator.setUp());
this.core = this.creator.getCore();
this.mockCommandSender = this.creator.getCommandSender();
}
@After
public void tearDown() throws Exception {
creator.tearDown();
}
@Test
@Ignore
public void test() {
// Initialize a fake command
Command mockCommand = mock(Command.class);
when(mockCommand.getName()).thenReturn("mv");
// Try to create a world that exists
String[] normalArgs = new String[] { "create", "world", "normal" };
core.onCommand(mockCommandSender, mockCommand, "", normalArgs);
verify(mockCommandSender).sendMessage(ChatColor.RED + "A Folder/World already exists with this name!");
verify(mockCommandSender).sendMessage(ChatColor.RED + "If you are confident it is a world you can import with /mvimport");
// Try to create a world that is new
String[] newArgs = new String[] { "create", "world2", "normal" };
core.onCommand(mockCommandSender, mockCommand, "", newArgs);
verify(mockCommandSender).sendMessage("Starting creation of world 'world2'...");
String[] dottedWorld = new String[] { "create", "fish.world", "normal" };
core.onCommand(mockCommandSender, mockCommand, "", dottedWorld);
verify(mockCommandSender).sendMessage("Starting creation of world 'fish.world'...");
verify(mockCommandSender, VerificationModeFactory.times(2)).sendMessage("Complete!");
// Grab the Config
Field worldConfigField = null;
ConfigurationSection worldsSection = null;
try {
worldConfigField = WorldManager.class.getDeclaredField("configWorlds");
worldConfigField.setAccessible(true);
Configuration rootConfig = (Configuration) worldConfigField.get(this.core.getMVWorldManager());
worldsSection = rootConfig.getConfigurationSection("worlds");
} catch (NoSuchFieldException e) {
e.printStackTrace();
} catch (IllegalAccessException e) {
e.printStackTrace();
}
// Verify that the world was added to the configs
// TODO: Expand this.
assertNotNull(worldsSection);
assertEquals(2, worldsSection.getKeys(false).size());
assertTrue(worldsSection.getKeys(false).contains("world2"));
assertTrue(worldsSection.getKeys(false).contains("fish.world"));
}
}

View File

@ -168,6 +168,35 @@ public class TestWorldStuff {
verify(mockServer).createWorld(Matchers.argThat(matcher)); verify(mockServer).createWorld(Matchers.argThat(matcher));
} }
@Test
public void testWorldCreateInvalidGenerator() {
// Pull a core instance from the server.
Plugin plugin = mockServer.getPluginManager().getPlugin("Multiverse-Core");
// Make sure Core is not null
assertNotNull(plugin);
// Make sure Core is enabled
assertTrue(plugin.isEnabled());
// Initialize a fake command
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());
// Create the world
String[] normalArgs = new String[]{ "create", "newworld", "normal", "-g", "BogusGen"};
plugin.onCommand(mockCommandSender, mockCommand, "", normalArgs);
// This command should halt, not creating any worlds
assertEquals(0, creator.getCore().getMVWorldManager().getMVWorlds().size());
// Verify
verify(mockCommandSender).sendMessage("Invalid generator! 'BogusGen'. " + ChatColor.RED + "Aborting world creation.");
}
@Test @Test
public void testNullWorld() { public void testNullWorld() {
// Pull a core instance from the server. // Pull a core instance from the server.