Paper/src/main/java/net/minecraft/server/WorldServer.java

202 lines
6.9 KiB
Java
Raw Normal View History

package net.minecraft.server;
2011-01-29 22:50:29 +01:00
import java.util.ArrayList;
import java.util.List;
// CraftBukkit start
import org.bukkit.BlockChangeDelegate;
import org.bukkit.generator.ChunkGenerator;
2010-12-30 23:07:54 +01:00
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;
import org.bukkit.craftbukkit.generator.NormalChunkGenerator;
import org.bukkit.craftbukkit.generator.SkyLandsChunkGenerator;
import org.bukkit.event.weather.LightningStrikeEvent;
public class WorldServer extends World implements BlockChangeDelegate {
// CraftBukkit end
public ChunkProviderServer chunkProviderServer;
public boolean weirdIsOpCache = false;
2011-05-26 14:48:22 +02:00
public boolean E;
public final MinecraftServer server; // CraftBukkit - private -> public final
2011-05-26 14:48:22 +02:00
private EntityList G = new EntityList();
2011-05-28 22:50:08 +02:00
// 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);
this.server = minecraftserver;
2011-01-29 22:50:29 +01:00
2011-05-26 14:48:22 +02:00
this.dimension = i;
this.cserver = minecraftserver.server;
this.world = new CraftWorld(this, gen);
2011-04-30 00:34:37 +02:00
this.pvpMode = minecraftserver.pvpMode;
this.manager = new PlayerManager(minecraftserver, dimension, minecraftserver.propertyManager.getInt("view-distance", 10));
2011-01-29 22:50:29 +01:00
}
2011-05-26 14:48:22 +02:00
public final int dimension;
2011-01-29 22:50:29 +01:00
private final CraftWorld world;
private final CraftServer cserver;
2011-05-26 14:48:22 +02:00
public EntityTracker tracker;
public PlayerManager manager;
2011-01-29 22:50:29 +01:00
public CraftWorld getWorld() {
return world;
}
public CraftServer getServer() {
return cserver;
2011-01-29 22:50:29 +01:00
}
// CraftBukkit end
public void entityJoinedWorld(Entity entity, boolean flag) {
2011-05-14 16:29:42 +02:00
/* CraftBukkit start - We prevent spawning in general, so this butchering is not needed
if (!this.server.spawnAnimals && (entity instanceof EntityAnimal || entity instanceof EntityWaterAnimal)) {
entity.die();
}
// CraftBukkit end */
2011-01-29 22:50:29 +01:00
if (entity.passenger == null || !(entity.passenger instanceof EntityHuman)) {
super.entityJoinedWorld(entity, flag);
}
}
public void vehicleEnteredWorld(Entity entity, boolean flag) {
super.entityJoinedWorld(entity, flag);
}
2011-02-23 03:37:56 +01:00
protected IChunkProvider b() {
2011-05-26 14:48:22 +02:00
IChunkLoader ichunkloader = this.w.a(this.worldProvider);
2011-02-23 03:37:56 +01:00
// Craftbukkit start
InternalChunkGenerator gen;
if (this.generator != null) {
gen = new CustomChunkGenerator(this, this.getSeed(), this.generator);
} else if (this.worldProvider instanceof WorldProviderHell) {
gen = new NetherChunkGenerator(this, this.getSeed());
} else if (this.worldProvider instanceof WorldProviderSky) {
gen = new SkyLandsChunkGenerator(this, this.getSeed());
} else {
gen = new NormalChunkGenerator(this, this.getSeed());
}
this.chunkProviderServer = new ChunkProviderServer(this, ichunkloader, gen);
// Craftbukkit end
return this.chunkProviderServer;
}
public List getTileEntities(int i, int j, int k, int l, int i1, int j1) {
ArrayList arraylist = new ArrayList();
2011-01-29 22:50:29 +01:00
for (int k1 = 0; k1 < this.c.size(); ++k1) {
TileEntity tileentity = (TileEntity) this.c.get(k1);
2011-02-23 03:37:56 +01:00
if (tileentity.e >= i && tileentity.f >= j && tileentity.g >= k && tileentity.e < l && tileentity.f < i1 && tileentity.g < j1) {
2011-01-29 22:50:29 +01:00
arraylist.add(tileentity);
}
}
2011-01-29 22:50:29 +01:00
return arraylist;
}
2011-01-29 22:50:29 +01:00
public boolean a(EntityHuman entityhuman, int i, int j, int k) {
int l = (int) MathHelper.abs((float) (i - this.worldData.c()));
int i1 = (int) MathHelper.abs((float) (k - this.worldData.e()));
if (l > i1) {
i1 = l;
}
2011-01-29 22:50:29 +01:00
2011-05-14 16:29:42 +02:00
// CraftBukkit - Configurable spawn protection
return i1 > this.server.spawnProtection || this.server.serverConfigurationManager.isOp(entityhuman.name);
}
protected void c(Entity entity) {
super.c(entity);
2011-05-26 14:48:22 +02:00
this.G.a(entity.id, entity);
2011-04-20 22:47:26 +02:00
}
protected void d(Entity entity) {
super.d(entity);
2011-05-26 14:48:22 +02:00
this.G.d(entity.id);
}
public Entity getEntity(int i) {
2011-05-26 14:48:22 +02:00
return (Entity) this.G.a(i);
2011-04-20 22:47:26 +02:00
}
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);
2011-05-14 16:29:42 +02:00
if (lightning.isCancelled()) {
return false;
}
if (super.a(entity)) {
2011-05-31 19:04:52 +02:00
this.server.serverConfigurationManager.a(entity.locX, entity.locY, entity.locZ, 512.0D, this.dimension, new Packet71Weather(entity));
2011-05-14 16:29:42 +02:00
// CraftBukkit end
return true;
2011-04-20 22:47:26 +02:00
} else {
return false;
}
}
2011-01-29 22:50:29 +01:00
public void a(Entity entity, byte b0) {
Packet38EntityStatus packet38entitystatus = new Packet38EntityStatus(entity.id, b0);
2011-05-31 19:04:52 +02:00
// CraftBukkit
this.server.b(this.dimension).b(entity, packet38entitystatus);
}
public Explosion createExplosion(Entity entity, double d0, double d1, double d2, float f, boolean flag) {
2011-05-14 16:29:42 +02:00
// CraftBukkit start
Explosion explosion = super.createExplosion(entity, d0, d1, d2, f, flag);
2011-02-23 13:56:36 +01:00
if (explosion.wasCanceled) {
return explosion;
}
2011-05-31 19:04:52 +02:00
// explosion.a = flag;
// explosion.a();
// explosion.a(false);
this.server.serverConfigurationManager.a(d0, d1, d2, 64.0D, this.dimension, new Packet60Explosion(d0, d1, d2, f, explosion.g));
// CraftBukkit end
return explosion;
}
2011-02-23 03:37:56 +01:00
public void d(int i, int j, int k, int l, int i1) {
super.d(i, j, k, l, i1);
2011-05-31 19:04:52 +02:00
// CraftBukkit
this.server.serverConfigurationManager.a((double) i, (double) j, (double) k, 64.0D, this.dimension, new Packet54PlayNoteBlock(i, j, k, l, i1));
2011-02-23 03:37:56 +01:00
}
public void saveLevel() {
2011-05-26 14:48:22 +02:00
this.w.e();
2011-04-20 22:47:26 +02:00
}
protected void i() {
boolean flag = this.v();
super.i();
if (flag != this.v()) {
// CraftBukkit start - only sending weather packets to those affected
for (int i = 0; i < this.players.size(); ++i) {
if (((EntityPlayer) this.players.get(i)).world == (World) this) {
if (flag) {
((EntityPlayer) this.players.get(i)).netServerHandler.sendPacket(new Packet70Bed(2));
} else {
((EntityPlayer) this.players.get(i)).netServerHandler.sendPacket(new Packet70Bed(1));
}
}
2011-04-20 22:47:26 +02:00
}
// CraftBukkit end
2011-04-20 22:47:26 +02:00
}
}
}