2011-02-01 20:26:07 +01:00
|
|
|
package net.minecraft.server;
|
|
|
|
|
|
|
|
import java.util.ArrayList;
|
|
|
|
import java.util.List;
|
|
|
|
|
2011-06-08 23:00:30 +02:00
|
|
|
// CraftBukkit start
|
|
|
|
import java.util.Collections;
|
|
|
|
import java.util.Comparator;
|
|
|
|
// CraftBukkit end
|
|
|
|
|
2011-02-01 20:26:07 +01:00
|
|
|
public class PlayerManager {
|
|
|
|
|
2011-05-26 14:48:22 +02:00
|
|
|
public List a = new ArrayList();
|
2011-02-01 20:26:07 +01:00
|
|
|
private PlayerList b = new PlayerList();
|
|
|
|
private List c = new ArrayList();
|
2011-04-20 19:05:14 +02:00
|
|
|
private MinecraftServer server;
|
2011-05-26 14:48:22 +02:00
|
|
|
private int e;
|
|
|
|
private int f;
|
|
|
|
private final int[][] g = new int[][] { { 1, 0}, { 0, 1}, { -1, 0}, { 0, -1}};
|
|
|
|
|
|
|
|
public PlayerManager(MinecraftServer minecraftserver, int i, int j) {
|
|
|
|
if (j > 15) {
|
|
|
|
throw new IllegalArgumentException("Too big view radius!");
|
|
|
|
} else if (j < 3) {
|
|
|
|
throw new IllegalArgumentException("Too small view radius!");
|
|
|
|
} else {
|
|
|
|
this.f = j;
|
|
|
|
this.server = minecraftserver;
|
|
|
|
this.e = i;
|
|
|
|
}
|
|
|
|
}
|
2011-02-23 13:56:36 +01:00
|
|
|
|
2011-05-26 14:48:22 +02:00
|
|
|
public WorldServer a() {
|
|
|
|
return this.server.a(this.e);
|
2011-02-01 20:26:07 +01:00
|
|
|
}
|
|
|
|
|
2011-04-20 19:05:14 +02:00
|
|
|
public void flush() {
|
2011-02-01 20:26:07 +01:00
|
|
|
for (int i = 0; i < this.c.size(); ++i) {
|
|
|
|
((PlayerInstance) this.c.get(i)).a();
|
|
|
|
}
|
|
|
|
|
|
|
|
this.c.clear();
|
|
|
|
}
|
|
|
|
|
2011-02-23 03:37:56 +01:00
|
|
|
private PlayerInstance a(int i, int j, boolean flag) {
|
2011-02-01 20:26:07 +01:00
|
|
|
long k = (long) i + 2147483647L | (long) j + 2147483647L << 32;
|
|
|
|
PlayerInstance playerinstance = (PlayerInstance) this.b.a(k);
|
|
|
|
|
|
|
|
if (playerinstance == null && flag) {
|
2011-02-07 00:47:44 +01:00
|
|
|
playerinstance = new PlayerInstance(this, i, j);
|
2011-02-01 20:26:07 +01:00
|
|
|
this.b.a(k, playerinstance);
|
|
|
|
}
|
|
|
|
|
|
|
|
return playerinstance;
|
|
|
|
}
|
|
|
|
|
2011-04-20 19:05:14 +02:00
|
|
|
public void flagDirty(int i, int j, int k) {
|
2011-02-01 20:26:07 +01:00
|
|
|
int l = i >> 4;
|
|
|
|
int i1 = k >> 4;
|
2011-02-23 03:37:56 +01:00
|
|
|
PlayerInstance playerinstance = this.a(l, i1, false);
|
2011-02-01 20:26:07 +01:00
|
|
|
|
|
|
|
if (playerinstance != null) {
|
|
|
|
playerinstance.a(i & 15, j, k & 15);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-04-20 19:05:14 +02:00
|
|
|
public void addPlayer(EntityPlayer entityplayer) {
|
2011-02-01 20:26:07 +01:00
|
|
|
int i = (int) entityplayer.locX >> 4;
|
|
|
|
int j = (int) entityplayer.locZ >> 4;
|
|
|
|
|
|
|
|
entityplayer.d = entityplayer.locX;
|
|
|
|
entityplayer.e = entityplayer.locZ;
|
2011-02-23 03:37:56 +01:00
|
|
|
int k = 0;
|
2011-05-26 14:48:22 +02:00
|
|
|
int l = this.f;
|
2011-02-23 03:37:56 +01:00
|
|
|
int i1 = 0;
|
2011-05-26 14:48:22 +02:00
|
|
|
int j1 = 0;
|
2011-02-01 20:26:07 +01:00
|
|
|
|
2011-02-23 03:37:56 +01:00
|
|
|
this.a(i, j, true).a(entityplayer);
|
2011-02-01 21:40:52 +01:00
|
|
|
|
2011-05-26 14:48:22 +02:00
|
|
|
int k1;
|
2011-02-01 21:40:52 +01:00
|
|
|
|
2011-05-26 14:48:22 +02:00
|
|
|
for (k1 = 1; k1 <= l * 2; ++k1) {
|
|
|
|
for (int l1 = 0; l1 < 2; ++l1) {
|
|
|
|
int[] aint = this.g[k++ % 4];
|
2011-02-01 21:40:52 +01:00
|
|
|
|
2011-05-26 14:48:22 +02:00
|
|
|
for (int i2 = 0; i2 < k1; ++i2) {
|
|
|
|
i1 += aint[0];
|
|
|
|
j1 += aint[1];
|
|
|
|
this.a(i + i1, j + j1, true).a(entityplayer);
|
2011-02-01 21:40:52 +01:00
|
|
|
}
|
2011-02-01 20:26:07 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-02-23 03:37:56 +01:00
|
|
|
k %= 4;
|
|
|
|
|
2011-05-26 14:48:22 +02:00
|
|
|
for (k1 = 0; k1 < l * 2; ++k1) {
|
|
|
|
i1 += this.g[k][0];
|
|
|
|
j1 += this.g[k][1];
|
|
|
|
this.a(i + i1, j + j1, true).a(entityplayer);
|
2011-02-01 21:40:52 +01:00
|
|
|
}
|
|
|
|
|
2011-02-01 20:26:07 +01:00
|
|
|
this.a.add(entityplayer);
|
|
|
|
}
|
|
|
|
|
2011-04-20 19:05:14 +02:00
|
|
|
public void removePlayer(EntityPlayer entityplayer) {
|
2011-02-01 20:26:07 +01:00
|
|
|
int i = (int) entityplayer.d >> 4;
|
|
|
|
int j = (int) entityplayer.e >> 4;
|
|
|
|
|
2011-05-26 14:48:22 +02:00
|
|
|
for (int k = i - this.f; k <= i + this.f; ++k) {
|
|
|
|
for (int l = j - this.f; l <= j + this.f; ++l) {
|
2011-02-23 03:37:56 +01:00
|
|
|
PlayerInstance playerinstance = this.a(k, l, false);
|
2011-02-01 20:26:07 +01:00
|
|
|
|
|
|
|
if (playerinstance != null) {
|
|
|
|
playerinstance.b(entityplayer);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
this.a.remove(entityplayer);
|
|
|
|
}
|
|
|
|
|
|
|
|
private boolean a(int i, int j, int k, int l) {
|
|
|
|
int i1 = i - k;
|
|
|
|
int j1 = j - l;
|
|
|
|
|
2011-05-26 14:48:22 +02:00
|
|
|
return i1 >= -this.f && i1 <= this.f ? j1 >= -this.f && j1 <= this.f : false;
|
2011-02-01 20:26:07 +01:00
|
|
|
}
|
|
|
|
|
2011-04-20 19:05:14 +02:00
|
|
|
public void movePlayer(EntityPlayer entityplayer) {
|
2011-02-01 20:26:07 +01:00
|
|
|
int i = (int) entityplayer.locX >> 4;
|
|
|
|
int j = (int) entityplayer.locZ >> 4;
|
|
|
|
double d0 = entityplayer.d - entityplayer.locX;
|
|
|
|
double d1 = entityplayer.e - entityplayer.locZ;
|
|
|
|
double d2 = d0 * d0 + d1 * d1;
|
|
|
|
|
|
|
|
if (d2 >= 64.0D) {
|
|
|
|
int k = (int) entityplayer.d >> 4;
|
|
|
|
int l = (int) entityplayer.e >> 4;
|
|
|
|
int i1 = i - k;
|
|
|
|
int j1 = j - l;
|
|
|
|
|
|
|
|
if (i1 != 0 || j1 != 0) {
|
2011-05-26 14:48:22 +02:00
|
|
|
for (int k1 = i - this.f; k1 <= i + this.f; ++k1) {
|
|
|
|
for (int l1 = j - this.f; l1 <= j + this.f; ++l1) {
|
2011-02-01 20:26:07 +01:00
|
|
|
if (!this.a(k1, l1, k, l)) {
|
2011-02-23 03:37:56 +01:00
|
|
|
this.a(k1, l1, true).a(entityplayer);
|
2011-02-01 20:26:07 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
if (!this.a(k1 - i1, l1 - j1, i, j)) {
|
2011-02-23 03:37:56 +01:00
|
|
|
PlayerInstance playerinstance = this.a(k1 - i1, l1 - j1, false);
|
2011-02-01 20:26:07 +01:00
|
|
|
|
|
|
|
if (playerinstance != null) {
|
|
|
|
playerinstance.b(entityplayer);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
entityplayer.d = entityplayer.locX;
|
|
|
|
entityplayer.e = entityplayer.locZ;
|
2011-06-08 23:00:30 +02:00
|
|
|
|
|
|
|
// CraftBukkit start - send nearest chunks first
|
|
|
|
if (i1 > 1 || i1 < -1 || j1 > 1 || j1 < -1) {
|
|
|
|
final int x = i;
|
|
|
|
final int z = j;
|
|
|
|
List<ChunkCoordIntPair> chunksToSend = entityplayer.f;
|
|
|
|
Collections.sort(chunksToSend, new Comparator<ChunkCoordIntPair>() {
|
|
|
|
public int compare(ChunkCoordIntPair a, ChunkCoordIntPair b) {
|
2011-06-12 00:02:58 +02:00
|
|
|
return Math.max(Math.abs(a.x - x), Math.abs(a.z - z)) - Math.max(Math.abs(b.x - x), Math.abs(b.z - z));
|
2011-06-08 23:00:30 +02:00
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
// CraftBukkit end
|
2011-02-01 20:26:07 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-05-26 14:48:22 +02:00
|
|
|
public int c() {
|
|
|
|
return this.f * 16 - 16;
|
2011-02-01 20:26:07 +01:00
|
|
|
}
|
|
|
|
|
2011-05-26 14:48:22 +02:00
|
|
|
static PlayerList a(PlayerManager playermanager) {
|
2011-02-01 20:26:07 +01:00
|
|
|
return playermanager.b;
|
|
|
|
}
|
|
|
|
|
2011-05-26 14:48:22 +02:00
|
|
|
static List b(PlayerManager playermanager) {
|
2011-02-01 20:26:07 +01:00
|
|
|
return playermanager.c;
|
|
|
|
}
|
|
|
|
}
|