2011-02-05 19:15:04 +01:00
|
|
|
package net.minecraft.server;
|
|
|
|
|
|
|
|
import java.util.ArrayList;
|
|
|
|
import java.util.List;
|
|
|
|
|
|
|
|
class PlayerInstance {
|
|
|
|
|
|
|
|
private List b;
|
2011-04-20 19:05:14 +02:00
|
|
|
private int chunkX;
|
|
|
|
private int chunkZ;
|
2011-06-27 00:25:01 +02:00
|
|
|
private ChunkCoordIntPair location;
|
2011-04-20 19:05:14 +02:00
|
|
|
private short[] dirtyBlocks;
|
|
|
|
private int dirtyCount;
|
2011-02-05 19:15:04 +01:00
|
|
|
private int h;
|
|
|
|
|
2011-04-20 19:05:14 +02:00
|
|
|
final PlayerManager playerManager;
|
2011-02-05 19:15:04 +01:00
|
|
|
|
2011-02-07 00:47:44 +01:00
|
|
|
public PlayerInstance(PlayerManager playermanager, int i, int j) {
|
2011-04-20 19:05:14 +02:00
|
|
|
this.playerManager = playermanager;
|
2011-02-05 19:15:04 +01:00
|
|
|
this.b = new ArrayList();
|
2012-03-01 11:49:23 +01:00
|
|
|
this.dirtyBlocks = new short[64];
|
2011-04-20 19:05:14 +02:00
|
|
|
this.dirtyCount = 0;
|
|
|
|
this.chunkX = i;
|
|
|
|
this.chunkZ = j;
|
2011-06-27 00:25:01 +02:00
|
|
|
this.location = new ChunkCoordIntPair(i, j);
|
2011-05-26 14:48:22 +02:00
|
|
|
playermanager.a().chunkProviderServer.getChunkAt(i, j);
|
2011-02-05 19:15:04 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
public void a(EntityPlayer entityplayer) {
|
|
|
|
if (this.b.contains(entityplayer)) {
|
2011-04-20 19:05:14 +02:00
|
|
|
throw new IllegalStateException("Failed to add player. " + entityplayer + " already is in chunk " + this.chunkX + ", " + this.chunkZ);
|
2011-02-05 19:15:04 +01:00
|
|
|
} else {
|
2011-05-05 04:16:26 +02:00
|
|
|
// CraftBukkit start
|
2011-06-27 00:25:01 +02:00
|
|
|
if (entityplayer.playerChunkCoordIntPairs.add(this.location)) {
|
|
|
|
entityplayer.netServerHandler.sendPacket(new Packet50PreChunk(this.location.x, this.location.z, true));
|
2011-05-05 04:16:26 +02:00
|
|
|
}
|
|
|
|
// CraftBukkit end
|
2011-05-14 16:29:42 +02:00
|
|
|
|
2011-02-05 19:15:04 +01:00
|
|
|
this.b.add(entityplayer);
|
2011-06-27 00:25:01 +02:00
|
|
|
entityplayer.chunkCoordIntPairQueue.add(this.location);
|
2011-02-05 19:15:04 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public void b(EntityPlayer entityplayer) {
|
2011-05-31 15:55:45 +02:00
|
|
|
if (this.b.contains(entityplayer)) {
|
2011-02-05 19:15:04 +01:00
|
|
|
this.b.remove(entityplayer);
|
|
|
|
if (this.b.size() == 0) {
|
2011-04-20 19:05:14 +02:00
|
|
|
long i = (long) this.chunkX + 2147483647L | (long) this.chunkZ + 2147483647L << 32;
|
2011-02-05 19:15:04 +01:00
|
|
|
|
2011-09-15 18:36:27 +02:00
|
|
|
PlayerManager.a(this.playerManager).remove(i);
|
2011-04-20 19:05:14 +02:00
|
|
|
if (this.dirtyCount > 0) {
|
2011-05-26 14:48:22 +02:00
|
|
|
PlayerManager.b(this.playerManager).remove(this);
|
2011-02-05 19:15:04 +01:00
|
|
|
}
|
|
|
|
|
2011-05-26 14:48:22 +02:00
|
|
|
this.playerManager.a().chunkProviderServer.queueUnload(this.chunkX, this.chunkZ);
|
2011-02-05 19:15:04 +01:00
|
|
|
}
|
|
|
|
|
2011-06-27 00:25:01 +02:00
|
|
|
entityplayer.chunkCoordIntPairQueue.remove(this.location);
|
2011-06-12 00:02:58 +02:00
|
|
|
// CraftBukkit - contains -> remove -- TODO VERIFY!!!!
|
2011-06-27 00:25:01 +02:00
|
|
|
if (entityplayer.playerChunkCoordIntPairs.remove(this.location)) {
|
2011-04-20 19:05:14 +02:00
|
|
|
entityplayer.netServerHandler.sendPacket(new Packet50PreChunk(this.chunkX, this.chunkZ, false));
|
2011-02-05 19:15:04 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public void a(int i, int j, int k) {
|
2011-04-20 19:05:14 +02:00
|
|
|
if (this.dirtyCount == 0) {
|
2011-05-26 14:48:22 +02:00
|
|
|
PlayerManager.b(this.playerManager).add(this);
|
2011-02-05 19:15:04 +01:00
|
|
|
}
|
|
|
|
|
2012-03-01 11:49:23 +01:00
|
|
|
this.h |= 1 << (j >> 4);
|
|
|
|
if (this.dirtyCount < 64) {
|
2011-02-05 19:15:04 +01:00
|
|
|
short short1 = (short) (i << 12 | k << 8 | j);
|
|
|
|
|
2011-04-20 19:05:14 +02:00
|
|
|
for (int l = 0; l < this.dirtyCount; ++l) {
|
|
|
|
if (this.dirtyBlocks[l] == short1) {
|
2011-02-05 19:15:04 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-04-20 19:05:14 +02:00
|
|
|
this.dirtyBlocks[this.dirtyCount++] = short1;
|
2011-02-05 19:15:04 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-04-20 19:05:14 +02:00
|
|
|
public void sendAll(Packet packet) {
|
2011-02-05 19:15:04 +01:00
|
|
|
for (int i = 0; i < this.b.size(); ++i) {
|
|
|
|
EntityPlayer entityplayer = (EntityPlayer) this.b.get(i);
|
|
|
|
|
2012-03-01 11:49:23 +01:00
|
|
|
if (entityplayer.playerChunkCoordIntPairs.contains(this.location) && !entityplayer.chunkCoordIntPairQueue.contains(this.location)) {
|
2011-04-20 19:05:14 +02:00
|
|
|
entityplayer.netServerHandler.sendPacket(packet);
|
2011-02-05 19:15:04 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public void a() {
|
2011-05-26 14:48:22 +02:00
|
|
|
WorldServer worldserver = this.playerManager.a();
|
|
|
|
|
2011-04-20 19:05:14 +02:00
|
|
|
if (this.dirtyCount != 0) {
|
2011-02-05 19:15:04 +01:00
|
|
|
int i;
|
|
|
|
int j;
|
|
|
|
int k;
|
|
|
|
|
2011-04-20 19:05:14 +02:00
|
|
|
if (this.dirtyCount == 1) {
|
2012-03-01 11:49:23 +01:00
|
|
|
i = this.chunkX * 16 + (this.dirtyBlocks[0] >> 12 & 15);
|
|
|
|
j = this.dirtyBlocks[0] & 255;
|
|
|
|
k = this.chunkZ * 16 + (this.dirtyBlocks[0] >> 8 & 15);
|
2011-05-26 14:48:22 +02:00
|
|
|
this.sendAll(new Packet53BlockChange(i, j, k, worldserver));
|
2012-03-01 11:49:23 +01:00
|
|
|
if (worldserver.isTileEntity(i, j, k)) {
|
2011-05-26 14:48:22 +02:00
|
|
|
this.sendTileEntity(worldserver.getTileEntity(i, j, k));
|
2011-02-05 19:15:04 +01:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
int l;
|
|
|
|
|
2012-03-01 11:49:23 +01:00
|
|
|
if (this.dirtyCount == 64) {
|
|
|
|
i = this.chunkX * 16;
|
|
|
|
j = this.chunkZ * 16;
|
2012-04-05 02:55:16 +02:00
|
|
|
this.sendAll(new Packet51MapChunk(worldserver.getChunkAt(this.chunkX, this.chunkZ), (this.h == 0xFFFF), this.h)); // CraftBukkit - send everything (including biome) if all sections flagged
|
2012-03-01 11:49:23 +01:00
|
|
|
|
|
|
|
for (k = 0; k < 16; ++k) {
|
|
|
|
if ((this.h & 1 << k) != 0) {
|
|
|
|
l = k << 4;
|
|
|
|
List list = worldserver.getTileEntities(i, l, j, i + 16, l + 16, j + 16);
|
|
|
|
|
|
|
|
for (int i1 = 0; i1 < list.size(); ++i1) {
|
|
|
|
this.sendTileEntity((TileEntity) list.get(i1));
|
|
|
|
}
|
|
|
|
}
|
2011-02-05 19:15:04 +01:00
|
|
|
}
|
|
|
|
} else {
|
2011-05-26 14:48:22 +02:00
|
|
|
this.sendAll(new Packet52MultiBlockChange(this.chunkX, this.chunkZ, this.dirtyBlocks, this.dirtyCount, worldserver));
|
2011-02-05 19:15:04 +01:00
|
|
|
|
2011-04-20 19:05:14 +02:00
|
|
|
for (i = 0; i < this.dirtyCount; ++i) {
|
2011-05-16 04:54:13 +02:00
|
|
|
j = this.chunkX * 16 + (this.dirtyBlocks[i] >> 12 & 15);
|
|
|
|
k = this.dirtyBlocks[i] & 255;
|
|
|
|
l = this.chunkZ * 16 + (this.dirtyBlocks[i] >> 8 & 15);
|
2012-03-01 11:49:23 +01:00
|
|
|
if (worldserver.isTileEntity(j, k, l)) {
|
2011-05-26 14:48:22 +02:00
|
|
|
this.sendTileEntity(worldserver.getTileEntity(j, k, l));
|
2011-02-05 19:15:04 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-04-20 19:05:14 +02:00
|
|
|
this.dirtyCount = 0;
|
2012-03-01 11:49:23 +01:00
|
|
|
this.h = 0;
|
2011-02-05 19:15:04 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-04-20 19:05:14 +02:00
|
|
|
private void sendTileEntity(TileEntity tileentity) {
|
2011-02-05 19:15:04 +01:00
|
|
|
if (tileentity != null) {
|
2012-03-01 11:49:23 +01:00
|
|
|
Packet packet = tileentity.d();
|
2011-02-05 19:15:04 +01:00
|
|
|
|
|
|
|
if (packet != null) {
|
2011-04-20 19:05:14 +02:00
|
|
|
this.sendAll(packet);
|
2011-02-05 19:15:04 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|