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();
|
2011-09-24 23:03:31 +02:00
|
|
|
private EntityList trackedEntities = new EntityList();
|
2011-02-05 19:15:04 +01:00
|
|
|
private MinecraftServer c;
|
|
|
|
private int d;
|
2011-05-26 14:48:22 +02:00
|
|
|
private int e;
|
2011-02-05 19:15:04 +01:00
|
|
|
|
2011-05-26 14:48:22 +02:00
|
|
|
public EntityTracker(MinecraftServer minecraftserver, int i) {
|
2011-02-05 19:15:04 +01:00
|
|
|
this.c = minecraftserver;
|
2011-05-26 14:48:22 +02:00
|
|
|
this.e = i;
|
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-06-27 00:25:01 +02:00
|
|
|
public synchronized void track(Entity entity) {
|
2011-02-05 19:15:04 +01:00
|
|
|
if (entity instanceof EntityPlayer) {
|
2011-09-24 23:03:31 +02:00
|
|
|
this.addEntity(entity, 512, 2);
|
2011-02-05 19:15:04 +01:00
|
|
|
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);
|
|
|
|
}
|
|
|
|
}
|
2011-09-24 23:03:31 +02:00
|
|
|
} else if (entity instanceof EntityFishingHook) {
|
|
|
|
this.addEntity(entity, 64, 5, true);
|
2011-02-05 19:15:04 +01:00
|
|
|
} else if (entity instanceof EntityArrow) {
|
2011-09-24 23:03:31 +02:00
|
|
|
this.addEntity(entity, 64, 20, false);
|
2011-11-20 09:01:14 +01:00
|
|
|
} else if (entity instanceof EntitySmallFireball) {
|
|
|
|
this.addEntity(entity, 64, 10, false);
|
2011-05-26 14:48:22 +02:00
|
|
|
} else if (entity instanceof EntityFireball) {
|
2011-09-24 23:03:31 +02:00
|
|
|
this.addEntity(entity, 64, 10, false);
|
2011-02-05 19:15:04 +01:00
|
|
|
} else if (entity instanceof EntitySnowball) {
|
2011-09-24 23:03:31 +02:00
|
|
|
this.addEntity(entity, 64, 10, true);
|
2011-11-20 09:01:14 +01:00
|
|
|
} else if (entity instanceof EntityEnderPearl) {
|
|
|
|
this.addEntity(entity, 64, 10, true);
|
|
|
|
} else if (entity instanceof EntityEnderSignal) {
|
|
|
|
this.addEntity(entity, 64, 10, true);
|
2011-02-05 19:15:04 +01:00
|
|
|
} else if (entity instanceof EntityEgg) {
|
2011-09-24 23:03:31 +02:00
|
|
|
this.addEntity(entity, 64, 10, true);
|
2011-11-20 09:01:14 +01:00
|
|
|
} else if (entity instanceof EntityPotion) {
|
|
|
|
this.addEntity(entity, 64, 10, true);
|
2011-02-05 19:15:04 +01:00
|
|
|
} else if (entity instanceof EntityItem) {
|
2011-09-24 23:03:31 +02:00
|
|
|
this.addEntity(entity, 64, 20, true);
|
2011-02-05 19:15:04 +01:00
|
|
|
} else if (entity instanceof EntityMinecart) {
|
2011-11-20 09:01:14 +01:00
|
|
|
this.addEntity(entity, 80, 3, true);
|
2011-02-05 19:15:04 +01:00
|
|
|
} else if (entity instanceof EntityBoat) {
|
2011-11-20 09:01:14 +01:00
|
|
|
this.addEntity(entity, 80, 3, true);
|
2011-02-05 19:15:04 +01:00
|
|
|
} else if (entity instanceof EntitySquid) {
|
2011-11-20 09:01:14 +01:00
|
|
|
this.addEntity(entity, 64, 3, true);
|
2011-02-05 19:15:04 +01:00
|
|
|
} else if (entity instanceof IAnimal) {
|
2011-11-20 09:01:14 +01:00
|
|
|
this.addEntity(entity, 80, 3, true);
|
|
|
|
} else if (entity instanceof EntityEnderDragon) {
|
2011-09-24 23:03:31 +02:00
|
|
|
this.addEntity(entity, 160, 3, true);
|
2011-02-05 19:15:04 +01:00
|
|
|
} else if (entity instanceof EntityTNTPrimed) {
|
2011-09-24 23:03:31 +02:00
|
|
|
this.addEntity(entity, 160, 10, true);
|
2011-02-05 19:15:04 +01:00
|
|
|
} else if (entity instanceof EntityFallingSand) {
|
2011-09-24 23:03:31 +02:00
|
|
|
this.addEntity(entity, 160, 20, true);
|
2011-02-05 19:15:04 +01:00
|
|
|
} else if (entity instanceof EntityPainting) {
|
2011-09-24 23:03:31 +02:00
|
|
|
this.addEntity(entity, 160, Integer.MAX_VALUE, false);
|
2011-09-15 02:23:52 +02:00
|
|
|
} else if (entity instanceof EntityExperienceOrb) {
|
2011-09-24 23:03:31 +02:00
|
|
|
this.addEntity(entity, 160, 20, true);
|
2011-11-20 09:01:14 +01:00
|
|
|
} else if (entity instanceof EntityEnderCrystal) {
|
|
|
|
this.addEntity(entity, 256, Integer.MAX_VALUE, false);
|
2011-02-05 19:15:04 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-09-24 23:03:31 +02:00
|
|
|
public void addEntity(Entity entity, int i, int j) {
|
|
|
|
this.addEntity(entity, i, j, false);
|
2011-02-05 19:15:04 +01:00
|
|
|
}
|
|
|
|
|
2011-05-14 16:29:42 +02:00
|
|
|
// CraftBukkit - synchronized
|
2011-09-24 23:03:31 +02:00
|
|
|
public synchronized void addEntity(Entity entity, int i, int j, boolean flag) {
|
2011-02-05 19:15:04 +01:00
|
|
|
if (i > this.d) {
|
|
|
|
i = this.d;
|
|
|
|
}
|
|
|
|
|
2011-09-24 23:03:31 +02:00
|
|
|
if (this.trackedEntities.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);
|
2011-09-24 23:03:31 +02:00
|
|
|
this.trackedEntities.a(entity.id, entitytrackerentry);
|
2011-06-27 00:25:01 +02:00
|
|
|
entitytrackerentry.scanPlayers(this.c.getWorldServer(this.e).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);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-09-24 23:03:31 +02:00
|
|
|
EntityTrackerEntry entitytrackerentry1 = (EntityTrackerEntry) this.trackedEntities.d(entity.id);
|
2011-02-05 19:15:04 +01:00
|
|
|
|
|
|
|
if (entitytrackerentry1 != null) {
|
|
|
|
this.a.remove(entitytrackerentry1);
|
|
|
|
entitytrackerentry1.a();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-05-14 16:29:42 +02:00
|
|
|
// CraftBukkit - synchronized
|
2011-06-27 00:25:01 +02:00
|
|
|
public synchronized void updatePlayers() {
|
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-06-27 00:25:01 +02:00
|
|
|
entitytrackerentry.track(this.c.getWorldServer(this.e).players);
|
2011-04-20 19:05:14 +02:00
|
|
|
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-09-24 23:03:31 +02:00
|
|
|
EntityTrackerEntry entitytrackerentry = (EntityTrackerEntry) this.trackedEntities.a(entity.id);
|
2011-02-05 19:15:04 +01:00
|
|
|
|
|
|
|
if (entitytrackerentry != null) {
|
|
|
|
entitytrackerentry.a(packet);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-05-14 16:29:42 +02:00
|
|
|
// CraftBukkit - synchronized
|
2011-06-27 00:25:01 +02:00
|
|
|
public synchronized void sendPacketToEntity(Entity entity, Packet packet) {
|
2011-09-24 23:03:31 +02:00
|
|
|
EntityTrackerEntry entitytrackerentry = (EntityTrackerEntry) this.trackedEntities.a(entity.id);
|
2011-02-05 19:15:04 +01:00
|
|
|
|
|
|
|
if (entitytrackerentry != null) {
|
|
|
|
entitytrackerentry.b(packet);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-05-14 16:29:42 +02:00
|
|
|
// CraftBukkit - synchronized
|
2011-06-27 00:25:01 +02:00
|
|
|
public synchronized void untrackPlayer(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);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|