mirror of
https://github.com/BlueMap-Minecraft/BlueMap.git
synced 2024-11-05 02:19:37 +01:00
Improve autogenerated config names
This commit is contained in:
parent
fab523fe05
commit
e68aacfd5d
@ -239,20 +239,33 @@ private Map<String, MapConfig> loadMapConfigs(Collection<ServerWorld> autoConfig
|
||||
StandardOpenOption.CREATE, StandardOpenOption.TRUNCATE_EXISTING
|
||||
);
|
||||
} else {
|
||||
for (var world : autoConfigWorlds) {
|
||||
Path worldFolder = world.getWorldFolder();
|
||||
// make sure overworld-dimensions come first, so they are the ones where the
|
||||
// dimension-key is omitted in the generated map-id
|
||||
List<ServerWorld> overworldFirstAutoConfigWorlds = new ArrayList<>(autoConfigWorlds.size());
|
||||
overworldFirstAutoConfigWorlds.addAll(autoConfigWorlds);
|
||||
overworldFirstAutoConfigWorlds.sort(Comparator.comparingInt(w ->
|
||||
DataPack.DIMENSION_OVERWORLD.equals(w.getDimension()) ? 0 : 1
|
||||
));
|
||||
|
||||
Set<String> mapIds = new HashSet<>();
|
||||
for (var world : overworldFirstAutoConfigWorlds) {
|
||||
Path worldFolder = world.getWorldFolder().normalize();
|
||||
Key dimension = world.getDimension();
|
||||
|
||||
String dimensionName = dimension.getNamespace().equals("minecraft") ?
|
||||
dimension.getValue() : dimension.getFormatted();
|
||||
String id = sanitiseMapId(worldFolder.getFileName() + "_" + dimensionName).toLowerCase(Locale.ROOT);
|
||||
|
||||
Path configFile = mapConfigFolder.resolve(id + ".conf");
|
||||
// find unique map id
|
||||
String id = sanitiseMapId(worldFolder.getFileName().toString()).toLowerCase(Locale.ROOT);
|
||||
if (mapIds.contains(id))
|
||||
id = sanitiseMapId(worldFolder.getFileName() + "_" + dimensionName).toLowerCase(Locale.ROOT);
|
||||
int i = 1;
|
||||
while (Files.exists(configFile)) {
|
||||
configFile = mapConfigFolder.resolve(id + '_' + (++i) + ".conf");
|
||||
}
|
||||
String uniqueId = id;
|
||||
while (mapIds.contains(uniqueId))
|
||||
uniqueId = id + "_" + (++i);
|
||||
mapIds.add(uniqueId);
|
||||
|
||||
Path configFile = mapConfigFolder.resolve(uniqueId + ".conf");
|
||||
String name = worldFolder.getFileName() + " (" + dimensionName + ")";
|
||||
if (i > 1) name = name + " (" + i + ")";
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user