diff --git a/src/main/java/com/onarandombox/MultiverseCore/MVWorld.java b/src/main/java/com/onarandombox/MultiverseCore/MVWorld.java index 165fab5f..ab0eb509 100644 --- a/src/main/java/com/onarandombox/MultiverseCore/MVWorld.java +++ b/src/main/java/com/onarandombox/MultiverseCore/MVWorld.java @@ -496,10 +496,7 @@ public class MVWorld implements MultiverseWorld { */ @Override public World getCBWorld() { - if (name == null) { - return null; - } - final World world = plugin.getServer().getWorld(name); + final World world = plugin.getServer().getWorld(worldUID); if (world == null) { Logging.severe("Lost reference to bukkit world '%s'", name); } diff --git a/src/test/java/com/onarandombox/MultiverseCore/TestWorldProperties.java b/src/test/java/com/onarandombox/MultiverseCore/TestWorldProperties.java index ffb2c007..bf53b71d 100644 --- a/src/test/java/com/onarandombox/MultiverseCore/TestWorldProperties.java +++ b/src/test/java/com/onarandombox/MultiverseCore/TestWorldProperties.java @@ -299,7 +299,6 @@ public class TestWorldProperties { // change a value here FileConfiguration config = YamlConfiguration.loadConfiguration(new File(core.getDataFolder(), "worlds.yml")); WorldProperties worldObj = (WorldProperties) config.get("worlds.world"); - System.out.println(worldObj.setColor("GREEN")); assertTrue(worldObj.setColor("GREEN")); config.set("worlds.world", worldObj); config.save(new File(core.getDataFolder(), "worlds.yml")); diff --git a/src/test/java/com/onarandombox/MultiverseCore/utils/MockWorldFactory.java b/src/test/java/com/onarandombox/MultiverseCore/utils/MockWorldFactory.java index 41e34614..fb2223cc 100644 --- a/src/test/java/com/onarandombox/MultiverseCore/utils/MockWorldFactory.java +++ b/src/test/java/com/onarandombox/MultiverseCore/utils/MockWorldFactory.java @@ -22,6 +22,7 @@ import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; +import java.util.UUID; import java.util.WeakHashMap; import static org.mockito.Mockito.*; @@ -29,6 +30,7 @@ import static org.mockito.Mockito.*; public class MockWorldFactory { private static final Map createdWorlds = new HashMap(); + private static final Map worldUIDS = new HashMap(); private static final Map pvpStates = new WeakHashMap(); private static final Map keepSpawnInMemoryStates = new WeakHashMap(); @@ -39,6 +41,7 @@ public class MockWorldFactory { private static void registerWorld(World world) { createdWorlds.put(world.getName(), world); + worldUIDS.put(world.getUID(), world); new File(TestInstanceCreator.worldsDirectory, world.getName()).mkdir(); } @@ -132,6 +135,7 @@ public class MockWorldFactory { return mockBlock; } }); + when(mockWorld.getUID()).thenReturn(UUID.randomUUID()); return mockWorld; } @@ -203,6 +207,10 @@ public class MockWorldFactory { return createdWorlds.get(name); } + public static World getWorld(UUID worldUID) { + return worldUIDS.get(worldUID); + } + public static List getWorlds() { // we have to invert the order! ArrayList myList = new ArrayList(createdWorlds.values()); @@ -217,5 +225,6 @@ public class MockWorldFactory { for (String name : createdWorlds.keySet()) new File(TestInstanceCreator.worldsDirectory, name).delete(); createdWorlds.clear(); + worldUIDS.clear(); } } diff --git a/src/test/java/com/onarandombox/MultiverseCore/utils/TestInstanceCreator.java b/src/test/java/com/onarandombox/MultiverseCore/utils/TestInstanceCreator.java index a125d298..c6ba41e0 100644 --- a/src/test/java/com/onarandombox/MultiverseCore/utils/TestInstanceCreator.java +++ b/src/test/java/com/onarandombox/MultiverseCore/utils/TestInstanceCreator.java @@ -36,6 +36,7 @@ import java.io.File; import java.lang.reflect.Field; import java.util.ArrayList; import java.util.List; +import java.util.UUID; import java.util.logging.Level; import java.util.logging.Logger; @@ -120,6 +121,19 @@ public class TestInstanceCreator { } }); + when(mockServer.getWorld(any(UUID.class))).thenAnswer(new Answer() { + @Override + public World answer(InvocationOnMock invocation) throws Throwable { + UUID arg; + try { + arg = (UUID) invocation.getArguments()[0]; + } catch (Exception e) { + return null; + } + return MockWorldFactory.getWorld(arg); + } + }); + when(mockServer.getWorlds()).thenAnswer(new Answer>() { @Override public List answer(InvocationOnMock invocation) throws Throwable {