From 6751433a8e106bfb4e1c6ab679f9cefc43ea8cdb Mon Sep 17 00:00:00 2001 From: Dinnerbone Date: Tue, 8 Feb 2011 12:03:36 +0000 Subject: Implemented new Server methods (getWorld + changes to createWorld) --- src/main/java/net/minecraft/server/World.java | 2 ++ .../java/org/bukkit/craftbukkit/CraftServer.java | 26 ++++++++++++++-------- .../java/org/bukkit/craftbukkit/CraftWorld.java | 4 ++++ 3 files changed, 23 insertions(+), 9 deletions(-) diff --git a/src/main/java/net/minecraft/server/World.java b/src/main/java/net/minecraft/server/World.java index be0b8e22..844b4471 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 4c4ee29f..26e083e5 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 7be39deb..2e90063e 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) { -- cgit v1.2.3