Now uses world UUID to retrieve world reference.

This commit is contained in:
Jeremy Wood 2012-11-14 14:24:10 -05:00
parent b11d911e4a
commit 4780f87278
4 changed files with 24 additions and 5 deletions

View File

@ -496,10 +496,7 @@ public class MVWorld implements MultiverseWorld {
*/ */
@Override @Override
public World getCBWorld() { public World getCBWorld() {
if (name == null) { final World world = plugin.getServer().getWorld(worldUID);
return null;
}
final World world = plugin.getServer().getWorld(name);
if (world == null) { if (world == null) {
Logging.severe("Lost reference to bukkit world '%s'", name); Logging.severe("Lost reference to bukkit world '%s'", name);
} }

View File

@ -299,7 +299,6 @@ public class TestWorldProperties {
// change a value here // change a value here
FileConfiguration config = YamlConfiguration.loadConfiguration(new File(core.getDataFolder(), "worlds.yml")); FileConfiguration config = YamlConfiguration.loadConfiguration(new File(core.getDataFolder(), "worlds.yml"));
WorldProperties worldObj = (WorldProperties) config.get("worlds.world"); WorldProperties worldObj = (WorldProperties) config.get("worlds.world");
System.out.println(worldObj.setColor("GREEN"));
assertTrue(worldObj.setColor("GREEN")); assertTrue(worldObj.setColor("GREEN"));
config.set("worlds.world", worldObj); config.set("worlds.world", worldObj);
config.save(new File(core.getDataFolder(), "worlds.yml")); config.save(new File(core.getDataFolder(), "worlds.yml"));

View File

@ -22,6 +22,7 @@ import java.util.ArrayList;
import java.util.HashMap; import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.UUID;
import java.util.WeakHashMap; import java.util.WeakHashMap;
import static org.mockito.Mockito.*; import static org.mockito.Mockito.*;
@ -29,6 +30,7 @@ import static org.mockito.Mockito.*;
public class MockWorldFactory { public class MockWorldFactory {
private static final Map<String, World> createdWorlds = new HashMap<String, World>(); private static final Map<String, World> createdWorlds = new HashMap<String, World>();
private static final Map<UUID, World> worldUIDS = new HashMap<UUID, World>();
private static final Map<World, Boolean> pvpStates = new WeakHashMap<World, Boolean>(); private static final Map<World, Boolean> pvpStates = new WeakHashMap<World, Boolean>();
private static final Map<World, Boolean> keepSpawnInMemoryStates = new WeakHashMap<World, Boolean>(); private static final Map<World, Boolean> keepSpawnInMemoryStates = new WeakHashMap<World, Boolean>();
@ -39,6 +41,7 @@ public class MockWorldFactory {
private static void registerWorld(World world) { private static void registerWorld(World world) {
createdWorlds.put(world.getName(), world); createdWorlds.put(world.getName(), world);
worldUIDS.put(world.getUID(), world);
new File(TestInstanceCreator.worldsDirectory, world.getName()).mkdir(); new File(TestInstanceCreator.worldsDirectory, world.getName()).mkdir();
} }
@ -132,6 +135,7 @@ public class MockWorldFactory {
return mockBlock; return mockBlock;
} }
}); });
when(mockWorld.getUID()).thenReturn(UUID.randomUUID());
return mockWorld; return mockWorld;
} }
@ -203,6 +207,10 @@ public class MockWorldFactory {
return createdWorlds.get(name); return createdWorlds.get(name);
} }
public static World getWorld(UUID worldUID) {
return worldUIDS.get(worldUID);
}
public static List<World> getWorlds() { public static List<World> getWorlds() {
// we have to invert the order! // we have to invert the order!
ArrayList<World> myList = new ArrayList<World>(createdWorlds.values()); ArrayList<World> myList = new ArrayList<World>(createdWorlds.values());
@ -217,5 +225,6 @@ public class MockWorldFactory {
for (String name : createdWorlds.keySet()) for (String name : createdWorlds.keySet())
new File(TestInstanceCreator.worldsDirectory, name).delete(); new File(TestInstanceCreator.worldsDirectory, name).delete();
createdWorlds.clear(); createdWorlds.clear();
worldUIDS.clear();
} }
} }

View File

@ -36,6 +36,7 @@ import java.io.File;
import java.lang.reflect.Field; import java.lang.reflect.Field;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.UUID;
import java.util.logging.Level; import java.util.logging.Level;
import java.util.logging.Logger; import java.util.logging.Logger;
@ -120,6 +121,19 @@ public class TestInstanceCreator {
} }
}); });
when(mockServer.getWorld(any(UUID.class))).thenAnswer(new Answer<World>() {
@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<List<World>>() { when(mockServer.getWorlds()).thenAnswer(new Answer<List<World>>() {
@Override @Override
public List<World> answer(InvocationOnMock invocation) throws Throwable { public List<World> answer(InvocationOnMock invocation) throws Throwable {