From 0caecf68db6fc68462d1d62af09857c1a25e9495 Mon Sep 17 00:00:00 2001 From: Camotoy <20743703+DoctorMacc@users.noreply.github.com> Date: Sun, 26 Apr 2020 00:54:42 -0400 Subject: [PATCH] Only add entity to entity cache if ID doesn't exist (#428) --- .../network/session/cache/EntityCache.java | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/connector/src/main/java/org/geysermc/connector/network/session/cache/EntityCache.java b/connector/src/main/java/org/geysermc/connector/network/session/cache/EntityCache.java index f0b394fd..80d10b1a 100644 --- a/connector/src/main/java/org/geysermc/connector/network/session/cache/EntityCache.java +++ b/connector/src/main/java/org/geysermc/connector/network/session/cache/EntityCache.java @@ -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) {