Fix purging removing the player entity
...and lots of other bad stuff...
This commit is contained in:
parent
bdd5e8bd91
commit
d84f930a54
4
pom.xml
4
pom.xml
|
@ -180,7 +180,9 @@
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.bukkit</groupId>
|
<groupId>org.bukkit</groupId>
|
||||||
<artifactId>bukkit</artifactId>
|
<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>
|
<type>jar</type>
|
||||||
<scope>compile</scope>
|
<scope>compile</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
|
@ -566,8 +566,8 @@ public interface MultiverseWorld {
|
||||||
String getTime();
|
String getTime();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets the type of this world. As of 1.1-R1 this will be:
|
* Gets the type of this world. As of 1.2 this will be:
|
||||||
* FLAT or NORMAL
|
* FLAT, NORMAL or VERSION_1_1
|
||||||
* <p>
|
* <p>
|
||||||
* This is *not* the generator.
|
* This is *not* the generator.
|
||||||
*
|
*
|
||||||
|
|
|
@ -53,8 +53,8 @@ public class EnvironmentCommand extends MultiverseCommand {
|
||||||
*/
|
*/
|
||||||
public static void showWorldTypes(CommandSender sender) {
|
public static void showWorldTypes(CommandSender sender) {
|
||||||
sender.sendMessage(ChatColor.YELLOW + "Valid World Types are:");
|
sender.sendMessage(ChatColor.YELLOW + "Valid World Types are:");
|
||||||
sender.sendMessage(String.format("%sNORMAL %sor %sFLAT",
|
sender.sendMessage(String.format("%sNORMAL%,s %sFLAT %sor %sVERSION_1_1",
|
||||||
ChatColor.GREEN, ChatColor.WHITE, ChatColor.AQUA));
|
ChatColor.GREEN, ChatColor.WHITE, ChatColor.AQUA, ChatColor.WHITE, ChatColor.GOLD));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -15,6 +15,10 @@ import org.bukkit.World;
|
||||||
import org.bukkit.command.CommandSender;
|
import org.bukkit.command.CommandSender;
|
||||||
import org.bukkit.entity.Animals;
|
import org.bukkit.entity.Animals;
|
||||||
import org.bukkit.entity.Entity;
|
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 org.bukkit.entity.Squid;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
@ -76,7 +80,7 @@ public class SimpleWorldPurger implements WorldPurger {
|
||||||
boolean specifiedAnimals = thingsToKill.contains("ANIMALS") || specifiedAll;
|
boolean specifiedAnimals = thingsToKill.contains("ANIMALS") || specifiedAll;
|
||||||
boolean specifiedMonsters = thingsToKill.contains("MONSTERS") || specifiedAll;
|
boolean specifiedMonsters = thingsToKill.contains("MONSTERS") || specifiedAll;
|
||||||
for (Entity e : world.getEntities()) {
|
for (Entity e : world.getEntities()) {
|
||||||
boolean negate;
|
boolean negate = false;
|
||||||
boolean specified = false;
|
boolean specified = false;
|
||||||
if (e instanceof Squid || e instanceof Animals) {
|
if (e instanceof Squid || e instanceof Animals) {
|
||||||
// it's an animal
|
// it's an animal
|
||||||
|
@ -89,7 +93,7 @@ public class SimpleWorldPurger implements WorldPurger {
|
||||||
if (specifiedAnimals)
|
if (specifiedAnimals)
|
||||||
specified = true;
|
specified = true;
|
||||||
negate = negateAnimals;
|
negate = negateAnimals;
|
||||||
} else {
|
} else if (e instanceof Monster || e instanceof Ghast || e instanceof Slime) {
|
||||||
// it's a monster
|
// it's a monster
|
||||||
if (specifiedMonsters && !negateMonsters) {
|
if (specifiedMonsters && !negateMonsters) {
|
||||||
this.plugin.log(Level.FINEST, "Removing an entity because I was told to remove all monsters: " + e);
|
this.plugin.log(Level.FINEST, "Removing an entity because I was told to remove all monsters: " + e);
|
||||||
|
|
|
@ -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.
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue