diff --git a/docs/src/progress/renderertodo.md b/docs/src/progress/renderertodo.md index 6bc39d04..dee78054 100644 --- a/docs/src/progress/renderertodo.md +++ b/docs/src/progress/renderertodo.md @@ -1742,6 +1742,7 @@ Fix character bug with loading into level Multiple loot pool support Crops replace loot pool on completion of growth Display name for all common entity data +Enitity id collision validation diff --git a/src/main/java/electrosphere/data/ConfigValidator.java b/src/main/java/electrosphere/data/ConfigValidator.java index 8c005353..a7eb5baf 100644 --- a/src/main/java/electrosphere/data/ConfigValidator.java +++ b/src/main/java/electrosphere/data/ConfigValidator.java @@ -1,7 +1,9 @@ package electrosphere.data; +import java.util.HashMap; import java.util.LinkedList; import java.util.List; +import java.util.Map; import java.util.stream.Collectors; import electrosphere.data.common.CommonEntityType; @@ -33,6 +35,45 @@ public class ConfigValidator { for(CommonEntityType type : allData){ CommonEntityValidator.validate(type); } + + ConfigValidator.checkIdCollisions(config); + } + + /** + * Checks if there are any id collisions + * @param config The config + */ + private static void checkIdCollisions(Config config){ + //check for id collisions + Map occupancyMap = new HashMap(); + for(CommonEntityType type : config.getObjectTypeMap().getTypes()){ + if(occupancyMap.containsKey(type.getId())){ + throw new Error("Entity id collision: " + type.getId()); + } else { + occupancyMap.put(type.getId(),true); + } + } + for(CommonEntityType type : config.getCreatureTypeLoader().getTypes()){ + if(occupancyMap.containsKey(type.getId())){ + throw new Error("Entity id collision: " + type.getId()); + } else { + occupancyMap.put(type.getId(),true); + } + } + for(CommonEntityType type : config.getFoliageMap().getTypes()){ + if(occupancyMap.containsKey(type.getId())){ + throw new Error("Entity id collision: " + type.getId()); + } else { + occupancyMap.put(type.getId(),true); + } + } + for(CommonEntityType type : config.getItemMap().getTypes()){ + if(occupancyMap.containsKey(type.getId())){ + throw new Error("Entity id collision: " + type.getId()); + } else { + occupancyMap.put(type.getId(),true); + } + } } }