geforkt von Mirrors/Paper
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:
Ursprung
a818669be0
Commit
7e22faf9d6
@ -9,7 +9,9 @@ import java.util.Set;
|
||||
import java.util.TreeSet;
|
||||
|
||||
// CraftBukkit start
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.World.Environment;
|
||||
import org.bukkit.generator.ChunkGenerator;
|
||||
import org.bukkit.craftbukkit.CraftServer;
|
||||
import org.bukkit.craftbukkit.CraftWorld;
|
||||
@ -73,6 +75,7 @@ public class World implements IBlockAccess {
|
||||
}
|
||||
|
||||
// CraftBukkit start
|
||||
private final CraftWorld world;
|
||||
public boolean pvpMode;
|
||||
public ChunkGenerator generator;
|
||||
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
|
||||
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.world = new CraftWorld((WorldServer)this, gen, env);
|
||||
// CraftBukkit end
|
||||
|
||||
this.O = this.random.nextInt(12000);
|
||||
@ -125,6 +137,8 @@ public class World implements IBlockAccess {
|
||||
|
||||
this.g();
|
||||
this.x();
|
||||
|
||||
getServer().addWorld(world);// Craftbukkit
|
||||
}
|
||||
|
||||
protected IChunkProvider b() {
|
||||
@ -421,7 +435,7 @@ public class World implements IBlockAccess {
|
||||
CraftWorld world = ((WorldServer) this).getWorld();
|
||||
if (world != null) {
|
||||
BlockPhysicsEvent event = new BlockPhysicsEvent(world.getBlockAt(i, j, k), l);
|
||||
((WorldServer) this).getServer().getPluginManager().callEvent(event);
|
||||
getServer().getPluginManager().callEvent(event);
|
||||
|
||||
if (event.isCancelled()) {
|
||||
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
|
||||
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);
|
||||
}
|
||||
// CraftBukkit end
|
||||
@ -1647,7 +1661,7 @@ public class World implements IBlockAccess {
|
||||
this.worldData.b(i);
|
||||
if (i <= 0) {
|
||||
// CraftBukkit start
|
||||
CraftServer server = ((WorldServer) this).getServer();
|
||||
CraftServer server = getServer();
|
||||
|
||||
ThunderChangeEvent thunder = new ThunderChangeEvent(((WorldServer) this).getWorld(), !this.worldData.j());
|
||||
server.getPluginManager().callEvent(thunder);
|
||||
@ -1671,7 +1685,7 @@ public class World implements IBlockAccess {
|
||||
this.worldData.c(j);
|
||||
if (j <= 0) {
|
||||
// CraftBukkit start
|
||||
CraftServer server = ((WorldServer) this).getServer();
|
||||
CraftServer server = getServer();
|
||||
|
||||
WeatherChangeEvent weather = new WeatherChangeEvent(((WorldServer) this).getWorld(), !this.worldData.l());
|
||||
server.getPluginManager().callEvent(weather);
|
||||
@ -1716,7 +1730,7 @@ public class World implements IBlockAccess {
|
||||
|
||||
private void y() {
|
||||
// CraftBukkit start
|
||||
CraftServer server = ((WorldServer) this).getServer();
|
||||
CraftServer server = getServer();
|
||||
|
||||
WeatherChangeEvent weather = new WeatherChangeEvent(((WorldServer) this).getWorld(), false);
|
||||
server.getPluginManager().callEvent(weather);
|
||||
@ -1818,7 +1832,7 @@ public class World implements IBlockAccess {
|
||||
// CraftBukkit start
|
||||
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()) {
|
||||
this.setTypeId(l + i, k1, j1 + j, snow.getMaterial().getId());
|
||||
this.setData(l + i, k1, j1 + j, snow.getData());
|
||||
@ -1980,7 +1994,7 @@ public class World implements IBlockAccess {
|
||||
|
||||
// CraftBukkit start
|
||||
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();
|
||||
// CraftBukkit end
|
||||
|
@ -5,9 +5,8 @@ import java.util.List;
|
||||
|
||||
// CraftBukkit start
|
||||
import org.bukkit.BlockChangeDelegate;
|
||||
import org.bukkit.World.Environment;
|
||||
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.InternalChunkGenerator;
|
||||
import org.bukkit.craftbukkit.generator.NetherChunkGenerator;
|
||||
@ -25,30 +24,18 @@ public class WorldServer extends World implements BlockChangeDelegate {
|
||||
private EntityList G = new EntityList();
|
||||
|
||||
// CraftBukkit start - change signature
|
||||
public WorldServer(MinecraftServer minecraftserver, IDataManager idatamanager, String s, int i, long j, org.bukkit.World.Environment env, ChunkGenerator gen) {
|
||||
super(idatamanager, s, j, WorldProvider.a(env.getId()), 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, env);
|
||||
this.server = minecraftserver;
|
||||
|
||||
this.dimension = i;
|
||||
this.cserver = minecraftserver.server;
|
||||
this.world = new CraftWorld(this, gen);
|
||||
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;
|
||||
}
|
||||
|
||||
public CraftServer getServer() {
|
||||
return cserver;
|
||||
}
|
||||
// CraftBukkit end
|
||||
|
||||
public void entityJoinedWorld(Entity entity, boolean flag) {
|
||||
@ -131,8 +118,8 @@ public class WorldServer extends World implements BlockChangeDelegate {
|
||||
|
||||
public boolean a(Entity entity) {
|
||||
// CraftBukkit start
|
||||
LightningStrikeEvent lightning = new LightningStrikeEvent((org.bukkit.World) world, (org.bukkit.entity.LightningStrike) entity.getBukkitEntity());
|
||||
this.cserver.getPluginManager().callEvent(lightning);
|
||||
LightningStrikeEvent lightning = new LightningStrikeEvent(getWorld(), (org.bukkit.entity.LightningStrike) entity.getBukkitEntity());
|
||||
getServer().getPluginManager().callEvent(lightning);
|
||||
|
||||
if (lightning.isCancelled()) {
|
||||
return false;
|
||||
|
@ -475,7 +475,7 @@ public final class CraftServer implements Server {
|
||||
return worlds.get(name.toLowerCase());
|
||||
}
|
||||
|
||||
protected void addWorld(World world) {
|
||||
public void addWorld(World world) {
|
||||
worlds.put(world.getName().toLowerCase(), world);
|
||||
}
|
||||
|
||||
|
@ -21,6 +21,7 @@ import org.bukkit.Chunk;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.util.Vector;
|
||||
import org.bukkit.BlockChangeDelegate;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.generator.ChunkGenerator;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.TreeType;
|
||||
@ -30,23 +31,18 @@ import org.bukkit.generator.BlockPopulator;
|
||||
public class CraftWorld implements World {
|
||||
private final WorldServer world;
|
||||
private Environment environment;
|
||||
private final CraftServer server;
|
||||
private final ChunkProviderServer provider;
|
||||
private final CraftServer server = (CraftServer)Bukkit.getServer();
|
||||
private HashMap<Integer, CraftChunk> unloadedChunks = new HashMap<Integer, CraftChunk>();
|
||||
private final ChunkGenerator generator;
|
||||
private final List<BlockPopulator> populators = new ArrayList<BlockPopulator>();
|
||||
|
||||
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.server = world.getServer();
|
||||
this.provider = world.chunkProviderServer;
|
||||
this.generator = gen;
|
||||
|
||||
environment = Environment.getEnvironment(world.worldProvider.dimension);
|
||||
|
||||
server.addWorld(this);
|
||||
environment = env;
|
||||
}
|
||||
|
||||
public void preserveChunk(CraftChunk chunk) {
|
||||
@ -91,7 +87,7 @@ public class CraftWorld implements World {
|
||||
}
|
||||
|
||||
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) {
|
||||
@ -99,11 +95,11 @@ public class CraftWorld implements World {
|
||||
}
|
||||
|
||||
public boolean isChunkLoaded(int x, int z) {
|
||||
return provider.isChunkLoaded(x, z);
|
||||
return world.chunkProviderServer.isChunkLoaded(x, z);
|
||||
}
|
||||
|
||||
public Chunk[] getLoadedChunks() {
|
||||
Object[] chunks = provider.chunks.values().toArray();
|
||||
Object[] chunks = world.chunkProviderServer.chunks.values().toArray();
|
||||
org.bukkit.Chunk[] craftChunks = new CraftChunk[chunks.length];
|
||||
|
||||
for (int i = 0; i < chunks.length; i++) {
|
||||
@ -135,7 +131,7 @@ public class CraftWorld implements World {
|
||||
return false;
|
||||
}
|
||||
|
||||
provider.queueUnload(x, z);
|
||||
world.chunkProviderServer.queueUnload(x, z);
|
||||
|
||||
return true;
|
||||
}
|
||||
@ -145,18 +141,18 @@ public class CraftWorld implements World {
|
||||
return false;
|
||||
}
|
||||
|
||||
net.minecraft.server.Chunk chunk = provider.getOrCreateChunk(x, z);
|
||||
net.minecraft.server.Chunk chunk = world.chunkProviderServer.getOrCreateChunk(x, z);
|
||||
|
||||
if (save) {
|
||||
chunk.removeEntities();
|
||||
provider.saveChunk(chunk);
|
||||
provider.saveChunkNOP(chunk);
|
||||
world.chunkProviderServer.saveChunk(chunk);
|
||||
world.chunkProviderServer.saveChunkNOP(chunk);
|
||||
}
|
||||
|
||||
preserveChunk((CraftChunk) chunk.bukkitChunk);
|
||||
provider.unloadQueue.remove(x, z);
|
||||
provider.chunks.remove(x, z);
|
||||
provider.chunkList.remove(chunk);
|
||||
world.chunkProviderServer.unloadQueue.remove(x, z);
|
||||
world.chunkProviderServer.chunks.remove(x, z);
|
||||
world.chunkProviderServer.chunkList.remove(chunk);
|
||||
|
||||
return true;
|
||||
}
|
||||
@ -164,14 +160,14 @@ public class CraftWorld implements World {
|
||||
public boolean regenerateChunk(int x, int z) {
|
||||
unloadChunk(x, z, false, false);
|
||||
|
||||
provider.unloadQueue.remove(x, z);
|
||||
world.chunkProviderServer.unloadQueue.remove(x, z);
|
||||
|
||||
net.minecraft.server.Chunk chunk = null;
|
||||
|
||||
if (provider.chunkProvider == null) {
|
||||
chunk = provider.emptyChunk;
|
||||
if (world.chunkProviderServer.chunkProvider == null) {
|
||||
chunk = world.chunkProviderServer.emptyChunk;
|
||||
} else {
|
||||
chunk = provider.chunkProvider.getOrCreateChunk(x, z);
|
||||
chunk = world.chunkProviderServer.chunkProvider.getOrCreateChunk(x, z);
|
||||
}
|
||||
|
||||
chunkLoadPostProcess(chunk, x, z);
|
||||
@ -208,7 +204,7 @@ public class CraftWorld implements World {
|
||||
|
||||
for (Player player : players) {
|
||||
Location loc = player.getLocation();
|
||||
if (loc.getWorld() != provider.world.getWorld()) {
|
||||
if (loc.getWorld() != world.chunkProviderServer.world.getWorld()) {
|
||||
continue;
|
||||
}
|
||||
|
||||
@ -225,14 +221,14 @@ public class CraftWorld implements World {
|
||||
public boolean loadChunk(int x, int z, boolean generate) {
|
||||
if (generate) {
|
||||
// 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);
|
||||
net.minecraft.server.Chunk chunk = (net.minecraft.server.Chunk) provider.chunks.get(x, z);
|
||||
world.chunkProviderServer.unloadQueue.remove(x, z);
|
||||
net.minecraft.server.Chunk chunk = (net.minecraft.server.Chunk) world.chunkProviderServer.chunks.get(x, z);
|
||||
|
||||
if (chunk == null) {
|
||||
chunk = provider.loadChunk(x, z);
|
||||
chunk = world.chunkProviderServer.loadChunk(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) {
|
||||
if (chunk != null) {
|
||||
provider.chunks.put(x, z, chunk);
|
||||
provider.chunkList.add(chunk);
|
||||
world.chunkProviderServer.chunks.put(x, z, chunk);
|
||||
world.chunkProviderServer.chunkList.add(chunk);
|
||||
|
||||
chunk.loadNOP();
|
||||
chunk.addEntities();
|
||||
|
||||
if (!chunk.done && provider.isChunkLoaded(x + 1, z + 1) && provider.isChunkLoaded(x, z + 1) && provider.isChunkLoaded(x + 1, z)) {
|
||||
provider.getChunkAt(provider, x, z);
|
||||
if (!chunk.done && world.chunkProviderServer.isChunkLoaded(x + 1, z + 1) && world.chunkProviderServer.isChunkLoaded(x, z + 1) && world.chunkProviderServer.isChunkLoaded(x + 1, 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)) {
|
||||
provider.getChunkAt(provider, 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)) {
|
||||
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)) {
|
||||
provider.getChunkAt(provider, x, z - 1);
|
||||
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)) {
|
||||
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)) {
|
||||
provider.getChunkAt(provider, x - 1, z - 1);
|
||||
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)) {
|
||||
world.chunkProviderServer.getChunkAt(world.chunkProviderServer, x - 1, z - 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Laden…
In neuem Issue referenzieren
Einen Benutzer sperren