summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDinnerbone <dinnerbone@dinnerbone.com>2011-02-08 12:03:36 +0000
committerDinnerbone <dinnerbone@dinnerbone.com>2011-02-08 12:03:36 +0000
commit6751433a8e106bfb4e1c6ab679f9cefc43ea8cdb (patch)
treef7d48fc7def15a2513f175f4f27fca9317ae3daa
parent50e42496e3ccc3ad52d2ef81b7028875c30985dd (diff)
downloadcraftbukkit-6751433a8e106bfb4e1c6ab679f9cefc43ea8cdb.tar
craftbukkit-6751433a8e106bfb4e1c6ab679f9cefc43ea8cdb.tar.gz
craftbukkit-6751433a8e106bfb4e1c6ab679f9cefc43ea8cdb.tar.lz
craftbukkit-6751433a8e106bfb4e1c6ab679f9cefc43ea8cdb.tar.xz
craftbukkit-6751433a8e106bfb4e1c6ab679f9cefc43ea8cdb.zip
Implemented new Server methods (getWorld + changes to createWorld)
-rw-r--r--src/main/java/net/minecraft/server/World.java2
-rw-r--r--src/main/java/org/bukkit/craftbukkit/CraftServer.java26
-rw-r--r--src/main/java/org/bukkit/craftbukkit/CraftWorld.java4
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<String, World> worlds = new HashMap<String, World>();
public CraftServer(MinecraftServer console, ServerConfigurationManager server) {
this.console = console;
@@ -155,15 +158,7 @@ public final class CraftServer implements Server {
}
public List<World> getWorlds() {
- List<World> worlds = new ArrayList<World>();
-
- synchronized (console.worlds) {
- for (WorldServer world : console.worlds) {
- worlds.add(world.getWorld());
- }
- }
-
- return worlds;
+ return new ArrayList<World>(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) {