diff --git a/src/main/java/emu/grasscutter/game/entity/EntityRegion.java b/src/main/java/emu/grasscutter/game/entity/EntityRegion.java index f3a8ffd0..f0ab0a0e 100644 --- a/src/main/java/emu/grasscutter/game/entity/EntityRegion.java +++ b/src/main/java/emu/grasscutter/game/entity/EntityRegion.java @@ -10,6 +10,7 @@ import org.anime_game_servers.multi_proto.gi.messages.scene.entity.SceneEntityIn import java.util.Set; import java.util.concurrent.ConcurrentHashMap; +import java.util.stream.Collectors; @Getter public class EntityRegion extends GameEntity{ @@ -72,6 +73,16 @@ public class EntityRegion extends GameEntity{ this.entityLeave = false; this.leftEntities.clear(); } + + public void clearDeadEntities() { + entities.removeAll(entities.stream() + .filter(entity -> this.getScene().getEntityById(entity.id) == null) + .collect(Collectors.toSet())); + notContainEntities.removeAll(notContainEntities.stream() + .filter(entity -> this.getScene().getEntityById(entity.id) == null) + .collect(Collectors.toSet())); + } + @Override public Int2FloatMap getFightProperties() {return null;} @Override public Position getPosition() {return position;} diff --git a/src/main/java/emu/grasscutter/scripts/SceneScriptManager.java b/src/main/java/emu/grasscutter/scripts/SceneScriptManager.java index f54a9143..1c1ee4ff 100644 --- a/src/main/java/emu/grasscutter/scripts/SceneScriptManager.java +++ b/src/main/java/emu/grasscutter/scripts/SceneScriptManager.java @@ -570,6 +570,7 @@ public class SceneScriptManager { for (var region : this.regions.values()) { val metaRegion = region.getMetaRegion(); + region.clearDeadEntities(); getScene().getEntities().values().stream() .filter(e -> e.getEntityType() == EntityType.Avatar)