use of com.faforever.api.data.domain.Map in project faf-java-api by FAForever.
the class MapService method updateMapEntities.
private void updateMapEntities(MapUploadData progressData) {
LuaValue scenarioInfo = progressData.getLuaScenarioInfo();
Map map = progressData.getMapEntity();
if (map == null) {
map = new Map();
}
map.setDisplayName(scenarioInfo.get(ScenarioMapInfo.NAME).toString()).setMapType(scenarioInfo.get(ScenarioMapInfo.TYPE).tojstring()).setBattleType(scenarioInfo.get(ScenarioMapInfo.CONFIGURATIONS).get(ScenarioMapInfo.CONFIGURATION_STANDARD).get(ScenarioMapInfo.CONFIGURATION_STANDARD_TEAMS).get(1).get(ScenarioMapInfo.CONFIGURATION_STANDARD_TEAMS_NAME).tojstring()).setAuthor(progressData.getAuthorEntity());
LuaValue size = scenarioInfo.get(ScenarioMapInfo.SIZE);
MapVersion version = new MapVersion().setDescription(scenarioInfo.get(ScenarioMapInfo.DESCRIPTION).tojstring().replaceAll("<LOC .*?>", "")).setWidth(size.get(1).toint()).setHeight(size.get(2).toint()).setHidden(false).setRanked(progressData.isRanked()).setMaxPlayers(scenarioInfo.get(ScenarioMapInfo.CONFIGURATIONS).get(ScenarioMapInfo.CONFIGURATION_STANDARD).get(ScenarioMapInfo.CONFIGURATION_STANDARD_TEAMS).get(1).get(ScenarioMapInfo.CONFIGURATION_STANDARD_TEAMS_ARMIES).length()).setVersion(scenarioInfo.get(ScenarioMapInfo.MAP_VERSION).toint());
map.getVersions().add(version);
version.setMap(map);
progressData.setMapEntity(map);
progressData.setMapVersionEntity(version);
version.setFilename(STUPID_MAP_FOLDER_PREFIX + progressData.getFinalZipName());
progressData.setFinalZipFile(this.fafApiProperties.getMap().getTargetDirectory().resolve(progressData.getFinalZipName()));
if (Files.exists(progressData.getFinalZipFile())) {
throw new ApiException(new Error(ErrorCode.MAP_NAME_CONFLICT, progressData.getFinalZipName()));
}
// this triggers validation
mapRepository.save(map);
}
use of com.faforever.api.data.domain.Map in project faf-java-api by FAForever.
the class MapService method postProcessLuaFile.
private void postProcessLuaFile(MapUploadData progressData) {
LuaValue scenarioInfo = progressData.getLuaScenarioInfo();
Optional<Map> mapEntity = mapRepository.findOneByDisplayName(scenarioInfo.get(ScenarioMapInfo.NAME).toString());
if (!mapEntity.isPresent()) {
return;
}
Player author = mapEntity.get().getAuthor();
if (author == null) {
return;
}
if (author.getId() != progressData.getAuthorEntity().getId()) {
throw new ApiException(new Error(ErrorCode.MAP_NOT_ORIGINAL_AUTHOR, mapEntity.get().getDisplayName()));
}
int newVersion = scenarioInfo.get(ScenarioMapInfo.MAP_VERSION).toint();
if (mapEntity.get().getVersions().stream().anyMatch(mapVersion -> mapVersion.getVersion() == newVersion)) {
throw new ApiException(new Error(ErrorCode.MAP_VERSION_EXISTS, mapEntity.get().getDisplayName(), newVersion));
}
progressData.setMapEntity(mapEntity.get());
}
Aggregations