2011-02-05 19:15:04 +01:00
|
|
|
package net.minecraft.server;
|
|
|
|
|
|
|
|
import java.util.ArrayList;
|
|
|
|
import java.util.HashSet;
|
|
|
|
import java.util.Iterator;
|
|
|
|
import java.util.Set;
|
|
|
|
|
|
|
|
public class EntityTracker {
|
|
|
|
|
|
|
|
private Set a = new HashSet();
|
|
|
|
private EntityList b = new EntityList();
|
|
|
|
private MinecraftServer c;
|
|
|
|
private int d;
|
|
|
|
|
|
|
|
public EntityTracker(MinecraftServer minecraftserver) {
|
|
|
|
this.c = minecraftserver;
|
2011-04-20 19:05:14 +02:00
|
|
|
this.d = minecraftserver.serverConfigurationManager.a();
|
2011-02-05 19:15:04 +01:00
|
|
|
}
|
|
|
|
|
2011-05-14 16:29:42 +02:00
|
|
|
// CraftBukkit - synchronized
|
2011-03-02 20:00:16 +01:00
|
|
|
public synchronized void a(Entity entity) {
|
2011-02-05 19:15:04 +01:00
|
|
|
if (entity instanceof EntityPlayer) {
|
|
|
|
this.a(entity, 512, 2);
|
|
|
|
EntityPlayer entityplayer = (EntityPlayer) entity;
|
|
|
|
Iterator iterator = this.a.iterator();
|
|
|
|
|
|
|
|
while (iterator.hasNext()) {
|
|
|
|
EntityTrackerEntry entitytrackerentry = (EntityTrackerEntry) iterator.next();
|
|
|
|
|
2011-04-20 19:05:14 +02:00
|
|
|
if (entitytrackerentry.tracker != entityplayer) {
|
2011-02-05 19:15:04 +01:00
|
|
|
entitytrackerentry.b(entityplayer);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else if (entity instanceof EntityFish) {
|
|
|
|
this.a(entity, 64, 5, true);
|
|
|
|
} else if (entity instanceof EntityArrow) {
|
|
|
|
this.a(entity, 64, 5, true);
|
|
|
|
} else if (entity instanceof EntitySnowball) {
|
|
|
|
this.a(entity, 64, 5, true);
|
|
|
|
} else if (entity instanceof EntityEgg) {
|
|
|
|
this.a(entity, 64, 5, true);
|
|
|
|
} else if (entity instanceof EntityItem) {
|
|
|
|
this.a(entity, 64, 20, true);
|
|
|
|
} else if (entity instanceof EntityMinecart) {
|
|
|
|
this.a(entity, 160, 5, true);
|
|
|
|
} else if (entity instanceof EntityBoat) {
|
|
|
|
this.a(entity, 160, 5, true);
|
|
|
|
} else if (entity instanceof EntitySquid) {
|
|
|
|
this.a(entity, 160, 3, true);
|
|
|
|
} else if (entity instanceof IAnimal) {
|
|
|
|
this.a(entity, 160, 3);
|
|
|
|
} else if (entity instanceof EntityTNTPrimed) {
|
|
|
|
this.a(entity, 160, 10, true);
|
|
|
|
} else if (entity instanceof EntityFallingSand) {
|
|
|
|
this.a(entity, 160, 20, true);
|
|
|
|
} else if (entity instanceof EntityPainting) {
|
|
|
|
this.a(entity, 160, Integer.MAX_VALUE, false);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public void a(Entity entity, int i, int j) {
|
|
|
|
this.a(entity, i, j, false);
|
|
|
|
}
|
|
|
|
|
2011-05-14 16:29:42 +02:00
|
|
|
// CraftBukkit - synchronized
|
2011-03-02 20:00:16 +01:00
|
|
|
public synchronized void a(Entity entity, int i, int j, boolean flag) {
|
2011-02-05 19:15:04 +01:00
|
|
|
if (i > this.d) {
|
|
|
|
i = this.d;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (this.b.b(entity.id)) {
|
2011-05-05 03:25:57 +02:00
|
|
|
// CraftBukkit - removed exception throw as tracking an already tracked entity theoretically shouldn't cause any issues.
|
2011-05-14 16:29:42 +02:00
|
|
|
// throw new IllegalStateException("Entity is already tracked!");
|
2011-02-05 19:15:04 +01:00
|
|
|
} else {
|
|
|
|
EntityTrackerEntry entitytrackerentry = new EntityTrackerEntry(entity, i, j, flag);
|
|
|
|
|
|
|
|
this.a.add(entitytrackerentry);
|
|
|
|
this.b.a(entity.id, entitytrackerentry);
|
2011-02-23 13:56:36 +01:00
|
|
|
// CraftBukkit
|
2011-04-20 19:05:14 +02:00
|
|
|
entitytrackerentry.scanPlayers(entity.world.players);
|
2011-02-05 19:15:04 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-05-14 16:29:42 +02:00
|
|
|
// CraftBukkit - synchronized
|
2011-04-20 19:05:14 +02:00
|
|
|
public synchronized void untrackEntity(Entity entity) {
|
2011-02-05 19:15:04 +01:00
|
|
|
if (entity instanceof EntityPlayer) {
|
|
|
|
EntityPlayer entityplayer = (EntityPlayer) entity;
|
|
|
|
Iterator iterator = this.a.iterator();
|
|
|
|
|
|
|
|
while (iterator.hasNext()) {
|
|
|
|
EntityTrackerEntry entitytrackerentry = (EntityTrackerEntry) iterator.next();
|
|
|
|
|
|
|
|
entitytrackerentry.a(entityplayer);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
EntityTrackerEntry entitytrackerentry1 = (EntityTrackerEntry) this.b.d(entity.id);
|
|
|
|
|
|
|
|
if (entitytrackerentry1 != null) {
|
|
|
|
this.a.remove(entitytrackerentry1);
|
|
|
|
entitytrackerentry1.a();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-05-14 16:29:42 +02:00
|
|
|
// CraftBukkit - synchronized
|
2011-03-02 20:00:16 +01:00
|
|
|
public synchronized void a() {
|
2011-02-05 19:15:04 +01:00
|
|
|
ArrayList arraylist = new ArrayList();
|
|
|
|
Iterator iterator = this.a.iterator();
|
|
|
|
|
|
|
|
while (iterator.hasNext()) {
|
|
|
|
EntityTrackerEntry entitytrackerentry = (EntityTrackerEntry) iterator.next();
|
|
|
|
|
2011-02-23 13:56:36 +01:00
|
|
|
// CraftBukkit
|
2011-04-20 19:05:14 +02:00
|
|
|
entitytrackerentry.track(entitytrackerentry.tracker.world.players);
|
|
|
|
if (entitytrackerentry.m && entitytrackerentry.tracker instanceof EntityPlayer) {
|
|
|
|
arraylist.add((EntityPlayer) entitytrackerentry.tracker);
|
2011-02-05 19:15:04 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
for (int i = 0; i < arraylist.size(); ++i) {
|
|
|
|
EntityPlayer entityplayer = (EntityPlayer) arraylist.get(i);
|
|
|
|
Iterator iterator1 = this.a.iterator();
|
|
|
|
|
|
|
|
while (iterator1.hasNext()) {
|
|
|
|
EntityTrackerEntry entitytrackerentry1 = (EntityTrackerEntry) iterator1.next();
|
|
|
|
|
2011-04-20 19:05:14 +02:00
|
|
|
if (entitytrackerentry1.tracker != entityplayer) {
|
2011-02-05 19:15:04 +01:00
|
|
|
entitytrackerentry1.b(entityplayer);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-05-14 16:29:42 +02:00
|
|
|
// CraftBukkit - synchronized
|
2011-03-02 20:00:16 +01:00
|
|
|
public synchronized void a(Entity entity, Packet packet) {
|
2011-02-05 19:15:04 +01:00
|
|
|
EntityTrackerEntry entitytrackerentry = (EntityTrackerEntry) this.b.a(entity.id);
|
|
|
|
|
|
|
|
if (entitytrackerentry != null) {
|
|
|
|
entitytrackerentry.a(packet);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-05-14 16:29:42 +02:00
|
|
|
// CraftBukkit - synchronized
|
2011-03-02 20:00:16 +01:00
|
|
|
public synchronized void b(Entity entity, Packet packet) {
|
2011-02-05 19:15:04 +01:00
|
|
|
EntityTrackerEntry entitytrackerentry = (EntityTrackerEntry) this.b.a(entity.id);
|
|
|
|
|
|
|
|
if (entitytrackerentry != null) {
|
|
|
|
entitytrackerentry.b(packet);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-05-14 16:29:42 +02:00
|
|
|
// CraftBukkit - synchronized
|
2011-04-20 19:05:14 +02:00
|
|
|
public synchronized void trackPlayer(EntityPlayer entityplayer) {
|
2011-02-05 19:15:04 +01:00
|
|
|
Iterator iterator = this.a.iterator();
|
|
|
|
|
|
|
|
while (iterator.hasNext()) {
|
|
|
|
EntityTrackerEntry entitytrackerentry = (EntityTrackerEntry) iterator.next();
|
|
|
|
|
|
|
|
entitytrackerentry.c(entityplayer);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|