Moved some craftbukkit stuff down from WorldServer to World; should fix a few NPEs during generation, and saves on a lot of casting

Dieser Commit ist enthalten in:
Dinnerbone 2011-06-17 03:06:45 +01:00
Ursprung a818669be0
Commit 7e22faf9d6
4 geänderte Dateien mit 61 neuen und 64 gelöschten Zeilen

Datei anzeigen

@ -9,7 +9,9 @@ import java.util.Set;
import java.util.TreeSet; import java.util.TreeSet;
// CraftBukkit start // CraftBukkit start
import org.bukkit.Bukkit;
import org.bukkit.Location; import org.bukkit.Location;
import org.bukkit.World.Environment;
import org.bukkit.generator.ChunkGenerator; import org.bukkit.generator.ChunkGenerator;
import org.bukkit.craftbukkit.CraftServer; import org.bukkit.craftbukkit.CraftServer;
import org.bukkit.craftbukkit.CraftWorld; import org.bukkit.craftbukkit.CraftWorld;
@ -73,6 +75,7 @@ public class World implements IBlockAccess {
} }
// CraftBukkit start // CraftBukkit start
private final CraftWorld world;
public boolean pvpMode; public boolean pvpMode;
public ChunkGenerator generator; public ChunkGenerator generator;
Chunk lastChunkAccessed; Chunk lastChunkAccessed;
@ -88,9 +91,18 @@ public class World implements IBlockAccess {
} }
} }
public CraftWorld getWorld() {
return world;
}
public CraftServer getServer() {
return (CraftServer)Bukkit.getServer();
}
// CraftBukkit - changed signature // CraftBukkit - changed signature
public World(IDataManager idatamanager, String s, long i, WorldProvider worldprovider, ChunkGenerator gen) { public World(IDataManager idatamanager, String s, long i, WorldProvider worldprovider, ChunkGenerator gen, Environment env) {
this.generator = gen; this.generator = gen;
this.world = new CraftWorld((WorldServer)this, gen, env);
// CraftBukkit end // CraftBukkit end
this.O = this.random.nextInt(12000); this.O = this.random.nextInt(12000);
@ -125,6 +137,8 @@ public class World implements IBlockAccess {
this.g(); this.g();
this.x(); this.x();
getServer().addWorld(world);// Craftbukkit
} }
protected IChunkProvider b() { protected IChunkProvider b() {
@ -421,7 +435,7 @@ public class World implements IBlockAccess {
CraftWorld world = ((WorldServer) this).getWorld(); CraftWorld world = ((WorldServer) this).getWorld();
if (world != null) { if (world != null) {
BlockPhysicsEvent event = new BlockPhysicsEvent(world.getBlockAt(i, j, k), l); BlockPhysicsEvent event = new BlockPhysicsEvent(world.getBlockAt(i, j, k), l);
((WorldServer) this).getServer().getPluginManager().callEvent(event); getServer().getPluginManager().callEvent(event);
if (event.isCancelled()) { if (event.isCancelled()) {
return; return;
@ -1593,7 +1607,7 @@ public class World implements IBlockAccess {
} }
// CraftBukkit start - Only call spawner if we have players online and the world allows for mobs or animals // CraftBukkit start - Only call spawner if we have players online and the world allows for mobs or animals
if ((this.allowMonsters || this.allowAnimals) && (this instanceof WorldServer && ((WorldServer) this).getServer().getHandle().players.size() > 0)) { if ((this.allowMonsters || this.allowAnimals) && (this instanceof WorldServer && getServer().getHandle().players.size() > 0)) {
SpawnerCreature.spawnEntities(this, this.allowMonsters, this.allowAnimals); SpawnerCreature.spawnEntities(this, this.allowMonsters, this.allowAnimals);
} }
// CraftBukkit end // CraftBukkit end
@ -1647,7 +1661,7 @@ public class World implements IBlockAccess {
this.worldData.b(i); this.worldData.b(i);
if (i <= 0) { if (i <= 0) {
// CraftBukkit start // CraftBukkit start
CraftServer server = ((WorldServer) this).getServer(); CraftServer server = getServer();
ThunderChangeEvent thunder = new ThunderChangeEvent(((WorldServer) this).getWorld(), !this.worldData.j()); ThunderChangeEvent thunder = new ThunderChangeEvent(((WorldServer) this).getWorld(), !this.worldData.j());
server.getPluginManager().callEvent(thunder); server.getPluginManager().callEvent(thunder);
@ -1671,7 +1685,7 @@ public class World implements IBlockAccess {
this.worldData.c(j); this.worldData.c(j);
if (j <= 0) { if (j <= 0) {
// CraftBukkit start // CraftBukkit start
CraftServer server = ((WorldServer) this).getServer(); CraftServer server = getServer();
WeatherChangeEvent weather = new WeatherChangeEvent(((WorldServer) this).getWorld(), !this.worldData.l()); WeatherChangeEvent weather = new WeatherChangeEvent(((WorldServer) this).getWorld(), !this.worldData.l());
server.getPluginManager().callEvent(weather); server.getPluginManager().callEvent(weather);
@ -1716,7 +1730,7 @@ public class World implements IBlockAccess {
private void y() { private void y() {
// CraftBukkit start // CraftBukkit start
CraftServer server = ((WorldServer) this).getServer(); CraftServer server = getServer();
WeatherChangeEvent weather = new WeatherChangeEvent(((WorldServer) this).getWorld(), false); WeatherChangeEvent weather = new WeatherChangeEvent(((WorldServer) this).getWorld(), false);
server.getPluginManager().callEvent(weather); server.getPluginManager().callEvent(weather);
@ -1818,7 +1832,7 @@ public class World implements IBlockAccess {
// CraftBukkit start // CraftBukkit start
SnowFormEvent snow = new SnowFormEvent(((WorldServer) this).getWorld().getBlockAt(l + i, k1, j1 + j)); SnowFormEvent snow = new SnowFormEvent(((WorldServer) this).getWorld().getBlockAt(l + i, k1, j1 + j));
((WorldServer) this).getServer().getPluginManager().callEvent(snow); getServer().getPluginManager().callEvent(snow);
if (!snow.isCancelled()) { if (!snow.isCancelled()) {
this.setTypeId(l + i, k1, j1 + j, snow.getMaterial().getId()); this.setTypeId(l + i, k1, j1 + j, snow.getMaterial().getId());
this.setData(l + i, k1, j1 + j, snow.getData()); this.setData(l + i, k1, j1 + j, snow.getData());
@ -1980,7 +1994,7 @@ public class World implements IBlockAccess {
// CraftBukkit start // CraftBukkit start
BlockCanBuildEvent event = new BlockCanBuildEvent(((WorldServer) this).getWorld().getBlockAt(j, k, l), i, defaultReturn); BlockCanBuildEvent event = new BlockCanBuildEvent(((WorldServer) this).getWorld().getBlockAt(j, k, l), i, defaultReturn);
((WorldServer) this).getServer().getPluginManager().callEvent(event); getServer().getPluginManager().callEvent(event);
return event.isBuildable(); return event.isBuildable();
// CraftBukkit end // CraftBukkit end

Datei anzeigen

@ -5,9 +5,8 @@ import java.util.List;
// CraftBukkit start // CraftBukkit start
import org.bukkit.BlockChangeDelegate; import org.bukkit.BlockChangeDelegate;
import org.bukkit.World.Environment;
import org.bukkit.generator.ChunkGenerator; import org.bukkit.generator.ChunkGenerator;
import org.bukkit.craftbukkit.CraftServer;
import org.bukkit.craftbukkit.CraftWorld;
import org.bukkit.craftbukkit.generator.CustomChunkGenerator; import org.bukkit.craftbukkit.generator.CustomChunkGenerator;
import org.bukkit.craftbukkit.generator.InternalChunkGenerator; import org.bukkit.craftbukkit.generator.InternalChunkGenerator;
import org.bukkit.craftbukkit.generator.NetherChunkGenerator; import org.bukkit.craftbukkit.generator.NetherChunkGenerator;
@ -25,30 +24,18 @@ public class WorldServer extends World implements BlockChangeDelegate {
private EntityList G = new EntityList(); private EntityList G = new EntityList();
// CraftBukkit start - change signature // CraftBukkit start - change signature
public WorldServer(MinecraftServer minecraftserver, IDataManager idatamanager, String s, int i, long j, org.bukkit.World.Environment env, ChunkGenerator gen) { public WorldServer(MinecraftServer minecraftserver, IDataManager idatamanager, String s, int i, long j, Environment env, ChunkGenerator gen) {
super(idatamanager, s, j, WorldProvider.a(env.getId()), gen); super(idatamanager, s, j, WorldProvider.a(env.getId()), gen, env);
this.server = minecraftserver; this.server = minecraftserver;
this.dimension = i; this.dimension = i;
this.cserver = minecraftserver.server;
this.world = new CraftWorld(this, gen);
this.pvpMode = minecraftserver.pvpMode; this.pvpMode = minecraftserver.pvpMode;
this.manager = new PlayerManager(minecraftserver, dimension, minecraftserver.propertyManager.getInt("view-distance", 10)); this.manager = new PlayerManager(minecraftserver, dimension, minecraftserver.propertyManager.getInt("view-distance", 10));
} }
public final int dimension; public final int dimension;
private final CraftWorld world;
private final CraftServer cserver;
public EntityTracker tracker; public EntityTracker tracker;
public PlayerManager manager; public PlayerManager manager;
public CraftWorld getWorld() {
return world;
}
public CraftServer getServer() {
return cserver;
}
// CraftBukkit end // CraftBukkit end
public void entityJoinedWorld(Entity entity, boolean flag) { public void entityJoinedWorld(Entity entity, boolean flag) {
@ -131,8 +118,8 @@ public class WorldServer extends World implements BlockChangeDelegate {
public boolean a(Entity entity) { public boolean a(Entity entity) {
// CraftBukkit start // CraftBukkit start
LightningStrikeEvent lightning = new LightningStrikeEvent((org.bukkit.World) world, (org.bukkit.entity.LightningStrike) entity.getBukkitEntity()); LightningStrikeEvent lightning = new LightningStrikeEvent(getWorld(), (org.bukkit.entity.LightningStrike) entity.getBukkitEntity());
this.cserver.getPluginManager().callEvent(lightning); getServer().getPluginManager().callEvent(lightning);
if (lightning.isCancelled()) { if (lightning.isCancelled()) {
return false; return false;

Datei anzeigen

@ -475,7 +475,7 @@ public final class CraftServer implements Server {
return worlds.get(name.toLowerCase()); return worlds.get(name.toLowerCase());
} }
protected void addWorld(World world) { public void addWorld(World world) {
worlds.put(world.getName().toLowerCase(), world); worlds.put(world.getName().toLowerCase(), world);
} }

Datei anzeigen

@ -21,6 +21,7 @@ import org.bukkit.Chunk;
import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.ItemStack;
import org.bukkit.util.Vector; import org.bukkit.util.Vector;
import org.bukkit.BlockChangeDelegate; import org.bukkit.BlockChangeDelegate;
import org.bukkit.Bukkit;
import org.bukkit.generator.ChunkGenerator; import org.bukkit.generator.ChunkGenerator;
import org.bukkit.Location; import org.bukkit.Location;
import org.bukkit.TreeType; import org.bukkit.TreeType;
@ -30,23 +31,18 @@ import org.bukkit.generator.BlockPopulator;
public class CraftWorld implements World { public class CraftWorld implements World {
private final WorldServer world; private final WorldServer world;
private Environment environment; private Environment environment;
private final CraftServer server; private final CraftServer server = (CraftServer)Bukkit.getServer();
private final ChunkProviderServer provider;
private HashMap<Integer, CraftChunk> unloadedChunks = new HashMap<Integer, CraftChunk>(); private HashMap<Integer, CraftChunk> unloadedChunks = new HashMap<Integer, CraftChunk>();
private final ChunkGenerator generator; private final ChunkGenerator generator;
private final List<BlockPopulator> populators = new ArrayList<BlockPopulator>(); private final List<BlockPopulator> populators = new ArrayList<BlockPopulator>();
private static final Random rand = new Random(); private static final Random rand = new Random();
public CraftWorld(WorldServer world, ChunkGenerator gen) { public CraftWorld(WorldServer world, ChunkGenerator gen, Environment env) {
this.world = world; this.world = world;
this.server = world.getServer();
this.provider = world.chunkProviderServer;
this.generator = gen; this.generator = gen;
environment = Environment.getEnvironment(world.worldProvider.dimension); environment = env;
server.addWorld(this);
} }
public void preserveChunk(CraftChunk chunk) { public void preserveChunk(CraftChunk chunk) {
@ -91,7 +87,7 @@ public class CraftWorld implements World {
} }
public Chunk getChunkAt(int x, int z) { public Chunk getChunkAt(int x, int z) {
return this.provider.getChunkAt(x, z).bukkitChunk; return this.world.chunkProviderServer.getChunkAt(x, z).bukkitChunk;
} }
public Chunk getChunkAt(Block block) { public Chunk getChunkAt(Block block) {
@ -99,11 +95,11 @@ public class CraftWorld implements World {
} }
public boolean isChunkLoaded(int x, int z) { public boolean isChunkLoaded(int x, int z) {
return provider.isChunkLoaded(x, z); return world.chunkProviderServer.isChunkLoaded(x, z);
} }
public Chunk[] getLoadedChunks() { public Chunk[] getLoadedChunks() {
Object[] chunks = provider.chunks.values().toArray(); Object[] chunks = world.chunkProviderServer.chunks.values().toArray();
org.bukkit.Chunk[] craftChunks = new CraftChunk[chunks.length]; org.bukkit.Chunk[] craftChunks = new CraftChunk[chunks.length];
for (int i = 0; i < chunks.length; i++) { for (int i = 0; i < chunks.length; i++) {
@ -135,7 +131,7 @@ public class CraftWorld implements World {
return false; return false;
} }
provider.queueUnload(x, z); world.chunkProviderServer.queueUnload(x, z);
return true; return true;
} }
@ -145,18 +141,18 @@ public class CraftWorld implements World {
return false; return false;
} }
net.minecraft.server.Chunk chunk = provider.getOrCreateChunk(x, z); net.minecraft.server.Chunk chunk = world.chunkProviderServer.getOrCreateChunk(x, z);
if (save) { if (save) {
chunk.removeEntities(); chunk.removeEntities();
provider.saveChunk(chunk); world.chunkProviderServer.saveChunk(chunk);
provider.saveChunkNOP(chunk); world.chunkProviderServer.saveChunkNOP(chunk);
} }
preserveChunk((CraftChunk) chunk.bukkitChunk); preserveChunk((CraftChunk) chunk.bukkitChunk);
provider.unloadQueue.remove(x, z); world.chunkProviderServer.unloadQueue.remove(x, z);
provider.chunks.remove(x, z); world.chunkProviderServer.chunks.remove(x, z);
provider.chunkList.remove(chunk); world.chunkProviderServer.chunkList.remove(chunk);
return true; return true;
} }
@ -164,14 +160,14 @@ public class CraftWorld implements World {
public boolean regenerateChunk(int x, int z) { public boolean regenerateChunk(int x, int z) {
unloadChunk(x, z, false, false); unloadChunk(x, z, false, false);
provider.unloadQueue.remove(x, z); world.chunkProviderServer.unloadQueue.remove(x, z);
net.minecraft.server.Chunk chunk = null; net.minecraft.server.Chunk chunk = null;
if (provider.chunkProvider == null) { if (world.chunkProviderServer.chunkProvider == null) {
chunk = provider.emptyChunk; chunk = world.chunkProviderServer.emptyChunk;
} else { } else {
chunk = provider.chunkProvider.getOrCreateChunk(x, z); chunk = world.chunkProviderServer.chunkProvider.getOrCreateChunk(x, z);
} }
chunkLoadPostProcess(chunk, x, z); chunkLoadPostProcess(chunk, x, z);
@ -208,7 +204,7 @@ public class CraftWorld implements World {
for (Player player : players) { for (Player player : players) {
Location loc = player.getLocation(); Location loc = player.getLocation();
if (loc.getWorld() != provider.world.getWorld()) { if (loc.getWorld() != world.chunkProviderServer.world.getWorld()) {
continue; continue;
} }
@ -225,14 +221,14 @@ public class CraftWorld implements World {
public boolean loadChunk(int x, int z, boolean generate) { public boolean loadChunk(int x, int z, boolean generate) {
if (generate) { if (generate) {
// Use the default variant of loadChunk when generate == true. // Use the default variant of loadChunk when generate == true.
return provider.getChunkAt(x, z) != null; return world.chunkProviderServer.getChunkAt(x, z) != null;
} }
provider.unloadQueue.remove(x, z); world.chunkProviderServer.unloadQueue.remove(x, z);
net.minecraft.server.Chunk chunk = (net.minecraft.server.Chunk) provider.chunks.get(x, z); net.minecraft.server.Chunk chunk = (net.minecraft.server.Chunk) world.chunkProviderServer.chunks.get(x, z);
if (chunk == null) { if (chunk == null) {
chunk = provider.loadChunk(x, z); chunk = world.chunkProviderServer.loadChunk(x, z);
chunkLoadPostProcess(chunk, x, z); chunkLoadPostProcess(chunk, x, z);
} }
@ -241,26 +237,26 @@ public class CraftWorld implements World {
private void chunkLoadPostProcess(net.minecraft.server.Chunk chunk, int x, int z) { private void chunkLoadPostProcess(net.minecraft.server.Chunk chunk, int x, int z) {
if (chunk != null) { if (chunk != null) {
provider.chunks.put(x, z, chunk); world.chunkProviderServer.chunks.put(x, z, chunk);
provider.chunkList.add(chunk); world.chunkProviderServer.chunkList.add(chunk);
chunk.loadNOP(); chunk.loadNOP();
chunk.addEntities(); chunk.addEntities();
if (!chunk.done && provider.isChunkLoaded(x + 1, z + 1) && provider.isChunkLoaded(x, z + 1) && provider.isChunkLoaded(x + 1, z)) { if (!chunk.done && world.chunkProviderServer.isChunkLoaded(x + 1, z + 1) && world.chunkProviderServer.isChunkLoaded(x, z + 1) && world.chunkProviderServer.isChunkLoaded(x + 1, z)) {
provider.getChunkAt(provider, x, z); world.chunkProviderServer.getChunkAt(world.chunkProviderServer, x, z);
} }
if (provider.isChunkLoaded(x - 1, z) && !provider.getOrCreateChunk(x - 1, z).done && provider.isChunkLoaded(x - 1, z + 1) && provider.isChunkLoaded(x, z + 1) && provider.isChunkLoaded(x - 1, z)) { if (world.chunkProviderServer.isChunkLoaded(x - 1, z) && !world.chunkProviderServer.getOrCreateChunk(x - 1, z).done && world.chunkProviderServer.isChunkLoaded(x - 1, z + 1) && world.chunkProviderServer.isChunkLoaded(x, z + 1) && world.chunkProviderServer.isChunkLoaded(x - 1, z)) {
provider.getChunkAt(provider, x - 1, z); world.chunkProviderServer.getChunkAt(world.chunkProviderServer, x - 1, z);
} }
if (provider.isChunkLoaded(x, z - 1) && !provider.getOrCreateChunk(x, z - 1).done && provider.isChunkLoaded(x + 1, z - 1) && provider.isChunkLoaded(x, z - 1) && provider.isChunkLoaded(x + 1, z)) { if (world.chunkProviderServer.isChunkLoaded(x, z - 1) && !world.chunkProviderServer.getOrCreateChunk(x, z - 1).done && world.chunkProviderServer.isChunkLoaded(x + 1, z - 1) && world.chunkProviderServer.isChunkLoaded(x, z - 1) && world.chunkProviderServer.isChunkLoaded(x + 1, z)) {
provider.getChunkAt(provider, x, z - 1); world.chunkProviderServer.getChunkAt(world.chunkProviderServer, x, z - 1);
} }
if (provider.isChunkLoaded(x - 1, z - 1) && !provider.getOrCreateChunk(x - 1, z - 1).done && provider.isChunkLoaded(x - 1, z - 1) && provider.isChunkLoaded(x, z - 1) && provider.isChunkLoaded(x - 1, z)) { if (world.chunkProviderServer.isChunkLoaded(x - 1, z - 1) && !world.chunkProviderServer.getOrCreateChunk(x - 1, z - 1).done && world.chunkProviderServer.isChunkLoaded(x - 1, z - 1) && world.chunkProviderServer.isChunkLoaded(x, z - 1) && world.chunkProviderServer.isChunkLoaded(x - 1, z)) {
provider.getChunkAt(provider, x - 1, z - 1); world.chunkProviderServer.getChunkAt(world.chunkProviderServer, x - 1, z - 1);
} }
} }
} }