Generalize world-ids

This commit is contained in:
Lukas Rieger (Blue) 2024-06-03 15:40:45 +02:00
parent 474c5e27c4
commit 75b562eeb1
No known key found for this signature in database
GPG Key ID: AA33883B1BBA03E6
4 changed files with 19 additions and 15 deletions

View File

@ -219,7 +219,7 @@ private synchronized void loadMap(String id, MapConfig mapConfig) throws Configu
"Check if the 'world' setting in the config-file for that map is correct, or remove the entire config-file if you don't want that map.");
}
String worldId = MCAWorld.id(worldFolder, dimension);
String worldId = World.id(worldFolder, dimension);
World world = worlds.get(worldId);
if (world == null) {
try {

View File

@ -31,6 +31,7 @@
import de.bluecolored.bluemap.common.addons.Addons;
import de.bluecolored.bluemap.common.api.BlueMapAPIImpl;
import de.bluecolored.bluemap.common.config.*;
import de.bluecolored.bluemap.common.debug.StateDumper;
import de.bluecolored.bluemap.common.live.LivePlayersDataSupplier;
import de.bluecolored.bluemap.common.plugin.skins.PlayerSkinUpdater;
import de.bluecolored.bluemap.common.rendermanager.MapUpdateTask;
@ -40,7 +41,6 @@
import de.bluecolored.bluemap.common.serverinterface.ServerWorld;
import de.bluecolored.bluemap.common.web.*;
import de.bluecolored.bluemap.common.web.http.HttpServer;
import de.bluecolored.bluemap.common.debug.StateDumper;
import de.bluecolored.bluemap.core.logger.Logger;
import de.bluecolored.bluemap.core.map.BmMap;
import de.bluecolored.bluemap.core.metrics.Metrics;
@ -50,7 +50,6 @@
import de.bluecolored.bluemap.core.util.FileHelper;
import de.bluecolored.bluemap.core.util.Tristate;
import de.bluecolored.bluemap.core.world.World;
import de.bluecolored.bluemap.core.world.mca.MCAWorld;
import lombok.AccessLevel;
import lombok.Getter;
import org.jetbrains.annotations.Nullable;
@ -639,7 +638,7 @@ public boolean checkPausedByPlayerCount() {
}
public @Nullable World getWorld(ServerWorld serverWorld) {
String id = MCAWorld.id(serverWorld.getWorldFolder(), serverWorld.getDimension());
String id = World.id(serverWorld.getWorldFolder(), serverWorld.getDimension());
return getBlueMap().getWorlds().get(id);
}

View File

@ -27,9 +27,11 @@
import com.flowpowered.math.vector.Vector2i;
import com.flowpowered.math.vector.Vector3i;
import de.bluecolored.bluemap.core.util.Grid;
import de.bluecolored.bluemap.core.util.Key;
import de.bluecolored.bluemap.core.util.WatchService;
import java.io.IOException;
import java.nio.file.Path;
import java.util.Collection;
import java.util.function.Predicate;
@ -105,4 +107,17 @@ default void preloadRegionChunks(int x, int z) {
*/
void invalidateChunkCache(int x, int z);
/**
* Generates a unique world-id based on a world-folder and a dimension
*/
static String id(Path worldFolder, Key dimension) {
worldFolder = worldFolder.toAbsolutePath().normalize();
Path workingDir = Path.of("").toAbsolutePath().normalize();
if (worldFolder.startsWith(workingDir))
worldFolder = workingDir.relativize(worldFolder);
return worldFolder + "#" + dimension.getFormatted();
}
}

View File

@ -94,7 +94,7 @@ public class MCAWorld implements World {
.build(this::loadChunk);
private MCAWorld(Path worldFolder, Key dimension, DataPack dataPack, LevelData levelData) {
this.id = id(worldFolder, dimension);
this.id = World.id(worldFolder, dimension);
this.worldFolder = worldFolder;
this.dimension = dimension;
this.dataPack = dataPack;
@ -275,16 +275,6 @@ public static MCAWorld load(Path worldFolder, Key dimension, DataPack dataPack)
return new MCAWorld(worldFolder, dimension, dataPack, levelData);
}
public static String id(Path worldFolder, Key dimension) {
worldFolder = worldFolder.toAbsolutePath().normalize();
Path workingDir = Path.of("").toAbsolutePath().normalize();
if (worldFolder.startsWith(workingDir))
worldFolder = workingDir.relativize(worldFolder);
return "MCA#" + worldFolder + "#" + dimension.getFormatted();
}
public static Path resolveDimensionFolder(Path worldFolder, Key dimension) {
if (DataPack.DIMENSION_OVERWORLD.equals(dimension)) return worldFolder;
if (DataPack.DIMENSION_THE_NETHER.equals(dimension)) return worldFolder.resolve("DIM-1");