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
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);
}

View File

@ -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"));

View File

@ -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<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> keepSpawnInMemoryStates = new WeakHashMap<World, Boolean>();
@ -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<World> getWorlds() {
// we have to invert the order!
ArrayList<World> myList = new ArrayList<World>(createdWorlds.values());
@ -217,5 +225,6 @@ public class MockWorldFactory {
for (String name : createdWorlds.keySet())
new File(TestInstanceCreator.worldsDirectory, name).delete();
createdWorlds.clear();
worldUIDS.clear();
}
}

View File

@ -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<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>>() {
@Override
public List<World> answer(InvocationOnMock invocation) throws Throwable {