2010-12-29 00:52:29 +01:00
|
|
|
package net.minecraft.server;
|
|
|
|
|
2011-01-29 22:50:29 +01:00
|
|
|
import java.util.ArrayList;
|
|
|
|
import java.util.List;
|
2011-01-01 09:12:39 +01:00
|
|
|
|
2011-01-11 09:25:13 +01:00
|
|
|
// CraftBukkit start
|
2011-04-26 01:47:25 +02:00
|
|
|
import org.bukkit.event.weather.LightningStrikeEvent;
|
2010-12-29 00:52:29 +01:00
|
|
|
|
2012-07-22 08:18:00 +02:00
|
|
|
public class WorldServer extends World implements org.bukkit.BlockChangeDelegate {
|
2011-06-12 00:02:58 +02:00
|
|
|
// CraftBukkit end
|
2010-12-29 00:52:29 +01:00
|
|
|
|
2011-04-20 19:05:14 +02:00
|
|
|
public ChunkProviderServer chunkProviderServer;
|
|
|
|
public boolean weirdIsOpCache = false;
|
2011-09-24 23:03:31 +02:00
|
|
|
public boolean savingDisabled;
|
2011-04-20 19:05:14 +02:00
|
|
|
public final MinecraftServer server; // CraftBukkit - private -> public final
|
2012-01-14 21:03:48 +01:00
|
|
|
private IntHashMap entitiesById;
|
2010-12-29 00:52:29 +01:00
|
|
|
|
2011-05-28 22:50:08 +02:00
|
|
|
// CraftBukkit start - change signature
|
2012-07-22 08:18:00 +02:00
|
|
|
public WorldServer(MinecraftServer minecraftserver, IDataManager idatamanager, String s, int i, WorldSettings worldsettings, org.bukkit.World.Environment env, org.bukkit.generator.ChunkGenerator gen) {
|
2011-09-15 02:23:52 +02:00
|
|
|
super(idatamanager, s, worldsettings, WorldProvider.byDimension(env.getId()), gen, env);
|
2011-04-20 19:05:14 +02:00
|
|
|
this.server = minecraftserver;
|
2012-01-14 21:03:48 +01:00
|
|
|
if (this.entitiesById == null) {
|
|
|
|
this.entitiesById = new IntHashMap();
|
2011-12-01 22:43:54 +01:00
|
|
|
}
|
2011-01-29 22:50:29 +01:00
|
|
|
|
2011-05-26 14:48:22 +02:00
|
|
|
this.dimension = i;
|
2011-04-30 00:34:37 +02:00
|
|
|
this.pvpMode = minecraftserver.pvpMode;
|
2011-08-15 20:27:02 +02:00
|
|
|
this.manager = new PlayerManager(minecraftserver, this.dimension, minecraftserver.propertyManager.getInt("view-distance", 10));
|
2011-01-29 22:50:29 +01:00
|
|
|
}
|
|
|
|
|
2011-10-02 05:25:21 +02:00
|
|
|
@Override
|
|
|
|
public TileEntity getTileEntity(int i, int j, int k) {
|
|
|
|
TileEntity result = super.getTileEntity(i, j, k);
|
|
|
|
int type = getTypeId(i, j, k);
|
|
|
|
|
|
|
|
if (type == Block.CHEST.id) {
|
|
|
|
if (!(result instanceof TileEntityChest)) {
|
|
|
|
result = fixTileEntity(i, j, k, type, result);
|
|
|
|
}
|
|
|
|
} else if (type == Block.FURNACE.id) {
|
|
|
|
if (!(result instanceof TileEntityFurnace)) {
|
|
|
|
result = fixTileEntity(i, j, k, type, result);
|
|
|
|
}
|
|
|
|
} else if (type == Block.DISPENSER.id) {
|
|
|
|
if (!(result instanceof TileEntityDispenser)) {
|
|
|
|
result = fixTileEntity(i, j, k, type, result);
|
|
|
|
}
|
|
|
|
} else if (type == Block.JUKEBOX.id) {
|
|
|
|
if (!(result instanceof TileEntityRecordPlayer)) {
|
|
|
|
result = fixTileEntity(i, j, k, type, result);
|
|
|
|
}
|
|
|
|
} else if (type == Block.NOTE_BLOCK.id) {
|
|
|
|
if (!(result instanceof TileEntityNote)) {
|
|
|
|
result = fixTileEntity(i, j, k, type, result);
|
|
|
|
}
|
|
|
|
} else if (type == Block.MOB_SPAWNER.id) {
|
|
|
|
if (!(result instanceof TileEntityMobSpawner)) {
|
|
|
|
result = fixTileEntity(i, j, k, type, result);
|
|
|
|
}
|
|
|
|
} else if ((type == Block.SIGN_POST.id) || (type == Block.WALL_SIGN.id)) {
|
|
|
|
if (!(result instanceof TileEntitySign)) {
|
|
|
|
result = fixTileEntity(i, j, k, type, result);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
private TileEntity fixTileEntity(int x, int y, int z, int type, TileEntity found) {
|
|
|
|
getServer().getLogger().severe("Block at " + x + "," + y + "," + z + " is " + org.bukkit.Material.getMaterial(type).toString() + " but has " + found + ". "
|
|
|
|
+ "Bukkit will attempt to fix this, but there may be additional damage that we cannot recover.");
|
|
|
|
|
|
|
|
if (Block.byId[type] instanceof BlockContainer) {
|
2012-01-14 23:02:10 +01:00
|
|
|
TileEntity replacement = ((BlockContainer) Block.byId[type]).a_();
|
2011-10-02 05:25:21 +02:00
|
|
|
setTileEntity(x, y, z, replacement);
|
|
|
|
return replacement;
|
|
|
|
} else {
|
|
|
|
getServer().getLogger().severe("Don't know how to fix for this type... Can't do anything! :(");
|
|
|
|
return found;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-05-26 14:48:22 +02:00
|
|
|
public final int dimension;
|
|
|
|
public EntityTracker tracker;
|
2011-05-26 23:15:27 +02:00
|
|
|
public PlayerManager manager;
|
2011-01-29 22:50:29 +01:00
|
|
|
// CraftBukkit end
|
|
|
|
|
2011-04-20 19:05:14 +02:00
|
|
|
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 */
|
2012-01-12 23:10:13 +01:00
|
|
|
if (!this.server.spawnNPCs && entity instanceof NPC) {
|
|
|
|
entity.die();
|
|
|
|
}
|
2011-01-29 22:50:29 +01:00
|
|
|
|
|
|
|
if (entity.passenger == null || !(entity.passenger instanceof EntityHuman)) {
|
2011-04-20 19:05:14 +02:00
|
|
|
super.entityJoinedWorld(entity, flag);
|
2011-01-11 09:25:13 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-04-20 19:05:14 +02:00
|
|
|
public void vehicleEnteredWorld(Entity entity, boolean flag) {
|
|
|
|
super.entityJoinedWorld(entity, flag);
|
2011-01-11 09:25:13 +01:00
|
|
|
}
|
|
|
|
|
2011-02-23 03:37:56 +01:00
|
|
|
protected IChunkProvider b() {
|
2011-11-30 00:17:43 +01:00
|
|
|
IChunkLoader ichunkloader = this.dataManager.createChunkLoader(this.worldProvider);
|
2011-02-23 03:37:56 +01:00
|
|
|
|
2011-06-12 00:02:58 +02:00
|
|
|
// CraftBukkit start
|
2012-07-22 08:18:00 +02:00
|
|
|
org.bukkit.craftbukkit.generator.InternalChunkGenerator gen;
|
2011-06-06 15:52:02 +02:00
|
|
|
|
|
|
|
if (this.generator != null) {
|
2012-07-22 08:18:00 +02:00
|
|
|
gen = new org.bukkit.craftbukkit.generator.CustomChunkGenerator(this, this.getSeed(), this.generator);
|
2011-06-06 15:52:02 +02:00
|
|
|
} else if (this.worldProvider instanceof WorldProviderHell) {
|
2012-07-22 08:18:00 +02:00
|
|
|
gen = new org.bukkit.craftbukkit.generator.NetherChunkGenerator(this, this.getSeed());
|
2011-11-30 00:17:43 +01:00
|
|
|
} else if (this.worldProvider instanceof WorldProviderTheEnd) {
|
2012-07-22 08:18:00 +02:00
|
|
|
gen = new org.bukkit.craftbukkit.generator.SkyLandsChunkGenerator(this, this.getSeed());
|
2011-06-06 15:52:02 +02:00
|
|
|
} else {
|
2012-07-22 08:18:00 +02:00
|
|
|
gen = new org.bukkit.craftbukkit.generator.NormalChunkGenerator(this, this.getSeed());
|
2011-06-06 15:52:02 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
this.chunkProviderServer = new ChunkProviderServer(this, ichunkloader, gen);
|
2011-06-12 00:02:58 +02:00
|
|
|
// CraftBukkit end
|
2011-06-06 15:52:02 +02:00
|
|
|
|
2011-04-20 19:05:14 +02:00
|
|
|
return this.chunkProviderServer;
|
2011-01-11 09:25:13 +01:00
|
|
|
}
|
|
|
|
|
2011-04-20 19:05:14 +02:00
|
|
|
public List getTileEntities(int i, int j, int k, int l, int i1, int j1) {
|
2011-01-11 09:25:13 +01:00
|
|
|
ArrayList arraylist = new ArrayList();
|
|
|
|
|
2012-01-14 21:03:48 +01:00
|
|
|
for (int k1 = 0; k1 < this.tileEntityList.size(); ++k1) {
|
|
|
|
TileEntity tileentity = (TileEntity) this.tileEntityList.get(k1);
|
2011-01-11 09:25:13 +01:00
|
|
|
|
2011-06-27 00:25:01 +02:00
|
|
|
if (tileentity.x >= i && tileentity.y >= j && tileentity.z >= k && tileentity.x < l && tileentity.y < i1 && tileentity.z < j1) {
|
2011-01-29 22:50:29 +01:00
|
|
|
arraylist.add(tileentity);
|
2011-01-11 09:25:13 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-01-29 22:50:29 +01:00
|
|
|
return arraylist;
|
2011-01-11 09:25:13 +01:00
|
|
|
}
|
|
|
|
|
2011-01-29 22:50:29 +01:00
|
|
|
public boolean a(EntityHuman entityhuman, int i, int j, int k) {
|
2011-09-15 02:23:52 +02:00
|
|
|
int l = MathHelper.a(i - this.worldData.c());
|
|
|
|
int i1 = MathHelper.a(k - this.worldData.e());
|
2011-01-11 09:25:13 +01:00
|
|
|
|
|
|
|
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
|
2011-06-27 00:25:01 +02:00
|
|
|
return i1 > this.getServer().getSpawnRadius() || this.server.serverConfigurationManager.isOp(entityhuman.name);
|
2011-01-11 09:25:13 +01:00
|
|
|
}
|
|
|
|
|
2011-12-01 22:43:54 +01:00
|
|
|
protected void c() {
|
2012-01-14 21:03:48 +01:00
|
|
|
if (this.entitiesById == null) {
|
|
|
|
this.entitiesById = new IntHashMap();
|
2011-12-01 22:43:54 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
super.c();
|
|
|
|
}
|
|
|
|
|
2011-01-11 09:25:13 +01:00
|
|
|
protected void c(Entity entity) {
|
|
|
|
super.c(entity);
|
2012-01-14 21:03:48 +01:00
|
|
|
this.entitiesById.a(entity.id, entity);
|
2012-03-22 21:39:39 +01:00
|
|
|
Entity[] aentity = entity.bb();
|
2011-11-20 09:01:14 +01:00
|
|
|
|
|
|
|
if (aentity != null) {
|
|
|
|
for (int i = 0; i < aentity.length; ++i) {
|
2012-01-14 21:03:48 +01:00
|
|
|
this.entitiesById.a(aentity[i].id, aentity[i]);
|
2011-11-20 09:01:14 +01:00
|
|
|
}
|
|
|
|
}
|
2011-04-20 22:47:26 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
protected void d(Entity entity) {
|
|
|
|
super.d(entity);
|
2012-01-14 21:03:48 +01:00
|
|
|
this.entitiesById.d(entity.id);
|
2012-03-22 21:39:39 +01:00
|
|
|
Entity[] aentity = entity.bb();
|
2011-11-20 09:01:14 +01:00
|
|
|
|
|
|
|
if (aentity != null) {
|
|
|
|
for (int i = 0; i < aentity.length; ++i) {
|
2012-01-14 21:03:48 +01:00
|
|
|
this.entitiesById.d(aentity[i].id);
|
2011-11-20 09:01:14 +01:00
|
|
|
}
|
|
|
|
}
|
2011-01-11 09:25:13 +01:00
|
|
|
}
|
|
|
|
|
2011-04-20 19:05:14 +02:00
|
|
|
public Entity getEntity(int i) {
|
2012-02-29 22:31:04 +01:00
|
|
|
return (Entity) this.entitiesById.get(i);
|
2011-04-20 22:47:26 +02:00
|
|
|
}
|
|
|
|
|
2011-06-27 00:25:01 +02:00
|
|
|
public boolean strikeLightning(Entity entity) {
|
2011-06-11 02:37:33 +02:00
|
|
|
// CraftBukkit start
|
2011-06-27 00:25:01 +02:00
|
|
|
LightningStrikeEvent lightning = new LightningStrikeEvent(this.getWorld(), (org.bukkit.entity.LightningStrike) entity.getBukkitEntity());
|
|
|
|
this.getServer().getPluginManager().callEvent(lightning);
|
2011-05-14 16:29:42 +02:00
|
|
|
|
2011-06-11 02:37:33 +02:00
|
|
|
if (lightning.isCancelled()) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2011-06-27 00:25:01 +02:00
|
|
|
if (super.strikeLightning(entity)) {
|
|
|
|
this.server.serverConfigurationManager.sendPacketNearby(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-11 09:25:13 +01:00
|
|
|
}
|
|
|
|
|
2012-02-29 22:31:04 +01:00
|
|
|
public void broadcastEntityEffect(Entity entity, byte b0) {
|
2011-01-29 22:50:29 +01:00
|
|
|
Packet38EntityStatus packet38entitystatus = new Packet38EntityStatus(entity.id, b0);
|
2011-01-11 09:25:13 +01:00
|
|
|
|
2011-05-31 19:04:52 +02:00
|
|
|
// CraftBukkit
|
2011-06-27 00:25:01 +02:00
|
|
|
this.server.getTracker(this.dimension).sendPacketToEntity(entity, packet38entitystatus);
|
2011-01-11 09:25:13 +01:00
|
|
|
}
|
|
|
|
|
2011-04-20 19:05:14 +02:00
|
|
|
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
|
2011-04-20 19:05:14 +02:00
|
|
|
Explosion explosion = super.createExplosion(entity, d0, d1, d2, f, flag);
|
2011-01-11 09:25:13 +01:00
|
|
|
|
2011-02-23 13:56:36 +01:00
|
|
|
if (explosion.wasCanceled) {
|
2011-02-07 19:37:08 +01:00
|
|
|
return explosion;
|
|
|
|
}
|
|
|
|
|
2011-06-27 00:25:01 +02:00
|
|
|
/* Remove
|
2011-06-12 00:02:58 +02:00
|
|
|
explosion.a = flag;
|
|
|
|
explosion.a();
|
|
|
|
explosion.a(false);
|
2011-06-27 00:25:01 +02:00
|
|
|
*/
|
|
|
|
this.server.serverConfigurationManager.sendPacketNearby(d0, d1, d2, 64.0D, this.dimension, new Packet60Explosion(d0, d1, d2, f, explosion.blocks));
|
2011-05-31 19:04:52 +02:00
|
|
|
// CraftBukkit end
|
2011-01-11 09:25:13 +01:00
|
|
|
return explosion;
|
|
|
|
}
|
|
|
|
|
2011-06-27 00:25:01 +02:00
|
|
|
public void playNote(int i, int j, int k, int l, int i1) {
|
|
|
|
super.playNote(i, j, k, l, i1);
|
2011-05-31 19:04:52 +02:00
|
|
|
// CraftBukkit
|
2011-06-27 00:25:01 +02:00
|
|
|
this.server.serverConfigurationManager.sendPacketNearby((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
|
|
|
}
|
|
|
|
|
2011-04-20 19:05:14 +02:00
|
|
|
public void saveLevel() {
|
2011-11-30 00:17:43 +01:00
|
|
|
this.dataManager.e();
|
2011-04-20 22:47:26 +02:00
|
|
|
}
|
|
|
|
|
2011-11-20 09:01:14 +01:00
|
|
|
protected void i() {
|
2012-03-01 11:49:23 +01:00
|
|
|
boolean flag = this.x();
|
2011-04-20 22:47:26 +02:00
|
|
|
|
2011-11-20 09:01:14 +01:00
|
|
|
super.i();
|
2012-03-01 11:49:23 +01:00
|
|
|
if (flag != this.x()) {
|
2011-06-09 08:33:16 +02:00
|
|
|
// CraftBukkit start - only sending weather packets to those affected
|
|
|
|
for (int i = 0; i < this.players.size(); ++i) {
|
2011-06-27 00:25:01 +02:00
|
|
|
if (((EntityPlayer) this.players.get(i)).world == this) {
|
2011-09-15 02:23:52 +02:00
|
|
|
((EntityPlayer) this.players.get(i)).netServerHandler.sendPacket(new Packet70Bed(flag ? 2 : 1, 0));
|
2011-06-09 08:33:16 +02:00
|
|
|
}
|
2011-04-20 22:47:26 +02:00
|
|
|
}
|
2011-06-09 08:33:16 +02:00
|
|
|
// CraftBukkit end
|
2011-04-20 22:47:26 +02:00
|
|
|
}
|
2011-01-14 22:22:14 +01:00
|
|
|
}
|
2010-12-29 00:52:29 +01:00
|
|
|
}
|