13
0
geforkt von Mirrors/Paper
Paper/src/main/java/net/minecraft/server/EntityTracker.java

179 Zeilen
6.9 KiB
Java

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();
public IntHashMap trackedEntities = new IntHashMap(); // CraftBukkit - private -> public
private MinecraftServer c;
private int d;
private World world; // CraftBukkit - change type
public EntityTracker(MinecraftServer minecraftserver, World i) { // CraftBukkit - change method signature
this.c = minecraftserver;
this.world = i;
this.d = minecraftserver.serverConfigurationManager.a();
}
2011-05-14 16:29:42 +02:00
// CraftBukkit - synchronized
public synchronized void track(Entity entity) {
if (entity instanceof EntityPlayer) {
this.addEntity(entity, 512, 2);
EntityPlayer entityplayer = (EntityPlayer) entity;
Iterator iterator = this.a.iterator();
while (iterator.hasNext()) {
EntityTrackerEntry entitytrackerentry = (EntityTrackerEntry) iterator.next();
if (entitytrackerentry.tracker != entityplayer) {
2012-02-29 22:31:04 +01:00
entitytrackerentry.updatePlayer(entityplayer);
}
}
} else if (entity instanceof EntityFishingHook) {
this.addEntity(entity, 64, 5, true);
} else if (entity instanceof EntityArrow) {
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) {
this.addEntity(entity, 64, 10, false);
} else if (entity instanceof EntitySnowball) {
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);
} else if (entity instanceof EntityEgg) {
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);
} else if (entity instanceof EntityItem) {
this.addEntity(entity, 64, 20, true);
} else if (entity instanceof EntityMinecart) {
2011-11-20 09:01:14 +01:00
this.addEntity(entity, 80, 3, true);
} else if (entity instanceof EntityBoat) {
2011-11-20 09:01:14 +01:00
this.addEntity(entity, 80, 3, true);
} else if (entity instanceof EntitySquid) {
2011-11-20 09:01:14 +01:00
this.addEntity(entity, 64, 3, true);
} else if (entity instanceof IAnimal) {
2011-11-20 09:01:14 +01:00
this.addEntity(entity, 80, 3, true);
} else if (entity instanceof EntityEnderDragon) {
this.addEntity(entity, 160, 3, true);
} else if (entity instanceof EntityTNTPrimed) {
this.addEntity(entity, 160, 10, true);
} else if (entity instanceof EntityFallingBlock) {
this.addEntity(entity, 160, 20, true);
} else if (entity instanceof EntityPainting) {
this.addEntity(entity, 160, Integer.MAX_VALUE, false);
2011-09-15 02:23:52 +02:00
} else if (entity instanceof EntityExperienceOrb) {
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);
}
}
public void addEntity(Entity entity, int i, int j) {
this.addEntity(entity, i, j, false);
}
2011-05-14 16:29:42 +02:00
// CraftBukkit - synchronized
public synchronized void addEntity(Entity entity, int i, int j, boolean flag) {
if (i > this.d) {
i = this.d;
}
if (this.trackedEntities.b(entity.id)) {
// 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!");
} else {
EntityTrackerEntry entitytrackerentry = new EntityTrackerEntry(entity, i, j, flag);
this.a.add(entitytrackerentry);
this.trackedEntities.a(entity.id, entitytrackerentry);
entitytrackerentry.scanPlayers(this.world.players); // CraftBukkit
}
}
2011-05-14 16:29:42 +02:00
// CraftBukkit - synchronized
public synchronized void untrackEntity(Entity entity) {
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.trackedEntities.d(entity.id);
if (entitytrackerentry1 != null) {
this.a.remove(entitytrackerentry1);
entitytrackerentry1.a();
}
}
2011-05-14 16:29:42 +02:00
// CraftBukkit - synchronized
public synchronized void updatePlayers() {
ArrayList arraylist = new ArrayList();
Iterator iterator = this.a.iterator();
while (iterator.hasNext()) {
EntityTrackerEntry entitytrackerentry = (EntityTrackerEntry) iterator.next();
entitytrackerentry.track(this.world.players); // CraftBukkit
if (entitytrackerentry.m && entitytrackerentry.tracker instanceof EntityPlayer) {
arraylist.add((EntityPlayer) entitytrackerentry.tracker);
}
}
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();
if (entitytrackerentry1.tracker != entityplayer) {
2012-02-29 22:31:04 +01:00
entitytrackerentry1.updatePlayer(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) {
2012-02-29 22:31:04 +01:00
EntityTrackerEntry entitytrackerentry = (EntityTrackerEntry) this.trackedEntities.get(entity.id);
if (entitytrackerentry != null) {
entitytrackerentry.broadcast(packet);
}
}
2011-05-14 16:29:42 +02:00
// CraftBukkit - synchronized
public synchronized void sendPacketToEntity(Entity entity, Packet packet) {
2012-02-29 22:31:04 +01:00
EntityTrackerEntry entitytrackerentry = (EntityTrackerEntry) this.trackedEntities.get(entity.id);
if (entitytrackerentry != null) {
entitytrackerentry.broadcastIncludingSelf(packet);
}
}
2011-05-14 16:29:42 +02:00
// CraftBukkit - synchronized
public synchronized void untrackPlayer(EntityPlayer entityplayer) {
Iterator iterator = this.a.iterator();
while (iterator.hasNext()) {
EntityTrackerEntry entitytrackerentry = (EntityTrackerEntry) iterator.next();
2012-02-29 22:31:04 +01:00
entitytrackerentry.clear(entityplayer);
}
}
}