2010-12-29 00:52:29 +01:00
|
|
|
package net.minecraft.server;
|
|
|
|
|
|
|
|
import java.io.File;
|
2011-01-29 22:50:29 +01:00
|
|
|
import java.util.ArrayList;
|
|
|
|
import java.util.List;
|
|
|
|
import java.util.Random;
|
2011-01-01 09:12:39 +01:00
|
|
|
|
2011-01-11 09:25:13 +01:00
|
|
|
// CraftBukkit start
|
2011-01-30 22:53:57 +01:00
|
|
|
import org.bukkit.BlockChangeDelegate;
|
2010-12-30 23:07:54 +01:00
|
|
|
import org.bukkit.craftbukkit.CraftServer;
|
2010-12-29 00:52:29 +01:00
|
|
|
import org.bukkit.craftbukkit.CraftWorld;
|
2010-12-31 13:52:40 +01:00
|
|
|
import org.bukkit.event.Event;
|
2011-01-01 07:20:44 +01:00
|
|
|
import org.bukkit.event.Event.Type;
|
|
|
|
import org.bukkit.event.block.BlockCanBuildEvent;
|
2010-12-30 23:07:54 +01:00
|
|
|
import org.bukkit.event.block.BlockPhysicsEvent;
|
2010-12-29 00:52:29 +01:00
|
|
|
|
2011-01-30 22:53:57 +01:00
|
|
|
public class WorldServer extends World implements BlockChangeDelegate {
|
|
|
|
// CraftBukkit end
|
2010-12-29 00:52:29 +01:00
|
|
|
|
|
|
|
public ChunkProviderServer A;
|
2011-01-29 22:50:29 +01:00
|
|
|
public boolean B = false;
|
2010-12-29 00:52:29 +01:00
|
|
|
public boolean C;
|
|
|
|
private MinecraftServer D;
|
2011-01-29 22:50:29 +01:00
|
|
|
private EntityList E = new EntityList();
|
2010-12-29 00:52:29 +01:00
|
|
|
|
2011-01-29 22:50:29 +01:00
|
|
|
public WorldServer(MinecraftServer minecraftserver, File file1, String s, int i) {
|
|
|
|
super(file1, s, (new Random()).nextLong(), WorldProvider.a(i));
|
|
|
|
this.D = minecraftserver;
|
|
|
|
|
|
|
|
// CraftBukkit start
|
|
|
|
world = new CraftWorld(this);
|
|
|
|
server = minecraftserver.server;
|
|
|
|
}
|
|
|
|
|
|
|
|
private final CraftWorld world;
|
|
|
|
private final CraftServer server;
|
|
|
|
|
2011-01-30 20:19:56 +01:00
|
|
|
/**
|
|
|
|
* setData
|
|
|
|
*
|
|
|
|
* @param x
|
|
|
|
* @param y
|
|
|
|
* @param z
|
|
|
|
* @param data (actually a byte!)
|
|
|
|
*/
|
2011-01-29 22:50:29 +01:00
|
|
|
@Override
|
2011-01-30 20:19:56 +01:00
|
|
|
public boolean d(int x, int y, int z, int data) {
|
|
|
|
boolean result = super.d(x, y, z, data);
|
|
|
|
if ((result) && (world != null)) world.updateBlock(x, y, z, null, data);
|
2011-01-29 22:50:29 +01:00
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2011-01-30 20:19:56 +01:00
|
|
|
public boolean setTypeId(int x, int y, int z, int type) {
|
|
|
|
boolean result = super.setTypeId(x, y, z, type);
|
|
|
|
if ((result) && (world != null)) world.updateBlock(x, y, z, type, null);
|
2011-01-29 22:50:29 +01:00
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2011-01-30 20:19:56 +01:00
|
|
|
public boolean setTypeIdAndData(int x, int y, int z, int type, int data) {
|
|
|
|
boolean result = super.setTypeIdAndData(x, y, z, type, data);
|
|
|
|
if ((result) && (world != null)) world.updateBlock(x, y, z, type, data);
|
2011-01-29 22:50:29 +01:00
|
|
|
return result;
|
2010-12-29 00:52:29 +01:00
|
|
|
}
|
|
|
|
|
2011-01-29 22:50:29 +01:00
|
|
|
public CraftWorld getWorld() {
|
|
|
|
return world;
|
|
|
|
}
|
|
|
|
|
|
|
|
public CraftServer getServer() {
|
|
|
|
return server;
|
|
|
|
}
|
|
|
|
// CraftBukkit end
|
|
|
|
|
2011-01-11 09:25:13 +01:00
|
|
|
public void f() {
|
|
|
|
super.f();
|
|
|
|
}
|
|
|
|
|
|
|
|
public void a(Entity entity, boolean flag) {
|
2011-01-29 22:50:29 +01:00
|
|
|
if (!this.D.m && (entity instanceof EntityAnimal || entity instanceof EntityWaterAnimal)) {
|
2011-01-14 14:31:10 +01:00
|
|
|
entity.q();
|
2011-01-11 09:25:13 +01:00
|
|
|
}
|
2011-01-29 22:50:29 +01:00
|
|
|
|
|
|
|
if (entity.passenger == null || !(entity.passenger instanceof EntityHuman)) {
|
2011-01-11 09:25:13 +01:00
|
|
|
super.a(entity, flag);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public void b(Entity entity, boolean flag) {
|
|
|
|
super.a(entity, flag);
|
|
|
|
}
|
|
|
|
|
2011-01-29 22:50:29 +01:00
|
|
|
protected IChunkProvider a(File file1) {
|
|
|
|
this.A = new ChunkProviderServer(this, this.q.a(file1), this.q.c());
|
|
|
|
return this.A;
|
2011-01-11 09:25:13 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
public List d(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-01-11 09:25:13 +01:00
|
|
|
|
|
|
|
if (tileentity.b >= i && tileentity.c >= j && tileentity.d >= k && tileentity.b < l && tileentity.c < i1 && tileentity.d < 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) {
|
|
|
|
int l = (int) MathHelper.e((float) (i - this.spawnX));
|
|
|
|
int i1 = (int) MathHelper.e((float) (k - this.spawnZ));
|
2011-01-11 09:25:13 +01:00
|
|
|
|
|
|
|
if (l > i1) {
|
|
|
|
i1 = l;
|
|
|
|
}
|
2011-01-29 22:50:29 +01:00
|
|
|
|
|
|
|
return i1 > 16 || this.D.f.g(entityhuman.name);
|
2011-01-11 09:25:13 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
protected void b(Entity entity) {
|
|
|
|
super.b(entity);
|
2011-01-29 22:50:29 +01:00
|
|
|
this.E.a(entity.id, entity);
|
2011-01-11 09:25:13 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
protected void c(Entity entity) {
|
|
|
|
super.c(entity);
|
2011-01-29 22:50:29 +01:00
|
|
|
this.E.d(entity.id);
|
2011-01-11 09:25:13 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
public Entity a(int i) {
|
2011-01-29 22:50:29 +01:00
|
|
|
return (Entity) this.E.a(i);
|
2011-01-11 09:25:13 +01:00
|
|
|
}
|
|
|
|
|
2011-01-29 22:50:29 +01:00
|
|
|
public void a(Entity entity, byte b0) {
|
|
|
|
Packet38EntityStatus packet38entitystatus = new Packet38EntityStatus(entity.id, b0);
|
2011-01-11 09:25:13 +01:00
|
|
|
|
2011-01-29 22:50:29 +01:00
|
|
|
this.D.k.b(entity, packet38entitystatus);
|
2011-01-11 09:25:13 +01:00
|
|
|
}
|
|
|
|
|
2011-01-29 22:50:29 +01:00
|
|
|
public Explosion a(Entity entity, double d0, double d1, double d2, float f, boolean flag) {
|
|
|
|
Explosion explosion = super.a(entity, d0, d1, d2, f, flag);
|
2011-01-11 09:25:13 +01:00
|
|
|
|
2011-01-29 22:50:29 +01:00
|
|
|
this.D.f.a(d0, d1, d2, 64.0D, new Packet60Explosion(d0, d1, d2, f, explosion.g));
|
2011-01-11 09:25:13 +01:00
|
|
|
return explosion;
|
|
|
|
}
|
|
|
|
|
2011-01-14 22:22:14 +01:00
|
|
|
public void c(int i, int j, int k, int l, int i1) {
|
|
|
|
super.c(i, j, k, l, i1);
|
2011-01-29 22:50:29 +01:00
|
|
|
this.D.f.a((double) i, (double) j, (double) k, 64.0D, new Packet54PlayNoteBlock(i, j, k, l, i1));
|
2011-01-14 22:22:14 +01:00
|
|
|
}
|
|
|
|
|
2011-01-02 00:36:24 +01:00
|
|
|
// XXX: the following method is straight from the World.java with tweaks as noted. KEEP THEM UPDATED!
|
2011-01-11 09:25:13 +01:00
|
|
|
// XXX: done because it calls private k()
|
2010-12-30 23:07:54 +01:00
|
|
|
@Override
|
2011-01-29 22:50:29 +01:00
|
|
|
public void h(int i, int j, int k, int l) {
|
|
|
|
this.l(i - 1, j, k, l);
|
|
|
|
this.l(i + 1, j, k, l);
|
|
|
|
this.l(i, j - 1, k, l);
|
|
|
|
this.l(i, j + 1, k, l);
|
|
|
|
this.l(i, j, k - 1, l);
|
|
|
|
this.l(i, j, k + 1, l);
|
2010-12-30 23:07:54 +01:00
|
|
|
}
|
|
|
|
|
2011-01-02 00:36:24 +01:00
|
|
|
// XXX: the following method is straight from the World.java with tweaks as noted. KEEP THEM UPDATED!
|
2011-01-29 22:50:29 +01:00
|
|
|
private void l(int i, int j, int k, int l) {
|
|
|
|
if (!this.i && !this.isStatic) {
|
|
|
|
Block block = Block.byId[this.getTypeId(i, j, k)];
|
|
|
|
|
|
|
|
if (block != null) {
|
|
|
|
// CraftBukkit start
|
|
|
|
if (world != null) {
|
|
|
|
BlockPhysicsEvent event = new BlockPhysicsEvent(Event.Type.BLOCK_PHYSICS, world.getBlockAt(i, j, k), l);
|
|
|
|
server.getPluginManager().callEvent(event);
|
|
|
|
if (event.isCancelled()) {
|
|
|
|
return;
|
|
|
|
}
|
2011-01-04 22:13:59 +01:00
|
|
|
}
|
2011-01-29 22:50:29 +01:00
|
|
|
// CraftBukkit stop
|
2010-12-30 23:07:54 +01:00
|
|
|
|
2011-01-29 22:50:29 +01:00
|
|
|
block.b(this, i, j, k, l);
|
|
|
|
}
|
2010-12-30 23:07:54 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-01-02 00:36:24 +01:00
|
|
|
// XXX: the following method is straight from the World.java with tweaks as noted. KEEP THEM UPDATED!
|
2011-01-11 09:25:13 +01:00
|
|
|
@Override
|
2011-01-29 22:50:29 +01:00
|
|
|
public boolean a(int i, int j, int k, int l, boolean flag) {
|
|
|
|
int i1 = this.getTypeId(j, k, l);
|
|
|
|
Block block = Block.byId[i1];
|
|
|
|
Block block1 = Block.byId[i];
|
|
|
|
AxisAlignedBB axisalignedbb = block1.d(this, j, k, l);
|
2011-01-02 00:48:58 +01:00
|
|
|
|
|
|
|
if (flag) {
|
|
|
|
axisalignedbb = null;
|
|
|
|
}
|
2011-01-29 22:50:29 +01:00
|
|
|
|
2011-01-11 09:25:13 +01:00
|
|
|
// Craftbukkit start - We dont want to allow the user to override the bounding box check
|
2011-01-29 22:50:29 +01:00
|
|
|
boolean defaultReturn = axisalignedbb != null && !this.a(axisalignedbb) ? false : (block != Block.WATER && block != Block.STATIONARY_WATER && block != Block.LAVA && block != Block.STATIONARY_LAVA && block != Block.FIRE && block != Block.SNOW ? i > 0 && block == null && block1.a(this, j, k, l) : true);
|
2011-01-11 09:25:13 +01:00
|
|
|
|
2011-01-29 22:50:29 +01:00
|
|
|
if (!defaultReturn) {
|
|
|
|
return false;
|
2011-01-02 00:48:58 +01:00
|
|
|
}
|
2011-01-11 09:25:13 +01:00
|
|
|
|
2011-01-29 22:50:29 +01:00
|
|
|
BlockCanBuildEvent event = new BlockCanBuildEvent(Type.BLOCK_CANBUILD, getWorld().getBlockAt(j, k, l), i1, defaultReturn);
|
|
|
|
server.getPluginManager().callEvent(event);
|
2011-01-01 14:06:04 +01:00
|
|
|
|
2011-01-29 22:50:29 +01:00
|
|
|
return event.isBuildable();
|
2011-01-11 09:25:13 +01:00
|
|
|
// CraftBukkit end
|
2010-12-29 00:52:29 +01:00
|
|
|
}
|
|
|
|
}
|