Only add entity to entity cache if ID doesn't exist (#428)

This commit is contained in:
Camotoy 2020-04-26 00:54:42 -04:00 committed by GitHub
parent 35506f8bef
commit 0caecf68db
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -58,13 +58,19 @@ public class EntityCache {
}
public void spawnEntity(Entity entity) {
cacheEntity(entity);
entity.spawnEntity(session);
if (cacheEntity(entity)) {
entity.spawnEntity(session);
}
}
public void cacheEntity(Entity entity) {
entityIdTranslations.put(entity.getEntityId(), entity.getGeyserId());
entities.put(entity.getGeyserId(), entity);
public boolean cacheEntity(Entity entity) {
// Check to see if the entity exists, otherwise we can end up with duplicated mobs
if (!entityIdTranslations.containsKey(entity.getEntityId())) {
entityIdTranslations.put(entity.getEntityId(), entity.getGeyserId());
entities.put(entity.getGeyserId(), entity);
return true;
}
return false;
}
public boolean removeEntity(Entity entity, boolean force) {