diff --git a/src/org/apollo/game/model/World.java b/src/org/apollo/game/model/World.java index a2d4c8a5..dd3ff8df 100644 --- a/src/org/apollo/game/model/World.java +++ b/src/org/apollo/game/model/World.java @@ -289,7 +289,7 @@ public final class World { boolean success = true; for (Entity entity : entities) { - Sector sector = sectorRepository.get(SectorCoordinates.fromPosition(entity.getPosition())); + Sector sector = sectorRepository.fromPosition(entity.getPosition()); success &= sector.addEntity(entity); } return success; diff --git a/src/org/apollo/game/model/area/Sector.java b/src/org/apollo/game/model/area/Sector.java index eca5b86e..a2f49e91 100644 --- a/src/org/apollo/game/model/area/Sector.java +++ b/src/org/apollo/game/model/area/Sector.java @@ -86,7 +86,15 @@ public final class Sector { * @return {@code true} if this sector contains the entity, otherwise {@code false}. */ public boolean contains(Entity entity) { - return entities.get(entity.getPosition()).contains(entity); + Position position = entity.getPosition(); + List entities = this.entities.get(position); + + if (entities == null) { + this.entities.put(position, new ArrayList<>()); + return false; + } + + return this.entities.get(position).contains(entity); } /** @@ -105,7 +113,13 @@ public final class Sector { * @return The list. */ public List getEntities(Position position) { - return new ArrayList<>(entities.get(position)); + List entities = this.entities.get(position); + if (entities == null) { + entities = new ArrayList<>(); + this.entities.put(position, entities); + } + + return new ArrayList<>(entities); } /** @@ -117,8 +131,13 @@ public final class Sector { */ @SuppressWarnings("unchecked") public List getEntities(Position position, EntityType type) { - return (List) entities.get(position).stream().filter((e) -> e.getEntityType() == type) - .collect(Collectors.toList()); + List entities = this.entities.get(position); + if (entities == null) { + entities = new ArrayList<>(); + this.entities.put(position, entities); + } + + return (List) entities.stream().filter((e) -> e.getEntityType() == type).collect(Collectors.toList()); } /**