Fix purging removing the player entity

...and lots of other bad stuff...
This commit is contained in:
Eric Stokes 2012-03-09 23:45:10 -07:00
parent bdd5e8bd91
commit d84f930a54
5 changed files with 120 additions and 7 deletions

View File

@ -180,7 +180,9 @@
<dependency>
<groupId>org.bukkit</groupId>
<artifactId>bukkit</artifactId>
<version>1.1-R5-SNAPSHOT</version>
<version>1.2.3-R0.2-SNAPSHOT</version>
<!-- If you want the lates, use this -->
<!-- <version>LATEST</version> -->
<type>jar</type>
<scope>compile</scope>
</dependency>

View File

@ -566,8 +566,8 @@ public interface MultiverseWorld {
String getTime();
/**
* Gets the type of this world. As of 1.1-R1 this will be:
* FLAT or NORMAL
* Gets the type of this world. As of 1.2 this will be:
* FLAT, NORMAL or VERSION_1_1
* <p>
* This is *not* the generator.
*

View File

@ -53,8 +53,8 @@ public class EnvironmentCommand extends MultiverseCommand {
*/
public static void showWorldTypes(CommandSender sender) {
sender.sendMessage(ChatColor.YELLOW + "Valid World Types are:");
sender.sendMessage(String.format("%sNORMAL %sor %sFLAT",
ChatColor.GREEN, ChatColor.WHITE, ChatColor.AQUA));
sender.sendMessage(String.format("%sNORMAL%,s %sFLAT %sor %sVERSION_1_1",
ChatColor.GREEN, ChatColor.WHITE, ChatColor.AQUA, ChatColor.WHITE, ChatColor.GOLD));
}
@Override

View File

@ -15,6 +15,10 @@ import org.bukkit.World;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Animals;
import org.bukkit.entity.Entity;
import org.bukkit.entity.Ghast;
import org.bukkit.entity.Monster;
import org.bukkit.entity.Player;
import org.bukkit.entity.Slime;
import org.bukkit.entity.Squid;
import java.util.ArrayList;
@ -76,7 +80,7 @@ public class SimpleWorldPurger implements WorldPurger {
boolean specifiedAnimals = thingsToKill.contains("ANIMALS") || specifiedAll;
boolean specifiedMonsters = thingsToKill.contains("MONSTERS") || specifiedAll;
for (Entity e : world.getEntities()) {
boolean negate;
boolean negate = false;
boolean specified = false;
if (e instanceof Squid || e instanceof Animals) {
// it's an animal
@ -89,7 +93,7 @@ public class SimpleWorldPurger implements WorldPurger {
if (specifiedAnimals)
specified = true;
negate = negateAnimals;
} else {
} else if (e instanceof Monster || e instanceof Ghast || e instanceof Slime) {
// it's a monster
if (specifiedMonsters && !negateMonsters) {
this.plugin.log(Level.FINEST, "Removing an entity because I was told to remove all monsters: " + e);

View File

@ -0,0 +1,107 @@
package com.onarandombox.MultiverseCore.test;
import com.onarandombox.MultiverseCore.MultiverseCore;
import com.onarandombox.MultiverseCore.api.MVWorldManager;
import com.onarandombox.MultiverseCore.api.MultiverseWorld;
import com.onarandombox.MultiverseCore.listeners.MVWeatherListener;
import com.onarandombox.MultiverseCore.test.utils.TestInstanceCreator;
import com.onarandombox.MultiverseCore.utils.WorldManager;
import org.bukkit.ChatColor;
import org.bukkit.Difficulty;
import org.bukkit.GameMode;
import org.bukkit.Location;
import org.bukkit.World;
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.Test;
import org.junit.runner.RunWith;
import org.mockito.internal.verification.VerificationModeFactory;
import org.mockito.stubbing.Answer;
import org.powermock.api.mockito.PowerMockito;
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.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.mockito.Matchers.any;
import static org.mockito.Matchers.anyString;
import static org.mockito.Mockito.*;
import static org.mockito.Mockito.never;
import static org.mockito.Mockito.verify;
@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
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"));
// TODO: Uncomment once this is fixed!!!
//assertTrue(worldsSection.getKeys(false).contains("'fish.world'"));
// Worlds with .s are a special case, verify that they work.
}
}