From 1784e42d5fe0ac465cda0fa5629ba06d16b90551 Mon Sep 17 00:00:00 2001 From: Dinnerbone Date: Thu, 26 May 2011 22:15:27 +0100 Subject: [PATCH] Fixed a bunch of multiworld issues (entity tracking etc) --- .../net/minecraft/server/MinecraftServer.java | 12 ++++++-- .../server/ServerConfigurationManager.java | 29 ++++++++++++------- .../net/minecraft/server/WorldServer.java | 2 ++ .../org/bukkit/craftbukkit/CraftServer.java | 7 +++-- .../craftbukkit/entity/CraftPlayer.java | 4 ++- 5 files changed, 37 insertions(+), 17 deletions(-) diff --git a/src/main/java/net/minecraft/server/MinecraftServer.java b/src/main/java/net/minecraft/server/MinecraftServer.java index aa2573e351..b36226b022 100644 --- a/src/main/java/net/minecraft/server/MinecraftServer.java +++ b/src/main/java/net/minecraft/server/MinecraftServer.java @@ -51,7 +51,7 @@ public class MinecraftServer implements Runnable, ICommandListener { // CraftBukkit start public int spawnProtection; - public List worlds = new ArrayList(); // TODO - REPLACE ABOVE + public List worlds = new ArrayList(); public CraftServer server; public OptionSet options; public ColouredConsoleSender console; @@ -461,7 +461,15 @@ public class MinecraftServer implements Runnable, ICommandListener { } public WorldServer a(int i) { - return i == -1 ? this.worlds.get(1) : this.worlds.get(0); // Craftbukkit + // Craftbukkit start + for (WorldServer world : worlds) { + if (world.dimension == i) { + return world; + } + } + + return worlds.get(0); + // Craftbukkit end } public EntityTracker b(int i) { diff --git a/src/main/java/net/minecraft/server/ServerConfigurationManager.java b/src/main/java/net/minecraft/server/ServerConfigurationManager.java index 4f433aa6e8..6fe2cbd8db 100644 --- a/src/main/java/net/minecraft/server/ServerConfigurationManager.java +++ b/src/main/java/net/minecraft/server/ServerConfigurationManager.java @@ -29,7 +29,7 @@ public class ServerConfigurationManager { public static Logger a = Logger.getLogger("Minecraft"); public List players = new ArrayList(); public MinecraftServer server; // CraftBukkit - private -> public - private PlayerManager[] d = new PlayerManager[2]; + // private PlayerManager[] d = new PlayerManager[2]; // Craftbukkit - removed public int maxPlayers; // CraftBukkit - private -> public private Set banByName = new HashSet(); private Set banByIP = new HashSet(); @@ -58,8 +58,7 @@ public class ServerConfigurationManager { this.m = minecraftserver.a("white-list.txt"); int i = minecraftserver.propertyManager.getInt("view-distance", 10); - this.d[0] = new PlayerManager(minecraftserver, 0, i); - this.d[1] = new PlayerManager(minecraftserver, -1, i); + // Craftbukkit - removed playermanagers this.maxPlayers = minecraftserver.propertyManager.getInt("max-players", 20); this.o = minecraftserver.propertyManager.getBoolean("white-list", false); this.g(); @@ -78,8 +77,7 @@ public class ServerConfigurationManager { } public void a(EntityPlayer entityplayer) { - this.d[0].removePlayer(entityplayer); - this.d[1].removePlayer(entityplayer); + // Craftbukkit - removed playermanagers this.a(entityplayer.dimension).addPlayer(entityplayer); WorldServer worldserver = this.server.a(entityplayer.dimension); @@ -87,11 +85,17 @@ public class ServerConfigurationManager { } public int a() { - return this.d[0].c(); + // Craftbukkit start + if (this.server.worlds.size() == 0) { + return this.server.propertyManager.getInt("view-distance", 10) * 16 - 16; + } else { + return this.server.worlds.get(0).manager.c(); + } + // Craftbukkit end } private PlayerManager a(int i) { - return i == -1 ? this.d[1] : this.d[0]; + return server.a(i).manager; // Craftbukkit } public void b(EntityPlayer entityplayer) { @@ -241,7 +245,7 @@ public class ServerConfigurationManager { entityplayer1.setPosition(entityplayer1.locX, entityplayer1.locY + 1.0D, entityplayer1.locZ); } - entityplayer1.netServerHandler.sendPacket(new Packet9Respawn((byte) entityplayer1.dimension)); + entityplayer1.netServerHandler.sendPacket(new Packet9Respawn((byte) ((WorldServer)entityplayer1.world).getWorld().getEnvironment().getId())); entityplayer1.netServerHandler.a(entityplayer1.locX, entityplayer1.locY, entityplayer1.locZ, entityplayer1.yaw, entityplayer1.pitch); this.a(entityplayer1, worldserver); this.a(entityplayer1.dimension).addPlayer(entityplayer1); @@ -266,7 +270,8 @@ public class ServerConfigurationManager { entityplayer.dimension = b0; WorldServer worldserver1 = this.server.a(entityplayer.dimension); - entityplayer.netServerHandler.sendPacket(new Packet9Respawn((byte) entityplayer.dimension)); + // Craftbukkit + entityplayer.netServerHandler.sendPacket(new Packet9Respawn((byte) ((WorldServer)entityplayer.world).getWorld().getEnvironment().getId())); worldserver.removeEntity(entityplayer); entityplayer.dead = false; double d0 = entityplayer.locX; @@ -306,9 +311,11 @@ public class ServerConfigurationManager { } public void b() { - for (int i = 0; i < this.d.length; ++i) { - this.d[i].flush(); + // Craftbukkit start + for (int i = 0; i < this.server.worlds.size(); ++i) { + this.server.worlds.get(i).manager.flush(); } + // Craftbukkit end } public void flagDirty(int i, int j, int k, int l) { diff --git a/src/main/java/net/minecraft/server/WorldServer.java b/src/main/java/net/minecraft/server/WorldServer.java index 5388ee07e7..95b2805a9b 100644 --- a/src/main/java/net/minecraft/server/WorldServer.java +++ b/src/main/java/net/minecraft/server/WorldServer.java @@ -27,12 +27,14 @@ public class WorldServer extends World implements BlockChangeDelegate { this.cserver = minecraftserver.server; this.world = new CraftWorld(this); this.pvpMode = minecraftserver.pvpMode; + this.manager = new PlayerManager(minecraftserver, dimension, minecraftserver.propertyManager.getInt("view-distance", 10)); } public final int dimension; private final CraftWorld world; private final CraftServer cserver; public EntityTracker tracker; + public PlayerManager manager; public CraftWorld getWorld() { return world; diff --git a/src/main/java/org/bukkit/craftbukkit/CraftServer.java b/src/main/java/org/bukkit/craftbukkit/CraftServer.java index 7d0a9fc41c..18f86c7034 100644 --- a/src/main/java/org/bukkit/craftbukkit/CraftServer.java +++ b/src/main/java/org/bukkit/craftbukkit/CraftServer.java @@ -287,7 +287,7 @@ public final class CraftServer implements Server { } // See if the server can process this command - return console.consoleCommandHandler.handle(new ServerCommand(commandLine, new ServerCommandListener(sender))); + return console.consoleCommandHandler.handle(new ServerCommand(commandLine, (ICommandListener)new ServerCommandListener(sender))); } public void reload() { @@ -366,10 +366,11 @@ public final class CraftServer implements Server { converter.convert(name, new ConvertProgressUpdater(console)); } - WorldServer internal = new WorldServer(console, new ServerNBTManager(new File("."), name, true), name, environment.getId(), seed); + int dimension = environment.getId() + 200 + console.worlds.size(); + WorldServer internal = new WorldServer(console, new ServerNBTManager(new File("."), name, true), name, dimension, seed); internal.z = console.worlds.get(0).z; - internal.tracker = new EntityTracker(console, environment.getId()); + internal.tracker = new EntityTracker(console, dimension); internal.addIWorldAccess((IWorldAccess)new WorldManager(console, internal)); internal.spawnMonsters = 1; internal.setSpawnFlags(true, true); diff --git a/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java b/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java index 371b9ee4ba..ce9d1a19e4 100644 --- a/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java +++ b/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java @@ -173,11 +173,13 @@ public class CraftPlayer extends CraftHumanEntity implements Player { if (oldWorld != newWorld) { entity.dimension = newWorld.dimension; - entity.netServerHandler.sendPacket(new Packet9Respawn((byte) entity.dimension)); + entity.netServerHandler.sendPacket(new Packet9Respawn((byte) location.getWorld().getEnvironment().getId())); oldWorld.removeEntity(entity); entity.dead = false; + entity.setPositionRotation(location.getX(), location.getY(), location.getZ(), location.getYaw(), location.getPitch()); if (entity.Q()) { + oldWorld.entityJoinedWorld(entity, false); newWorld.addEntity(entity); entity.setPositionRotation(location.getX(), location.getY(), location.getZ(), location.getYaw(), location.getPitch()); newWorld.entityJoinedWorld(entity, false);