diff --git a/src/main/java/net/minecraft/server/World.java b/src/main/java/net/minecraft/server/World.java index be0b8e221a..844b44719e 100644 --- a/src/main/java/net/minecraft/server/World.java +++ b/src/main/java/net/minecraft/server/World.java @@ -136,6 +136,8 @@ public class World implements IBlockAccess { flag = true; } + // Craftbukkit start + this.q = (WorldProvider) object; this.q.a(this); this.G = this.a(this.t); diff --git a/src/main/java/org/bukkit/craftbukkit/CraftServer.java b/src/main/java/org/bukkit/craftbukkit/CraftServer.java index 4c4ee29f4f..26e083e502 100644 --- a/src/main/java/org/bukkit/craftbukkit/CraftServer.java +++ b/src/main/java/org/bukkit/craftbukkit/CraftServer.java @@ -4,7 +4,9 @@ import org.bukkit.command.*; import org.bukkit.entity.Player; import java.io.File; import java.util.ArrayList; +import java.util.HashMap; import java.util.List; +import java.util.Map; import java.util.logging.Level; import java.util.logging.Logger; import net.minecraft.server.EntityPlayer; @@ -30,6 +32,7 @@ public final class CraftServer implements Server { private final CommandMap commandMap = new SimpleCommandMap(this); protected final MinecraftServer console; protected final ServerConfigurationManager server; + private final Map worlds = new HashMap(); public CraftServer(MinecraftServer console, ServerConfigurationManager server) { this.console = console; @@ -155,15 +158,7 @@ public final class CraftServer implements Server { } public List getWorlds() { - List worlds = new ArrayList(); - - synchronized (console.worlds) { - for (WorldServer world : console.worlds) { - worlds.add(world.getWorld()); - } - } - - return worlds; + return new ArrayList(worlds.values()); } public ServerConfigurationManager getHandle() { @@ -203,6 +198,11 @@ public final class CraftServer implements Server { public World createWorld(String name, World.Environment environment) { File folder = new File(name); + World world = getWorld(name); + + if (world != null) { + return world; + } if ((folder.exists()) && (!folder.isDirectory())) { throw new IllegalArgumentException("File exists with the name '" + name + "' and isn't a folder"); @@ -248,4 +248,12 @@ public final class CraftServer implements Server { public MinecraftServer getServer() { return console; } + + public World getWorld(String name) { + return worlds.get(name.toLowerCase()); + } + + protected void addWorld(World world) { + worlds.put(world.getName().toLowerCase(), world); + } } diff --git a/src/main/java/org/bukkit/craftbukkit/CraftWorld.java b/src/main/java/org/bukkit/craftbukkit/CraftWorld.java index 7be39debb6..2e90063e38 100644 --- a/src/main/java/org/bukkit/craftbukkit/CraftWorld.java +++ b/src/main/java/org/bukkit/craftbukkit/CraftWorld.java @@ -25,17 +25,21 @@ import org.bukkit.World; public class CraftWorld implements World { private final WorldServer world; private final Environment environment; + private final CraftServer server; private static final Random rand = new Random(); public CraftWorld(WorldServer world) { this.world = world; + this.server = world.getServer(); if (world.q instanceof WorldProviderHell) { environment = Environment.NETHER; } else { environment = Environment.NORMAL; } + + server.addWorld(this); } public Block getBlockAt(int x, int y, int z) {